Outlook邮件管理服务器

基于Microsoft Identity Platform (MSAL)的Outlook MCP服务器,提供OAuth 2.0认证和完整的邮件管理功能。

  • by EmilyThaHuman
  • 本地部署
  • 更新于
在 GitHub 查看 EmilyThaHuman/outlook-mcp-server

使用说明

Outlook MCP服务器

Microsoft Outlook MCP服务器,使用OAuth 2.0身份验证,使用Microsoft身份平台(SCL)。

特性

  • OAuth 2.0身份验证 -使用Microsoft Identity Platform进行安全身份验证
  • 6个MCP工具 -完整的电子邮件管理功能
  • 会话管理 -自动令牌刷新
  • 基于Express -支持MCP协议的RESTful API
  • Cloudflare员工就绪 -部署到边缘

工具

1. outlook_get_profile

从Microsoft Graph获取用户配置文件信息。

  • 范围: User.Read
  • 退货:用户个人资料,包括显示名称、电子邮件、职位等。

2. outlook_list_messages

列出来自特定文件夹或收件箱的邮件。

  • 范围: Mail.Read
  • 参数:folderId、maxResults、orderBy、筛选、搜索、跳过
  • 退货:包含元数据的消息数组

3. outlook_search_messages

使用查询和筛选器搜索邮件。

  • 范围: Mail.Read
  • 参数:query、maxResults、folderId、orderBy
  • 退货:匹配消息数组

4. outlook_get_recent_emails

获取最近收到的电子邮件。

  • 范围: Mail.Read
  • 参数:maxResults(默认值:10)
  • 退货:最近消息数组

5. outlook_fetch_message

按ID获取一封包含完整详细信息的电子邮件。

  • 范围: Mail.Read
  • 参数:消息ID
  • 退货:用正文内容完成消息对象

6. outlook_fetch_messages_batch

在一个请求中高效地获取多封电子邮件。

  • 范围: Mail.Read
  • 参数:messageIds(数组,最多20个)
  • 退货:消息数组

设置

先决条件

  • Node.js 18+
  • 用于应用程序注册的Microsoft Azure帐户
  • npm或纱线

1.微软应用程序注册

  1. 首选 Azure门户
  2. 导航至 Azure Active Directory > 应用程序注册
  3. 点击 新注册
  4. 配置:
    • 名称: Outlook MCP Server
    • 支持的帐户类型:根据您的需求进行选择
    • 重定向URI: http://localhost:3003/oauth/callback (或您的域名)
  5. 创建后,请注意 应用程序(客户端)ID 和 目录(租户)ID
  6. 首选 证书和秘密 并创建一个新的 客户端密钥
  7. 注意秘密值(仅显示一次)
  8. 首选 API权限 并添加:
    • User.Read
    • Mail.Read
    • offline_access (用于刷新令牌)
  9. 授予管理员权限同意

2.安装

cd outlook-mcp-server
npm install

3.配置

复制示例环境文件:

cp env.example .env

编辑 .env 与你的价值观:

PORT=3003
NODE_ENV=development

# Microsoft OAuth Configuration
MICROSOFT_CLIENT_ID=your_application_client_id
MICROSOFT_CLIENT_SECRET=your_client_secret
MICROSOFT_TENANT_ID=common  # or your specific tenant ID
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-mcp-server
MCP_SERVER_VERSION=1.0.0

4.本地运行

自动重新加载的开发模式:

npm run dev

构建和运行生产:

npm run build
npm start

服务器将于启动 http://localhost:3003

API终点

健康检查

GET /health

OAuth流

1.获取授权URL

GET /oauth/authorize?userId=user123&state=random_state

2.OAuth回调 (自动重定向)

GET /oauth/callback?code=xxx&state=xxx

3.刷新令牌

POST /oauth/refresh
Body: { "userId": "user123", "refreshToken": "xxx" }

4.断开连接

POST /oauth/disconnect
Body: { "userId": "user123" }

MCP协议

初始化会话

POST /mcp
Body: MCP initialize request

工具执行

POST /mcp
Header: mcp-session-id: xxx
Body: MCP tool call request

Cloudflare员工部署

设置

  1. 创建KV命名空间:
npm run kv:create
  1. 更新 wrangler.toml 使用您的KV命名空间ID

  2. 设置秘密:

