M365 MCP Server
An MCP server for Microsoft 365 administration using the Microsoft Graph API, enabling user, group, and mailbox management.
README
M365 MCP Server
A Model Context Protocol (MCP) server for Microsoft 365 administration using the Microsoft Graph API.
🚀 Features
- User Management: Create, read, update, delete users and their mailboxes
- Microsoft 365 Groups: Full CRUD operations for Microsoft 365 Groups, including member and owner management
- Shared Mailboxes: List and manage shared mailboxes (read-only via Graph API, PowerShell required for member management)
- Mailbox Operations: Delegate mailboxes and convert user mailboxes to shared (PowerShell instructions provided)
- Enhanced Error Handling: Comprehensive error reporting with troubleshooting guidance and Graph API limitation explanations
🛠️ Setup
1. Azure App Registration
- Go to Azure Portal → "Azure Active Directory" → "App registrations"
- Click "New registration"
- Name your application
- Supported account types: "Accounts in this organizational directory only"
- Click "Register"
2. Configure Permissions
-
Go to "API permissions" in your app registration
-
Click "Add a permission" → "Microsoft Graph" → "Application permissions"
-
Add these required permissions:
User Management:
User.ReadWrite.All- Required for all user operations (create, read, update, delete users)Directory.ReadWrite.All- Required for user directory operations and license management
Group Management:
Group.ReadWrite.All- Required for Microsoft 365 Groups operations (create, manage members/owners)
Mailbox Operations:
MailboxSettings.ReadWrite.All- Required for mailbox settings and calendar permissions
License Management:
User.ReadWrite.All(already listed above) - Covers license assignment operations
-
Click "Grant admin consent for [Your Organization]"
3. Important Notes About Permissions
⚠️ Graph API Limitations:
- Shared Mailboxes: Cannot add/remove members via Graph API - requires Exchange Online PowerShell
- Mailbox Delegation: Cannot delegate mailbox access via Graph API - requires Exchange Online PowerShell
- Distribution Lists: Cannot manage members via Graph API - requires Exchange Online PowerShell
- Mailbox Type Conversion: Cannot convert mailbox types via Graph API - requires Exchange Online PowerShell
✅ What Works with Graph API:
- User creation, updates, deletion
- Microsoft 365 Groups management
- Basic mailbox settings retrieval
- License assignment and removal
- User account enable/disable
4. Create Client Secret
- Go to "Certificates & secrets" in your app registration
- Click "New client secret"
- Description:
MCP Server Secret - Expiration: Choose appropriate duration
- Copy the Value (not the ID) - this is your
CLIENT_SECRET
5. Get Credentials
Copy these values from your app registration:
- Application (client) ID →
CLIENT_ID - Directory (tenant) ID →
TENANT_ID - Client Secret Value →
CLIENT_SECRET
🚀 Installation
1. Install Dependencies
pip3 install -r requirements.txt
2. Configure Environment
Create a .env file:
TENANT_ID=your_tenant_id_here
CLIENT_ID=your_client_id_here
CLIENT_SECRET=your_client_secret_here
3. Run the Server
python3 m365_mcp_server.py
🖥️ Claude Desktop Integration
Add this to your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"m365-admin": {
"command": "python3",
"args": ["/path/to/your/m365-mcp/m365_mcp_server.py"],
"env": {
"TENANT_ID": "your_tenant_id_here",
"CLIENT_ID": "your_client_id_here",
"CLIENT_SECRET": "your_client_secret_here"
}
}
}
}
🔍 Troubleshooting
PowerShell Requirements
Many operations require Exchange Online PowerShell:
- Shared mailbox member management
- Mailbox delegation
- Distribution list member management
- Mailbox type conversion
To install Exchange Online PowerShell:
Install-Module -Name ExchangeOnlineManagement
Connect-ExchangeOnline
Common Error Codes
- 401 Unauthorized: Token expired or insufficient permissions
- 403 Forbidden: Missing API permissions or admin consent not granted
- 404 Not Found: Resource doesn't exist or email address is incorrect
- 400 Bad Request: Invalid request format or missing required properties
- 409 Conflict: Resource already exists
Authentication Issues
- Check Environment Variables: Ensure all three variables are set
- Verify App Registration: Confirm app exists and has correct permissions
- Grant Admin Consent: Ensure admin consent is granted for all permissions
- Check Client Secret: Verify secret is valid and not expired
API Permission Issues
- Review Permissions: Ensure all required permissions are added:
User.ReadWrite.AllDirectory.ReadWrite.AllGroup.ReadWrite.AllMailboxSettings.ReadWrite.All
- Check Permission Type: Use "Application permissions" not "Delegated permissions"
- Grant Admin Consent: Click "Grant admin consent" in Azure Portal
- Wait for Propagation: Changes may take up to 15 minutes to propagate
Graph API Limitations
Expected Behaviors (Not Errors):
- Shared mailbox member management fails: This is expected - use PowerShell
Add-MailboxPermission - Mailbox delegation fails: This is expected - use PowerShell
Add-MailboxPermission - Distribution list member management fails: This is expected - use PowerShell
Add-DistributionGroupMember - Mailbox type conversion fails: This is expected - use PowerShell
Set-Mailbox -Type Shared
Common Issues
- "pip command not found": Use
pip3instead ofpip - "Permission denied" (403): Ensure admin consent is granted for all permissions
- "Resource not found" (404): Check if the user/group exists and verify email addresses
- "Unsupported query" (400): Usually indicates Graph API limitation - use PowerShell instead
- "Authorization denied" (403): Check if the operation is supported by Graph API
- Microsoft 365 Group membership restrictions: Some groups may have restricted membership management
- Shared mailbox operations: Most shared mailbox operations require Exchange Online PowerShell
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。