๐ M365 MCP
Powerful MCP server for Microsoft Graph API โ a complete AI assistant toolkit for Outlook, Calendar, OneDrive, and Contacts.
โจ Features
- Email Management: Read, send, reply, manage attachments, organize folders
- Calendar Intelligence: Create, update, check availability, respond to invitations
- OneDrive Files: Upload, download, browse with pagination
- Contacts: Search and list contacts from your address book
- Multi-Account: Support for multiple Microsoft accounts (personal, work, school)
- Unified Search: Search across emails, files, events, and people
- โก High-Performance Caching: AES-256 encrypted cache with 300x performance improvement
- ๐ Security & Compliance: Encrypted-at-rest cache designed for GDPR/HIPAA-aligned deployments
๐ Quick Start
๐ See QUICKSTART.md for complete installation and setup guide.
TL;DR
git clone https://github.com/robin-collins/m365-mcp.git
cd m365-mcp && uv sync
cp .env.example .env
uv run authenticate.py
uv run m365-mcp
Claude Desktop
claude mcp add m365-mcp -e M365_MCP_CLIENT_ID=your-app-id-here -- uvx --from git+https://github.com/robin-collins/m365-mcp.git m365-mcp
claude
Usage Examples
> read my latest emails with full content
> reply to the email from John saying "I'll review this today"
> send an email with attachment to alice@example.com
> show my calendar for next week
> check if I'm free tomorrow at 2pm
> create a meeting with Bob next Monday at 10am
# File examples
> list files in my OneDrive
> upload this report to OneDrive
> search for "project proposal" across all my files
# Multi-account
> list all my Microsoft accounts
> send email from my work account
๐งฐ Available Tools
๐ง Email Tools
| Tool |
Description |
email_list |
List emails with optional body content |
email_get |
Get a specific email with attachments |
email_create_draft |
Create an email draft with attachment support |
email_send |
Send email immediately with CC/BCC and attachments |
email_reply |
Reply while maintaining thread context |
email_reply_all |
Reply to all recipients in a thread |
email_forward |
Forward an email |
email_update |
Update message metadata |
email_move |
Move email between folders |
email_delete |
Delete email |
email_get_attachment |
Download an attachment to a validated local path |
email_mark_read |
Mark email read or unread |
email_flag |
Add or clear follow-up flags |
email_add_category |
Add an Outlook category |
email_archive |
Archive an email |
search_emails |
Search emails by query |
๐
Calendar Tools
| Tool |
Description |
calendar_list_calendars |
List calendars |
calendar_create_calendar |
Create a calendar |
calendar_delete_calendar |
Delete a calendar |
calendar_list_events |
List calendar events with details |
calendar_get_event |
Get specific event details |
calendar_create_event |
Create events with location and attendees |
calendar_update_event |
Reschedule or modify events |
calendar_delete_event |
Cancel events |
calendar_respond_event |
Accept, decline, or tentatively accept invitations |
calendar_forward_event |
Forward an event invitation |
calendar_propose_new_time |
Propose a new meeting time |
calendar_get_free_busy |
Get free/busy schedules |
calendar_check_availability |
Check free/busy times for scheduling |
search_events |
Search calendar events |
๐ค Contact Tools
| Tool |
Description |
contact_list |
List all contacts |
contact_get |
Get specific contact details |
contact_create |
Create a new contact |
contact_update |
Update contact information |
contact_delete |
Delete a contact |
contact_create_list |
Create a contact list |
contact_add_to_list |
Add contacts to a contact list |
contact_export |
Export contacts |
search_contacts |
Search contacts by query |
๐ File Tools
| Tool |
Description |
file_list |
Browse OneDrive files and folders |
file_get |
Download file content |
file_create |
Upload files to OneDrive |
file_update |
Update existing file content |
file_delete |
Delete files |
file_copy |
Copy files |
file_move |
Move files |
file_rename |
Rename files |
file_share |
Create sharing links |
file_download_url |
Get a temporary download URL |
folder_list |
List OneDrive folders |
folder_get |
Get folder metadata |
folder_get_tree |
Build a recursive folder tree |
folder_create |
Create folders |
folder_move |
Move folders |
folder_rename |
Rename folders |
folder_delete |
Delete folders |
search_files |
Search files in OneDrive |
๐ Email Folder And Rule Tools
| Tool |
Description |
emailfolders_list |
List mail folders |
emailfolders_get |
Get mail folder metadata |
emailfolders_get_tree |
Build a recursive mail folder tree |
emailfolders_create |
Create mail folders |
emailfolders_rename |
Rename mail folders |
emailfolders_move |
Move mail folders |
emailfolders_delete |
Delete mail folders |
emailfolders_mark_all_as_read |
Mark a folder as read |
emailfolders_empty |
Empty a mail folder |
emailrules_list |
List inbox rules |
emailrules_get |
Get a rule |
emailrules_create |
Create a rule |
emailrules_update |
Update a rule |
emailrules_delete |
Delete a rule |
emailrules_move_top, emailrules_move_bottom, emailrules_move_up, emailrules_move_down |
Reorder rules |
๐ ๏ธ Utility Tools
| Tool |
Description |
search_unified |
Search across emails, events, files, and contacts |
account_list |
Show authenticated Microsoft accounts |
account_authenticate |
Start authentication for a new Microsoft account |
account_complete_auth |
Complete authentication after entering the device code |
server_get_version |
Return server version metadata |
๐๏ธ Cache Management Tools
| Tool |
Description |
cache_get_stats |
View cache statistics (size, entries, hit rate) |
cache_invalidate |
Manually invalidate cache entries by pattern |
cache_task_get_status |
Check status of queued cache tasks |
cache_task_list |
List all cache tasks by account or status |
cache_warming_status |
View cache warming/background refresh status |
โก High-Performance Caching
M365 MCP includes an intelligent caching system that dramatically improves performance by reducing redundant API calls to Microsoft Graph.
Key Features
- ๐ AES-256 Encryption: Cached data is encrypted at rest using SQLCipher by default
- โก 300x Performance Boost: Common operations like
folder_get_tree go from 30s โ <100ms
- ๐ง Intelligent TTL: Three-state cache (Fresh/Stale/Expired) with automatic refresh
- ๐ฆ Automatic Compression: Large entries (โฅ50KB) automatically compressed (70-80% size reduction)
- ๐ Optional Cache Warming: Set
M365_MCP_CACHE_WARMING=true to start the background worker, startup warming, and stale-cache refresh queue
- ๐ฏ Smart Invalidation: Write operations automatically invalidate related caches
- ๐ Multi-Account: Complete isolation between different accounts
- โ
Compliance Ready: Encryption and retention controls for regulated deployments
Performance Benchmarks
| Operation |
Without Cache |
With Cache |
Speedup |
folder_get_tree |
30s |
<100ms |
300x |
email_list |
2-5s |
<50ms |
40-100x |
file_list |
1-3s |
<30ms |
30-100x |
| Cache Hit Rate |
N/A |
>80% |
70%+ API call reduction |
Cache Configuration
The cache works automatically, but you can control its behavior:
folder_get_tree(account_id, path="/Documents")
folder_get_tree(account_id, path="/Documents", force_refresh=True)
email_list(account_id, folder="inbox", use_cache=False)
Cache Security
- Encryption: AES-256 encryption via SQLCipher. If SQLCipher is missing while encryption is enabled, startup fails instead of silently using plaintext.
- Key Storage: System keyring (macOS Keychain, Windows Credential Manager, Linux Secret Service)
- Fallback: Environment variable
M365_MCP_CACHE_KEY for headless servers; if neither keyring nor the env var is available, a generated ephemeral key is used with a warning
- Plaintext Mode: Only used when cache encryption is explicitly disabled by code, primarily for tests and diagnostics
Cache Management
View cache statistics:
stats = cache_get_stats()
Manually invalidate cache:
cache_invalidate("email_*")
cache_invalidate("email_*", account_id="account-123")
๐ For complete cache documentation, see CLAUDE.md
๐ ๏ธ Manual Setup
1. Azure App Registration
- Go to Azure Portal โ Microsoft Entra ID โ App registrations
- New registration โ Name:
m365-mcp
- Supported account types: Personal + Work/School
- Authentication โ Allow public client flows: Yes
- API permissions โ Add these delegated permissions:
- offline_access (required for refresh tokens; the CLI retries against the consumers authority if a personal account flags it as reserved)
- Mail.ReadWrite
- Calendars.ReadWrite
- Files.ReadWrite
- Contacts.Read
- People.Read
- User.Read
- Copy Application ID
2. Installation
git clone https://github.com/robin-collins/m365-mcp.git
cd m365-mcp
uv sync
3. Authentication
export M365_MCP_CLIENT_ID="your-app-id-here"
uv run authenticate.py
uv run authenticate.py --re-auth <account-id-or-email>
uv run authenticate.py --remove <account-id-or-email>
4. Claude Desktop Configuration
Add to your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"microsoft": {
"command": "uvx",
"args": ["--from", "git+https://github.com/robin-collins/m365-mcp.git", "m365-mcp"],
"env": {
"M365_MCP_CLIENT_ID": "your-app-id-here"
}
}
}
}
Or for local development:
{
"mcpServers": {
"m365-mcp": {
"command": "uv",
"args": ["--directory", "c:\\projects\\m365-mcp", "run", "m365-mcp"],
"env": {
"M365_MCP_CLIENT_ID": "your-app-id-here"
}
}
}
}
๐ฆ Transport Modes
M365 MCP supports two transport modes for different use cases:
stdio (Default) - For Desktop Apps
Use for: Claude Desktop, local MCP clients
Security: Inherently secure through process isolation (no authentication required)
export M365_MCP_CLIENT_ID="your-app-id"
uv run m365-mcp
Streamable HTTP - For Web/API Access
Use for: Web applications, remote access, multi-client scenarios
Security: โ ๏ธ Requires authentication (bearer token or OAuth)
Protocol: Uses MCP Streamable HTTP (spec 2025-03-26+)
export MCP_AUTH_TOKEN=$(openssl rand -hex 32)
export M365_MCP_CLIENT_ID="your-app-id"
export MCP_TRANSPORT="http"
export MCP_AUTH_METHOD="bearer"
export MCP_HOST="127.0.0.1"
export MCP_PORT="8000"
uv run m365-mcp
Client connection:
from mcp.client.http import http_client
async with http_client(
"http://localhost:8000/mcp",
headers={"Authorization": f"Bearer {your_token}"}
) as (read, write):
๐ See SECURITY.md for complete security guide and authentication options
๐ฅ Multi-Account Support
Account-scoped tools require an account_id argument. Established public tool signatures keep their historical parameter order for compatibility, so use the tool schema or examples for exact ordering instead of assuming account_id is always first.
accounts = account_list()
account_id = accounts[0]["account_id"]
email_send(account_id, "user@example.com", "Subject", "Body", confirm=True)
email_list(account_id, limit=10, include_body=True)
calendar_create_event(account_id, "Meeting", "2024-01-15T10:00:00Z", "2024-01-15T11:00:00Z")
๐ง๐ป Development
uv run pytest tests/ -v
uv run pyright
uvx ruff format .
uvx ruff check --fix --unsafe-fixes .
๐ค Example: AI Assistant Scenarios
Smart Email Management
accounts = account_list()
account_id = accounts[0]["account_id"]
emails = email_list(account_id, limit=10, include_body=True)
email_reply(account_id, email_id, "Thanks for your message. I'll review and get back to you.", confirm=True)
email = email_get(email_id, account_id)
for attachment in email["attachments"]:
email_get_attachment(
email_id,
attachment["id"],
f"C:/Users/you/Downloads/{attachment['name']}",
account_id,
)
Intelligent Scheduling
accounts = account_list()
account_id = accounts[0]["account_id"]
availability = calendar_check_availability(account_id, "2024-01-15T10:00:00Z", "2024-01-15T18:00:00Z", ["colleague@company.com"])
calendar_create_event(
account_id,
"Project Review",
"2024-01-15T14:00:00Z",
"2024-01-15T15:00:00Z",
location="Conference Room A",
body="Quarterly review of project progress",
attendees=["colleague@company.com", "manager@company.com"]
)
๐ Security Notes
- Tokens are cached locally in
~/.m365_mcp_token_cache.json
- Cache data is encrypted at rest using AES-256 SQLCipher in
~/.m365_mcp_cache.db
- Encryption keys are loaded from system keyring or
M365_MCP_CACHE_KEY; generated non-persistent keys produce a warning
- SQLCipher is required when cache encryption is enabled; plaintext cache mode is only used when explicitly requested by code
- Use app-specific passwords if you have 2FA enabled
- Only request permissions your app actually needs
- Consider using a dedicated app registration for production
๐ ๏ธ Troubleshooting
- Authentication fails: Check your CLIENT_ID is correct
- "Need admin approval": Use
M365_MCP_TENANT_ID=consumers for personal accounts
- Missing permissions: Ensure all required API permissions are granted in Azure
- Token errors: Delete
~/.m365_mcp_token_cache.json and re-authenticate
- Cache issues: Delete
~/.m365_mcp_cache.db to reset cache. If the stored key cannot open the database, the cache is recreated automatically.
- Slow first requests: Normal on a cold cache. Set
M365_MCP_CACHE_WARMING=true to enable startup warming and stale-cache background refresh.
๐ License
MIT