microsoft-outlook-mcp
# microsoft-outlook-mcp
MCP (Model Context Protocol) server exposing Microsoft 365 surfaces — Outlook
email, calendar, and OneDrive — over Microsoft Graph. Supports both personal
Microsoft accounts (consumer) and business/school (365) work accounts.
- Transport: JSON-RPC 2.0 over stdio (streamable-HTTP can be added later)
- Auth: MSAL public client; device code flow by default (headless), loopback
redirect for local development
- License: MIT — see [LICENSE](LICENSE)
## Requirements
- Python 3.12+
- A public-client Microsoft app registration (no client secret) for each mode
you intend to use
- An account: personal Microsoft account, or a work/school account (business)
## Install
pip install -e . # runtime dependencies
pip install -e ".[dev]" # plus lint/test tooling
Start the server:
microsoft-outlook-mcp
## Configuration
One environment variable shape covers both auth modes.
| Variable | Required | Default | Meaning |
| --- | --- | --- | --- |
| `OUTLOOK_MCP_MODE` | yes | — | `personal` or `business` |
| `OUTLOOK_MCP_PERSONAL_CLIENT_ID` | in personal mode | — | app registration client id |
| `OUTLOOK_MCP_BUSINESS_CLIENT_ID` | in business mode | — | app registration client id |
| `OUTLOOK_MCP_BUSINESS_TENANT` | no | `common` | tenant id (business mode only) |
| `OUTLOOK_MCP_CACHE_DIR` | no | `~/.microsoft-outlook-mcp` | token cache directory |
| `OUTLOOK_MCP_AUTH_FLOW` | no | `device` | `device` or `loopback` |
| `OUTLOOK_MCP_LOOPBACK_PORT` | no | `8400` | loopback redirect port |
Scopes requested in both modes: `Mail.ReadWrite`, `Calendars.ReadWrite`,
`Files.ReadWrite`, `offline_access`.
## Authentication
Both modes use the MSAL device code flow by default, which is friendly to
headless sidecars:
1. Start the server and call the `authenticate` tool.
2. The device code message (URL + code) is printed to **stderr**.
3. On any device, open the URL, enter the code, sign in, and accept the
consent prompt.
4. Tokens are persisted to a per-`(mode, client id)` cache file with `0600`
permissions under `OUTLOOK_MCP_CACHE_DIR`.
`check-auth-status` reports whether a cached silent token currently works.
`authenticate` with `force: true` deletes the cache and re-runs the flow.
## Tools
Email (19): `about`, `authenticate`, `check-auth-status`, `list-emails`,
`search-emails`, `read-email`, `send-email`, `draft-email`, `mark-as-read`,
`delete-email`, `list-folders`, `create-folder`, `move-emails`, `list-rules`,
`create-rule`, `edit-rule-sequence`, `list-attachments`, `read-attachment`,
`download-attachment`.
Calendar (7): `list-events`, `create-event`, `update-event`, `delete-event`,
`cancel-event`, `decline-event`, `check-availability`.
OneDrive (8): `onedrive-list`, `onedrive-search`, `onedrive-download`,
`onedrive-upload`, `onedrive-upload-large`, `onedrive-share`,
`onedrive-create-folder`, `onedrive-delete`.
## Security
- Token and refresh tokens are stored on disk as JSON under
`OUTLOOK_MCP_CACHE_DIR` with `0600` permissions. Restrict access to that
directory accordingly; encrypted-at-rest caching is a follow-up.
- All token/credential diagnostics are written to stderr only. The MCP wire
is stdout and is never polluted with secrets.
- `read-email` strips HTML to visible text by default; raw HTML is only
returned when explicitly requested.
## Development
Gate for every commit (all must pass):
ruff check .
mypy src
pytest
Tests are unit tests against a mocked Graph client; no live credentials are
used anywhere in the test suite.
TDQS
Scored across 19 tools
Most tools target a distinct resource+action (read-email, send-email, draft-email, list-folders, create-folder, mark-as-read), so selection is usually clear. The one genuinely confusable pair is read-attachment vs download-attachment, which both retrieve the same attachment and differ only in output destination; list-attachments vs read-attachment is also close but separable.
There is a predictable kebab-case verb-noun convention (list-emails, create-rule, delete-email, move-emails) used consistently across the bulk of the surface. Minor deviations are 'about' (no verb/object) and 'authenticate'/'check-auth-status', which don't fit the verb-noun pattern but remain readable.
19 tools is on the high side, but the surface spans four sub-domains (auth, mail, folders, rules, attachments) and each tool maps to a real operation rather than a duplicate. A couple of tools (about, download-attachment) are marginal, but none feel gratuitous.
Core email lifecycle is covered: list/search/read/send/draft/delete/move, plus folders, rules, and attachments. However, reply and forward are missing (agents must compose a fresh email and lose threading), and the rules and folder surfaces are asymmetric — rules can be created and resequenced but not deleted or edited, and folders can be created but not renamed or deleted.