Outlook日历MCP服务器
用于Microsoft Outlook日历的模型上下文协议(MCP)服务器,通过Microsoft Graph API与OAuth 2.0身份验证集成。
特性
- OAuth 2.0身份验证:通过自动令牌刷新保护Microsoft OAuth流
- MCP协议支持:全面实施模型上下文协议
- Outlook日历操作:
- 使用高级筛选器搜索事件 - 获取单个事件详细信息 - 批量获取多个事件 - 列出日期范围内的事件 - 获取用户配置文件信息
- 会话管理:具有自动令牌刷新功能的持久会话
- TypeScript:完全使用TypeScript类型,以获得更好的开发体验
- Cloudflare员工:可以部署为Cloudflare Worker进行无服务器操作
先决条件
- Node.js 18+
- 启用Microsoft Graph API的Microsoft Azure应用程序注册
- OAuth 2.0凭据(客户端ID和客户端密钥)
设置
1.Microsoft Azure配置
- 首选 Azure门户
- 导航至 Azure Active Directory → 应用程序注册
- 点击 新注册
- 配置您的应用程序:
- 姓名: Outlook Calendar MCP Server - 支持的帐户类型:根据您的需求进行选择 - 重定向URI: http://localhost:3003/oauth/callback (网络)
- 创建后,请注意您的 应用程序(客户端)ID 和 目录(租户)ID
- 首选 证书和秘密 → 新客户机密
- 添加描述和过期时间 - 立即复制机密值(您将不会再看到它)
- 首选 API权限 → 添加权限
- 选择 Microsoft Graph → 委托权限 - 添加这些权限: - Calendars.Read - User.Read - 点击 授予管理员同意 (如果您有管理员权限)
2.安装
# Clone or navigate to the project directory
cd outlook-calendar-mcp-server
# Install dependencies
npm install3.配置
创建一个 .env 根目录中的文件:
cp env.example .env编辑 .env 根据您的配置:
# Server Configuration
PORT=3003
NODE_ENV=development
# Microsoft OAuth Configuration
MICROSOFT_CLIENT_ID=your_microsoft_client_id_here
MICROSOFT_CLIENT_SECRET=your_microsoft_client_secret_here
MICROSOFT_TENANT_ID=common
MICROSOFT_REDIRECT_URI=http://localhost:3003/oauth/callback
# Frontend URL (where to redirect after OAuth)
FRONTEND_URL=http://localhost:5173
# MCP Server Configuration
MCP_SERVER_NAME=outlook-calendar-mcp-server
MCP_SERVER_VERSION=1.0.0注: 使用 common 对于多租户应用,或者对于单租户应用,您的特定租户ID。
用法
发展模式
npm run dev生产模式
# Build
npm run build
# Start
npm startCloudflare员工部署
# Create KV namespace for sessions
npm run kv:create
# Update wrangler.toml with the KV namespace ID
# Deploy
npm run deployAPI终点
健康检查
GET /healthOAuth流
1.启动授权
GET /oauth/authorize?userId={userId}&state={state}答复:
{
"authorizationUrl": "https://login.microsoftonline.com/...",
"state": "your-state-value"
}2.OAuth回调(自动处理)
GET /oauth/callback?code={code}&state={state}3.刷新令牌
POST /oauth/refresh
Content-Type: application/json
{
"userId": "user123",
"refreshToken": "refresh_token_here"
}4.断开连接
POST /oauth/disconnect
Content-Type: application/json
{
"userId": "user123"
}MCP端点
POST /mcp
GET /mcp
DELETE /mcpMCP端点遵循工具执行的模型上下文协议规范。
MCP工具
1.展望_日历_搜索_事件
使用日期筛选器和其他条件搜索Outlook日历事件。
输入:
{
"userId": "user123",
"startDateTime": "2024-01-01T00:00:00",
"endDateTime": "2024-12-31T23:59:59",
"subject": "Meeting",
"location": "Conference Room",
"category": "Work",
"top": 20,
"skip": 0,
"orderBy": "start/dateTime"
}输出:
{
"events": [
{
"id": "event123",
"subject": "Team Meeting",
"startDateTime": "2024-01-15T10:00:00",
"endDateTime": "2024-01-15T11:00:00",
"timeZone": "Pacific Standard Time",
"location": "Conference Room A",
"organizer": "organizer@example.com",
"attendees": [
{
"email": "attendee@example.com",
"name": "John Doe",
"response": "accepted"
}
],
"isAllDay": false,
"webLink": "https://outlook.office365.com/...",
"onlineMeetingUrl": "https://teams.microsoft.com/..."
}
],
"count": 1
}所需范围: Calendars.Read
2.展望_日历_蚀刻_事件
按ID检索单个日历事件的详细信息。
输入:
{
"userId": "user123",
"eventId": "event123"
}输出:
{
"event": {
"id": "event123",
"subject": "Team Meeting",
"bodyPreview": "Discuss Q4 goals...",
"startDateTime": "2024-01-15T10:00:00",
"endDateTime": "2024-01-15T11:00:00",
"location": "Conference Room A",
"organizer": "organizer@example.com"
}
}所需范围: Calendars.Read
3.展望_日历_蚀刻_事件_批处理
通过ID在一次呼叫中检索多个事件。
输入:
{
"userId": "user123",
"eventIds": ["event123", "event456", "event789"]
}输出:
{
"events": [
{
"id": "event123",
"subject": "Team Meeting",
"startDateTime": "2024-01-15T10:00:00",
"endDateTime": "2024-01-15T11:00:00"
},
{
"id": "event456",
"subject": "Client Call",
"startDateTime": "2024-01-16T14:00:00",
"endDateTime": "2024-01-16T15:00:00"
}
],
"count": 2
}所需范围: Calendars.Read
4.展望日历列表事件
列出特定日期范围内的日历事件。
输入:
{
"userId": "user123",
"startDateTime": "2024-01-01T00:00:00",
"endDateTime": "2024-01-31T23:59:59",
"top": 50,
"skip": 0
}输出:
{
"events": [
{
"id": "event123",
"subject": "Team Meeting",
"startDateTime": "2024-01-15T10:00:00",
"endDateTime": "2024-01-15T11:00:00",
"location": "Conference Room A"
}
],
"count": 1
}所需范围: Calendars.Read
5.展望_日历_get.profile
检索当前用户的Microsoft配置文件信息。
输入:
{
"userId": "user123"
}输出:
{
"profile": {
"id": "user-uuid",
"displayName": "John Doe",
"givenName": "John",
"surname": "Doe",
"mail": "john.doe@example.com",
"userPrincipalName": "john.doe@company.com",
"jobTitle": "Software Engineer",
"officeLocation": "Building 1",
"mobilePhone": "+1234567890",
"businessPhones": ["+0987654321"]
}
}所需范围: User.Read
建筑
┌─────────────────┐
│ Frontend │
│ (ZeroTwo) │
└────────┬────────┘
│
│ OAuth Flow
▼
┌─────────────────┐ ┌──────────────────┐
│ Outlook │◄────►│ Microsoft OAuth │
│ Calendar MCP │ │ & Graph API │
│ Server │ └──────────────────┘
└────────┬────────┘
│
│ MCP Protocol
▼
┌─────────────────┐
│ Backend │
│ (ZeroTwoApi) │
└─────────────────┘发展
项目结构
outlook-calendar-mcp-server/
├── src/
│ ├── auth/
│ │ └── oauth-manager.ts # OAuth token management
│ ├── config/
│ │ └── index.ts # Configuration management
│ ├── outlook/
│ │ └── client.ts # Microsoft Graph API wrapper
│ ├── mcp/
│ │ ├── server.ts # MCP server implementation
│ │ └── tools.ts # MCP tool definitions
│ ├── types/
│ │ └── index.ts # TypeScript type definitions
│ ├── utils/
│ │ └── logger.ts # Logging utility
│ ├── index.ts # Entry point
│ └── worker.ts # Cloudflare Worker entry point
├── package.json
├── tsconfig.json
├── wrangler.toml
├── env.example
└── README.md脚本
npm run dev-使用热重新加载启动开发服务器npm run dev:worker-启动Cloudflare Workers开发模式npm run build-将TypeScript构建为JavaScriptnpm run start-启动生产服务器npm run deploy-部署到Cloudflare Workersnpm run lint-运行ESLintnpm run format-使用Prettier格式化代码
Microsoft Graph API参考
此服务器使用以下Microsoft Graph API终结点:
- 事件:
GET /me/events - 单一事件:
GET /me/events/{eventId} - 批量请求:
POST /$batch - 用户档案:
GET /me
有关更多信息,请参见 Microsoft Graph Calendar API文档.
安全考虑
- OAuth令牌:令牌存储在内存(Node.js)或KV(Cloudflare Workers)中。对于生产,考虑加密存储。
- 跨域资源共享:为生产适当配置CORS源。
- 超文本传输安全协议:在生产环境中始终使用HTTPS进行安全通信。
- 环境变量:从不承诺
.env文件夹。在生产中使用安全的秘密管理。 - 速率限制:对生产部署实施速率限制。
- 租户ID:使用特定的租户ID,而不是
common对于单租户应用程序。
故障排除
OAuth错误
- “缺少必需的环境变量”:检查您的
.env文件包含所有必需的变量 - “交换授权码失败”:在Azure门户中验证您的重定向URI是否完全匹配
- “令牌已过期”:如果刷新令牌可用,服务器会自动刷新令牌
- “AADST50011:请求中指定的回复URL不匹配”:确保Azure中的重定向URI与您的配置匹配
MCP连接问题
- “没有有效的会话ID”:确保MCP客户端发送正确的会话标头
- “需要身份验证”:用户需要先完成OAuth流程
Microsoft Graph API错误
- “401未经授权”:令牌可能已过期或无效。尝试重新验证。
- “403禁止”:检查是否授予了所有必需的权限,并提供了管理员同意。
- “404未找到”:验证事件ID或资源是否存在。
Microsoft Graph API范围
此服务器需要以下Microsoft Graph作用域:
| 范围 | 类型 | 描述 | 需要管理员同意 |
|---|---|---|---|
Calendars.Read | 委派 | 读取用户日历 | 否 |
User.Read | 委派 | 读取用户配置文件 | 否 |
与ZeroTwo集成
要将此Outlook日历MCP服务器与ZeroTwo应用程序集成,请执行以下操作:
1.添加OAuth提供程序配置
为Outlook日历创建新的OAuth提供程序配置:
// In your OAuth providers configuration
outlook_calendar: {
provider: "outlook_calendar",
clientId: import.meta.env.VITE_MICROSOFT_CLIENT_ID,
flowType: OAuthFlowType.REDIRECT,
scopes: [
"https://graph.microsoft.com/Calendars.Read",
"https://graph.microsoft.com/User.Read",
],
authEndpoint: "http://localhost:3003/oauth/authorize",
backendExchangeEndpoint: "/api/auth/outlook/callback",
backendRefreshEndpoint: "/api/auth/outlook/refresh",
mcpEnabled: true,
mcpEndpoint: "http://localhost:3003/mcp",
}2.更新MCP客户端
将Outlook日历支持添加到MCP客户端配置中。
3.后端集成
创建后端端点来处理OAuth回调和令牌管理,将令牌存储在用户配置文件中。
许可证
麻省理工学院
贡献
欢迎投稿!请随时提交拉取请求。
支持
对于问题和疑问:
- 检查 故障排除 部分
- 审查 Microsoft Graph API文档
- 在GitHub上打开一个问题
______________________________________________________________________
由ZeroTwo提供技术支持
此Outlook日历MCP连接器是 ZeroTwo人工智能平台 --一体化的人工智能工作区,让您通过GPT-5、Claude和Gemini安排会议、管理事件并自动化您的Microsoft日历。
| 🌐 ZeroTwo——一个应用程序中的所有AI模型 | 使用GPT-5、Claude和Gemini管理您的Outlook日历,所有这些都在一个AI工作区中。 |
| ✨ 零两个功能 | 人工智能日程安排、电子邮件起草、网络搜索和MCP支持的Microsoft 365工具。 |
| 🤖 人工智能模型——GPT-5、克劳德和双子座 | 使用世界上最好的人工智能预订会议、查找可用性和管理时间。 |
| 🔌 ZeroTwo连接器和集成 | 将Outlook日历、Gmail、团队、SharePoint等连接到您的AI工作流程。 |
| 💰 零二定价 | 一个替代ChatGPT Plus、Claude Pro和Gemini Advanced的订阅。 |
| 📝 ZeroTwo博客 | AI生产力提示、Microsoft 365指南和ZeroTwo产品更新。 |
| 🚀 免费试用ZeroTwo | 让AI管理您的Outlook日程安排——立即免费开始。 |
专为ZeroTwo打造 --使用此Outlook日历MCP服务器 ZeroTwo的AI连接器系统 通过人工智能助手中的自然语言创建事件、检查日程安排和管理会议。
