使用说明
微软MCP
适用于Microsoft Graph API的强大MCP服务器-适用于Outlook、日历、OneDrive和联系人的完整人工智能助手工具包。
特性
- 电子邮件管理:读取、发送、回复、管理附件、组织文件夹
- 专业电子邮件模板:KamDental品牌模板,具有自动主题选择功能
- 日历智能:创建、更新、检查可用性、回复邀请
- OneDrive文件:上传、下载、分页浏览
- 联系人:从通讯簿中搜索并列出联系人
- 多账户:支持多个Microsoft帐户(个人、工作、学校)
- 统一搜索:在电子邮件、文件、事件和人员中搜索
Claude Desktop快速入门
# Add Microsoft MCP server (replace with your Azure app ID)
claude mcp add microsoft-mcp -e MICROSOFT_MCP_CLIENT_ID=your-app-id-here -- uvx --from git+https://github.com/elyxlz/microsoft-mcp.git microsoft-mcp
# Start Claude Desktop
claude
使用示例
# Email 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
# Professional email templates
> send a practice report for Baytown location with this month's financial data
> send an executive summary across all locations
> send a provider performance update for Dr. Johnson
> send an alert notification about system downtime
# Calendar examples
> 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
可用工具
电子邮件工具
list_emails-列出包含可选正文内容的电子邮件get_email-获取带有附件的特定电子邮件create_email_draft-创建支持附件的电子邮件草稿send_email-立即发送带有CC/BCC和附件的电子邮件reply_to_email-回复维护线程上下文reply_all_email-回复帖子中的所有收件人update_email-将电子邮件标记为已读/未读move_email-在文件夹之间移动电子邮件delete_email-删除电子邮件get_attachment-获取电子邮件附件内容search_emails-按查询搜索电子邮件
专业电子邮件模板
send_practice_report-发送品牌实践绩效报告send_executive_summary-发送多地点高管概览send_provider_update-发送提供商性能更新send_alert_notification-发送紧急警报和通知
电子邮件模板功能
- 自动主题选择:根据地点/收件人,Baytown(蓝色)、Humble(绿色)或Executive(深色)
- 移动响应:针对所有设备和电子邮件客户端进行了优化
- 专业设计:与KamDental视觉识别一致的品牌
- 性能优化:渲染时间<2秒,总大小<100KB
- 无障碍:WCAG 2.1 AA兼容屏幕阅读器支持
日历工具
list_events-列出日历事件及其详细信息get_event-获取特定事件详细信息create_event-创建包含地点和与会者的活动update_event-重新安排或修改活动delete_event-取消活动respond_event-接受/拒绝/初步回应邀请check_availability-检查空闲/繁忙时间以进行日程安排search_events-搜索日历事件
联系工具
list_contacts-列出所有联系人get_contact-获取具体联系方式create_contact-创建新联系人update_contact-更新联系信息delete_contact-删除联系人search_contacts-按查询搜索联系人
文件工具
list_files-浏览OneDrive文件和文件夹get_file-下载文件内容create_file-将文件上传到OneDriveupdate_file-更新现有文件内容delete_file-删除文件或文件夹search_files-在OneDrive中搜索文件
实用工具
unified_search-在电子邮件、事件和文件中搜索list_accounts-显示经过身份验证的Microsoft帐户authenticate_account-启动新Microsoft帐户的身份验证complete_authentication-输入设备代码后完成身份验证过程
手动设置
1.Azure应用程序注册
- 首选 Azure门户 → 微软Entra ID→ 应用程序注册
- 新注册→ Name:
microsoft-mcp - 支持的帐户类型:个人+工作/学校
- 认证→ 允许公共客户端流:是
- API权限→ 添加这些委派权限:
- 邮件。读写
- 邮件。发送
- 日历。读写
- 文件夹。读写
- 联络。阅读
- 人。阅读
- 用户。阅读
- 复制应用程序ID
2.安装
git clone https://github.com/elyxlz/microsoft-mcp.git
cd microsoft-mcp
uv sync
3.身份验证
# Set your Azure app ID
export MICROSOFT_MCP_CLIENT_ID="your-app-id-here"
# Run authentication script
uv run authenticate.py
# Follow the prompts to authenticate your Microsoft accounts
4.克劳德桌面配置
添加到您的Claude Desktop配置中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"microsoft": {
"command": "uvx",
"args": ["--from", "git+https://github.com/elyxlz/microsoft-mcp.git", "microsoft-mcp"],
"env": {
"MICROSOFT_MCP_CLIENT_ID": "your-app-id-here"
}
}
}
}
或者为了当地发展:
{
"mcpServers": {
"microsoft": {
"command": "uv",
"args": ["--directory", "/path/to/microsoft-mcp", "run", "microsoft-mcp"],
"env": {
"MICROSOFT_MCP_CLIENT_ID": "your-app-id-here"
}
}
}
}
多账户支持
所有工具都需要 account_id 参数作为第一个参数。您可以通过:
- 确切的
home_account_id(推荐) - 账户
username(电子邮件),例如。admin@contoso.com - 关键字
default使用第一个经过身份验证的帐户
# List accounts to get IDs
accounts = list_accounts()
account_id = accounts[0]["account_id"]
# Use account for operations
send_email(account_id, "user@example.com", "Subject", "Body")
list_emails(account_id, limit=10, include_body=True)
create_event(account_id, "Meeting", "2024-01-15T10:00:00Z", "2024-01-15T11:00:00Z")
# Or via username or 'default'
list_emails("admin@contoso.com", limit=10, include_body=True)
list_emails("default", limit=10, include_body=True)
专业电子邮件模板
KamDental电子邮件框架提供专业、品牌化的电子邮件模板:
实践报告示例
await send_practice_report(
account_id="default",
to="manager@kamdental.com",
subject="Baytown Practice Report - January 2024",
location="Baytown",
financial_data={
"production": {"value": 285000, "goal": 300000},
"collections": {"value": 270000, "ratio": 0.947},
"case_acceptance": {"value": 0.72, "goal": 0.75},
"call_answer_rate": {"value": 0.91, "goal": 0.95}
},
provider_data=[
{
"name": "Dr. Sarah Johnson",
"role": "General Dentist",
"production": 125000,
"goal_percentage": 1.04
}
],
period="January 2024",
alerts=[
{
"type": "warning",
"title": "Production Below Target",
"message": "Current production is 5% below monthly target."
}
]
)
执行摘要示例
await send_executive_summary(
account_id="default",
to="executive@kamdental.com",
locations_data=[
{
"name": "Baytown",
"production": 285000,
"target": 300000,
"status": "warning"
},
{
"name": "Humble",
"production": 195000,
"target": 180000,
"status": "ahead"
}
],
period="Q1 2024",
key_insights=[
{
"title": "Overall Performance",
"description": "Combined production at 96% of target"
}
]
)
发展
# Run tests
uv run pytest tests/ -v
# Type checking
uv run pyright
# Format code
uvx ruff format .
# Lint
uvx ruff check --fix --unsafe-fixes .
# Test email framework
uv run python -m microsoft_mcp.email_framework.test_runner
Codex CLI设置
您可以通过添加启动以下命令的MCP服务器条目,从Codex CLI运行此MCP服务器 microsoft-mcp 二进制(或 uvx 命令)与所需的环境变量。
- 添加到Codex配置文件中(调整Codex CLI读取配置的路径):
[mcp_servers.microsoft]
command = "uvx"
args = [
"--from",
"git+https://github.com/elyxlz/microsoft-mcp.git",
"microsoft-mcp",
]
env = { "MICROSOFT_MCP_CLIENT_ID" = "your-azure-app-id", "MICROSOFT_MCP_TENANT_ID" = "common" }
笔记:
MICROSOFT_MCP_CLIENT_ID是必需的(Azure应用程序注册→ 应用程序ID)。- 可选的
MICROSOFT_MCP_TENANT_ID可以是common,您的租户GUID,或consumers个人账户。 - 上述用途
uvx直接从GitHub获取/运行。如果你在本地开发,请使用下面的本地变体。
- 本地开发变体(从您签出的仓库运行):
[mcp_servers.microsoft]
command = "uv"
args = ["--directory", "/path/to/microsoft-mcp", "run", "microsoft-mcp"]
env = { "MICROSOFT_MCP_CLIENT_ID" = "your-azure-app-id", "MICROSOFT_MCP_TENANT_ID" = "common" }
- 启动Codex CLI并确保服务器出现在工具列表中。如果需要身份验证,请使用
auth_operations工具:
auth_operations(action="authenticate")→ 访问URL并输入代码auth_operations(action="status")→ 验证至少一个帐户是否经过身份验证- 使用
account_id="default"或您的电子邮件(例如。,admin@contoso.com)调用工具时
故障排除:
- 如果电子邮件发送在403上返回
/me/sendMail,添加Mail.Send将权限委托给您的Azure应用程序并授予管理员同意。 - 如果通过A
account_id如果不存在,服务器现在会返回一个包含可用帐户列表的明确错误。你也可以通过default使用第一个帐户。
示例:AI助手场景
智能电子邮件管理
# Get account ID first
accounts = list_accounts()
account_id = accounts[0]["account_id"]
# List latest emails with full content
emails = list_emails(account_id, limit=10, include_body=True)
# Reply maintaining thread
reply_to_email(account_id, email_id, "Thanks for your message. I'll review and get back to you.")
# Forward with attachments
email = get_email(email_id, account_id)
attachments = [get_attachment(email_id, att["id"], account_id) for att in email["attachments"]]
send_email(account_id, "boss@company.com", f"FW: {email['subject']}", email["body"]["content"], attachments=attachments)
智能调度
# Get account ID first
accounts = list_accounts()
account_id = accounts[0]["account_id"]
# Check availability before scheduling
availability = check_availability(account_id, "2024-01-15T10:00:00Z", "2024-01-15T18:00:00Z", ["colleague@company.com"])
# Create meeting with details
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"]
)
安全说明
- 令牌在本地缓存在
~/.microsoft_mcp_token_cache.json - 如果您启用了2FA,请使用特定于应用程序的密码
- 仅请求您的应用程序实际需要的权限
- 考虑使用专用的应用程序注册进行生产
故障排除
- 身份验证失败:检查您的CLIENT_ID是否正确
- “需要管理员批准”:使用
MICROSOFT_MCP_TENANT_ID=consumers个人账户 - 缺少权限:确保在Azure中授予所有必需的API权限
- 发送邮件需要
Mail.Send授权权限(除Mail.ReadWrite).失踪Mail.Send通常在以下情况下返回HTTP 403/me/sendMail.
- 发送邮件需要
- 令牌错误:删除
~/.microsoft_mcp_token_cache.json并重新验证
文档
- 电子邮件框架指南 -专业电子邮件模板综合指南
- API文档 -API详细参考
- 例子 -代码示例和用例
- Bug修复:帐户解析挂起 -在以下情况下挂起工具调用的修复细节
account_id不匹配的
许可证
麻省理工学院