wrangler secret put MICROSOFT_CLIENT_ID
wrangler secret put MICROSOFT_CLIENT_SECRET
wrangler secret put MICROSOFT_TENANT_ID
wrangler secret put MICROSOFT_REDIRECT_URI
wrangler secret put FRONTEND_URL

部署

npm run deploy

用法示例

// Initialize MCP client
const client = new McpClient({
  url: 'http://localhost:3003/mcp'
});

// Get user profile
const profile = await client.callTool('outlook_get_profile', {
  userId: 'user123'
});

// List recent emails
const emails = await client.callTool('outlook_get_recent_emails', {
  userId: 'user123',
  maxResults: 10
});

// Search emails
const results = await client.callTool('outlook_search_messages', {
  userId: 'user123',
  query: 'from:boss@company.com',
  maxResults: 20
});

// Fetch specific message
const message = await client.callTool('outlook_fetch_message', {
  userId: 'user123',
  messageId: 'AAMkAGI...'
});

建筑

src/
├── auth/
│   └── oauth-manager.ts    # Microsoft OAuth & MSAL integration
├── config/
│   └── index.ts            # Configuration management
├── mcp/
│   ├── server.ts           # MCP server implementation
│   └── tools.ts            # MCP tool definitions
├── outlook/
│   └── client.ts           # Microsoft Graph API client
├── types/
│   └── index.ts            # TypeScript type definitions
├── utils/
│   └── logger.ts           # Logging utility
└── index.ts                # Entry point

Microsoft Graph API范围

  • 用户。阅读:读取用户配置文件
  • 邮件。阅读:读取用户的邮箱
  • 离线访问:通过刷新令牌保持访问权限

错误处理

所有工具返回一致的错误响应:

{
  "content": [
    {
      "type": "text",
      "text": "Error message here"
    }
  ],
  "isError": true
}

安全

  • OAuth 2.0与PKCE流
  • 自动令牌刷新
  • 安全会话存储
  • CORS保护
  • 代码中没有凭据

发展

观看模式:

npm run dev

类型检查:

npm run build

棉绒:

npm run lint

格式:

npm run format

故障排除

身份验证问题

  1. 验证您的Microsoft应用程序注册设置
  2. 检查重定向URI是否完全匹配
  3. 确保添加并同意所有必需的范围
  4. 检查租户ID是否正确(common 适用于多租户)

API错误

  • 检查访问令牌有效性
  • 验证用户是否已授予权限
  • 查看Microsoft Graph API限制
  • 检查网络连接

令牌刷新

如果刷新令牌不起作用:

  1. 确保 offline_access 范围包括在内
  2. 验证 prompt: 'consent' 在身份验证URL中使用
  3. 检查刷新令牌是否正确存储

许可证

麻省理工学院

支持

对于问题和疑问:

  • Microsoft Graph API:https://docs.microsoft.com/graph
  • SOAP节点:https://github.com/AzureAD/microsoft-authentication-library-for-js
  • MCP协议:https://modelcontextprotocol.io

由ZeroTwo提供技术支持

此Outlook MCP连接器是 ZeroTwo人工智能平台 --多功能人工智能工作区,让您通过GPT-5、Claude和Gemini阅读、编写和管理Microsoft Outlook电子邮件。

🌐 ZeroTwo——一个应用程序中的所有AI模型 在一个地方阅读、起草和发送带有GPT-5、Claude和Gemini的Outlook电子邮件。
✨ 零两个功能 人工智能电子邮件管理、文档分析、网络搜索和MCP驱动的Outlook工具。
🤖 人工智能模型——GPT-5、克劳德和双子座 使用世界上最好的人工智能来起草电子邮件、总结帖子和管理收件箱。
🔌 ZeroTwo连接器和集成 将Outlook、Gmail、Teams、Outlook日历等连接到您的AI工作流程。
💰 零二定价 一个替代ChatGPT Plus、Claude Pro和Gemini Advanced的订阅。
📝 ZeroTwo博客 AI电子邮件生产力提示、Microsoft 365指南和ZeroTwo产品更新。
🚀 免费试用ZeroTwo 让AI处理您的Outlook收件箱——立即免费开始。

专为ZeroTwo打造 --使用此Outlook MCP服务器 ZeroTwo的AI连接器系统 在人工智能助手中通过自然语言阅读、搜索、发送和起草电子邮件。