If you’ve ever tried to script or automate Microsoft 365 workflows, you know the drill: register an app in Entra ID, wrestle with MSAL libraries, handle token caching, and eventually write a bunch of boilerplate just to read your own inbox or fetch a file.
It gets even more complicated when you’re building AI Agents (like those powered by OpenClaw). To give an LLM access to your email and calendar, you typically have to write custom tools and API wrappers from scratch.
That’s why I built M365 CLI — a modern, fast, and dependency-light command-line interface for Microsoft 365 personal and corporate accounts.
What is it?
Simply put, M365 CLI is a terminal tool that lets you manage your Mail, Calendar, OneDrive, and SharePoint directly from the command line.
Instead of writing custom API calls, you can now run commands like:
# Read your top 5 unread emails
m365 mail list --top 5
# See what's next on your schedule
m365 cal list --days 3
# Grab a file from OneDrive
m365 od download "Documents/Q1_Report.pdf" ./
Why build another CLI?
There are existing tools out there, but M365 CLI was built with a very specific dual-purpose philosophy: It must be perfect for AI Agents, while remaining a joy for human power users.
🤖 Built for AI Agents
The primary motivation behind this project was to give AI agents a seamless, out-of-the-box way to interact with the M365 ecosystem.
- Zero-friction Auth: It uses OAuth 2.0 Device Code Flow. Your agent doesn’t need to juggle browser popups or complex secrets; it just follows the device code prompt.
- Agent-friendly Output: Every command supports a
--jsonflag. This means an AI agent can execute a command and reliably parse the structured data without trying to read human-formatted tables. - Built-in Phishing Protection: When letting an AI read your emails, security is critical. M365 CLI includes a Trusted Senders Whitelist feature (
m365 mail trust @domain.com). If an email comes from an untrusted source, the CLI automatically strips the body and warns the user, preventing prompt injection attacks against your agent.
👨💻 Built for Power Users
If you spend most of your day in the terminal, switching to a heavy web app just to check your calendar or send a quick email breaks your flow.
- Fast and Native: Built on Node.js 18+ using native
fetch. No heavy legacy SDKs. - Quick Triage: Send emails, attach files, and manage your OneDrive files natively from your shell.
- SharePoint Support: Easily navigate SharePoint document libraries using human-readable paths (
m365 sp sites).
How to get started
Getting started is designed to be frictionless. The tool comes with a pre-configured Azure AD application, so you don’t even need to touch the Azure Portal to try it out (though you can configure your own app for production).
# Install globally
npm install -g m365-cli
# Login via Device Code
m365 login
# Start exploring!
m365 mail list
m365 onedrive ls
What’s Next
Right now, M365 CLI successfully covers Mail, Calendar, OneDrive, and SharePoint. The upcoming phases will introduce Contacts management and further optimization.
If you are building AI workflows, running a personal assistant agent, or just hate leaving the terminal, give it a try.
Check out the code, contribute, or drop a star on the repository!