Mail MCP
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Mail MCPShow my inbox messages."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Mail MCP (Python + modelcontextprotocol)
这是一个邮件助手 MCP 服务,基于 Python 和官方 MCP Python SDK(mcp 包),并真实对接 Outlook(Microsoft Graph)。
当前版本实现:
MCP 服务入口
Outlook 邮箱读写(Microsoft Graph)
常见邮件助手基础工具(列目录、读邮件、搜索、写草稿、发草稿、撤销草稿)
1. 环境准备
要求:
Python 3.10+
安装:
python -m venv .venv
.venv\\Scripts\\activate
pip install -U pip
pip install -e .Related MCP server: Gmail AutoAuth MCP Server
2. 启动服务
mail-mcp或者:
python -m mail_mcp.server服务进程本身默认使用 HTTP(streamable-http),推荐通过反向代理提供 HTTPS。
2.0 通过 Docker 部署到 Azure App Service
仓库已提供 Dockerfile 和 .dockerignore。
服务在容器内默认监听:
Host:
0.0.0.0Port:
80(也兼容 App Service 注入的PORT)MCP Path:
/mcp
推荐流程:
使用 ACR 云端构建镜像(无需本地 Docker)
az acr build \
--registry <acr-name> \
--image mail-mcp:latest \
.(可选)查看 ACR 中镜像标签
az acr repository show-tags \
--name <acr-name> \
--repository mail-mcp \
--output table在 App Service 使用该镜像(Web App for Containers)
Image source: ACR
Image:
<acr-name>.azurecr.io/mail-mcp:latestContainer port:
80Health check path:
/healthz
MCP 客户端连接地址
https://<app-name>.azurewebsites.net/mcp
部署后验证
https://<app-name>.azurewebsites.net/https://<app-name>.azurewebsites.net/healthz
2.1 Outlook 鉴权配置
服务会按以下优先级获取 Bearer Token:
MCP 请求头中的
Authorization: Bearer <token>(推荐)环境变量
OUTLOOK_ACCESS_TOKEN(调试兜底,Graph 与 EWS 均适用)
可选环境变量:
MAIL_MCP_BACKEND(默认graph,可选graph/ews;决定使用 Microsoft Graph 还是 Exchange Server EWS)GRAPH_BASE_URL(默认https://graph.microsoft.com/v1.0)DELEGATED_TOKEN_LOG_MODE(默认masked,可选masked/full/none)DELEGATED_TOKEN_CACHE_TTL_SECONDS(默认300,token 校验结果缓存秒数)MCP_EXPOSE_AGENTS_MD(默认false,设置为true后对外暴露mailbox_get_agents_md()工具,返回仓库根目录AGENTS.md内容)
后端切换示例:
# 使用 Microsoft Graph(默认)
MAIL_MCP_BACKEND=graph
# 使用 Exchange Server EWS
MAIL_MCP_BACKEND=ewsExchange Server EWS 后端专用环境变量(仅在 MAIL_MCP_BACKEND=ews 时生效;此模式不再兼容用户名/密码认证):
# 选择 EWS 后端
MAIL_MCP_BACKEND=ews
# Exchange Server EWS 终结点(例如 EWS 地址)
EXCHANGE_SERVER_URL=https://exchange.example.com/EWS/Exchange.asmx
# Entra ID / OAuth 2.0 认证信息
EXCHANGE_SERVER_CLIENT_ID=<app-registration-client-id>
EXCHANGE_SERVER_CLIENT_SECRET=<app-registration-client-secret>
EXCHANGE_SERVER_TENANT_ID=<tenant-id>
# 可选:Mailbox 时区,默认 UTC
EXCHANGE_SERVER_TIME_ZONE=Asia/Shanghai注意:
该模式已改为 bearer token 认证,不再接受
EXCHANGE_SERVER_USERNAME/EXCHANGE_SERVER_PASSWORD。EWS 也支持统一的 token 解析顺序:当前请求头中的
Authorization: Bearer <token>优先,未提供时回退到OUTLOOK_ACCESS_TOKEN。EWS 仅从当前登录用户的 bearer token 中解析邮箱,不支持指定邮箱/共享邮箱。
EXCHANGE_SERVER_URL必须指向实际的 EWS/Exchange 端点,不要只填域名。
2.1.1 配置分层(推荐:非敏感入库,敏感留在 App Service)
服务启动时按以下优先级加载配置(高 -> 低):
进程环境变量(例如 Azure App Service 的 App Settings)
仓库根目录
.env(本地私有,不入库)当
APP_ENV已设置时:.env.<APP_ENV>;否则:.env.prod
说明:
项目已支持将
.env.prod提交到 Git(用于非敏感默认值)。机密信息仍应只放在 App Service App Settings(或 Key Vault),不要写入
.env.prod。
建议放入 .env.prod 的示例(非敏感):
MCP_HOST/MCP_PORT/MCP_PATHMAIL_MCP_BACKEND(graph或ews)GRAPH_BASE_URLDELEGATED_TOKEN_LOG_MODEDELEGATED_TOKEN_CACHE_TTL_SECONDSMCP_EXPOSE_AGENTS_MD
建议仅放在 App Service 的示例(敏感/租户强绑定):
AZURE_CLIENT_SECRETMCP_OAUTH_CLIENT_SECRETOUTLOOK_ACCESS_TOKENAZURE_CLIENT_ID/AZURE_TENANT_ID/AZURE_STORAGE_ACCOUNT_NAME
Azure Table(定时发送队列)环境变量:
AZURE_STORAGE_ACCOUNT_NAME(Storage Account 名称)AZURE_STORAGE_TABLE_NAME(可选,默认EmailSendQueue)AZURE_TENANT_ID(Service Principal 租户 ID)AZURE_CLIENT_ID(Service Principal 客户端 ID)AZURE_CLIENT_SECRET(Service Principal 密钥)
Azure Table 所需 RBAC(Service Principal):
建议最小权限:
Storage Table Data Contributor建议作用域:Storage Account 级别(支持表不存在时自动创建)
不建议仅分配
Contributor(管理面权限,通常不包含 Table 数据面读写)
触发批量发送(Service Principal)所需 Graph 应用权限:
Mail.Send(Application)建议同时配置
Mail.ReadWrite(Application)用于草稿与发送流程兼容以上 Application 权限需管理员同意(Admin consent)
当前实现固定使用 /me 路由访问 Outlook 邮箱。
2.1.1 OAuth 2.0 Dynamic discovery
服务支持两种接入模式:
默认兼容模式:客户端直接发送
Authorization: Bearer <Graph token>DCR 模式:当
MCP_OAUTH_DYNAMIC_DISCOVERY_ENABLED=true且MCP_PUBLIC_BASE_URL/MCP_OAUTH_TENANT_ID/MCP_OAUTH_CLIENT_ID/MCP_OAUTH_CLIENT_SECRET完整时,服务会自动暴露 OAuth 元数据与回调端点
启用 DCR 后会提供:
/.well-known/oauth-authorization-server/.well-known/oauth-protected-resource/register//authorize//token//revoke/oauth/callback
运行状态会写入 Azure Table:
OAuthClientRegistry:客户端注册信息OAuthTokenRegistry:state / code / token / Graph token 映射
注意:
MCP 访问令牌由本服务签发并校验
实际调用 Graph 时使用登录过程中获取的用户委托 token
若未启用 DCR,服务保持兼容模式,直接接收
Authorization: Bearer <Graph token>
Token 权限至少满足以下之一:
Mail.Read/Mail.ReadWrite/Mail.SendCalendars.Read/Calendars.ReadWriteMailboxSettings.Read
默认地址:
Host:
127.0.0.1Port:
80Path:
/mcp
2.1.2 重置 VS Code 缓存的动态 Client ID(触发新 client_id)
当浏览器回调出现类似错误时:
{"error":"invalid_request","error_description":"Client ID '<old-client-id>' not found"}通常是 VS Code 侧缓存了旧的 MCP 动态注册信息。可按以下方式重置。
方法一:命令面板清理(推荐)
打开命令面板:
Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(macOS)。执行:
Authentication: Remove Dynamic Authentication Provider。在列表中选择你的 MCP 服务(例如
mail-assist-mcp-local)。确认后,VS Code 会删除该服务对应的动态
client_id和关联认证缓存。下次重新连接 MCP 服务时,会重新走 OAuth/DCR 流程并生成新的
client_id。
方法二:手动清理本地缓存(高级)
完全退出 VS Code。
清理当前用户的 VS Code 缓存目录中与 MCP/OAuth 相关的条目(重点检查
User/globalStorage与User/workspaceStorage)。重新打开 VS Code,再次连接该 MCP 服务,触发新的动态注册。
说明:
你当前仓库的
.vscode/mcp.json仅配置服务器地址,不保存动态client_id。如果服务端也清理了
OAuthClientRegistry,而客户端未清理缓存,也会出现同样错误;此时优先执行方法一。
2.2 反向代理与 HTTPS
建议把 mail-mcp 仅暴露到内网 HTTP,并由 Nginx/Caddy 负责 443 TLS 终结。核心思路是:
后端监听
127.0.0.1:80反向代理转发
/mcp到后端对外仅提供 HTTPS 地址,例如
https://mcp.example.com/mcp
2.3 定时发送
服务提供一个批量发送入口:
GET /jobs/dispatch
它会扫描 Azure Table EmailSendQueue 中已到期的 pending / scheduled 任务,并用 Service Principal 调用 Graph 发送对应草稿。成功写入 sent,失败写入 failed 和 lasterror。
4. 集成说明
本服务通过
/mcp暴露 MCP 工具/mcp请求必须带Authorization: Bearer <token>对于 Copilot Studio,可使用
OAuth 2.0 -> Manual方式接入建议使用独立 Entra 应用注册进行隔离,便于审计、权限控制和密钥轮换
最小推荐 scope:
offline_access openid profile Mail.Read Mail.ReadWrite Mail.Send Calendars.Read Calendars.ReadWrite MailboxSettings.Read
5. 约束与注意事项
Graph 默认后端:
MAIL_MCP_BACKEND=graphEWS 后端仅在
MAIL_MCP_BACKEND=ews时启用,并且仅使用 bearer token,不兼容用户名/密码EWS 只从当前登录用户的 bearer token 中解析邮箱,不支持指定邮箱或共享邮箱
EXCHANGE_SERVER_URL必须指向真实 EWS 端点,不要只填域名OUTLOOK_ACCESS_TOKEN仅用于调试兜底;生产环境应优先使用请求头中的 token
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseBqualityNot gradedmaintenanceThis MCP server enables users to manage emails via POP3 and SMTP protocols, allowing for listing, searching, reading, and sending messages. It also supports fetching email threads and extracting text content from various document attachments including PDFs and Office files.8
- AlicenseNot gradedqualityDmaintenanceAn MCP server enabling AI assistants to manage Gmail through natural language, including sending, reading, searching, labeling, and handling attachments with auto authentication.1MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server for email operations supporting IMAP and SMTP protocols, enabling sending, receiving, searching, and managing emails with attachments.MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server for Gmail that allows AI assistants to read, search, compose drafts, send emails, and manage labels with attachment support.MIT
Related MCP Connectors
Read, search, send, organize, draft and schedule email across your inboxes from any MCP client.
Fully-managed email as MCP tools - register domains, real mailboxes, send and receive mail.
Hosted email MCP for AI agents with inboxes, send/receive, memory, recovery, and credits.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jiabin-24/mail-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server