M365 Agent MCP
Remote MCP server for ChatGPT workspace agents to access Microsoft 365 mailboxes, enabling listing, searching, reading, and sending emails with per-agent mailbox isolation.
README
M365 Agent MCP
A remote MCP server for ChatGPT workspace agents. One Vercel deployment serves multiple agents, and each agent gets access only to the Microsoft 365 mailbox mapped to its secret URL key.
Mailboxes
This project is configured for these three agent mailboxes:
reservations@kwantu.co.zaassistant@kwantu.co.zaassistant@sapphireglobalfs.com
All three mailboxes must exist in the Microsoft 365 tenant identified by TENANT_ID. If one mailbox is in a different tenant, use a separate deployment for that tenant.
Route Shape
Each MCP URL has this shape:
https://<vercel-domain>/api/agents/<agent-key>/mcp
The app route is:
app/api/agents/[agent]/[transport]/route.ts
<agent-key> is a long random secret. The server resolves it through AGENT_MAILBOX_MAP; unknown keys return HTTP 404.
Tools
list_recent_emails: lists recent messages from the mapped mailbox.search_emails: searches messages in the mapped mailbox.read_email: reads one message from the mapped mailbox.send_email: sends HTML email from the mapped mailbox.
No database is used. Secrets and mailbox mapping live only in environment variables.
Microsoft Graph Setup
In Microsoft Entra admin center:
- Create an app registration.
- Create a client secret and copy the secret value immediately.
- Add Microsoft Graph application permissions:
Mail.ReadMail.Send
- Grant admin consent for the tenant.
Recommended tenant safety control: restrict the app to only the three agent mailboxes with an Exchange Online application access policy.
Connect-ExchangeOnline
New-DistributionGroup `
-Name "M365 Agent MCP Mailboxes" `
-Alias "m365-agent-mcp-mailboxes" `
-Type Security `
-PrimarySmtpAddress "m365-agent-mcp-mailboxes@kwantu.co.za"
Add-DistributionGroupMember -Identity "m365-agent-mcp-mailboxes@kwantu.co.za" -Member "reservations@kwantu.co.za"
Add-DistributionGroupMember -Identity "m365-agent-mcp-mailboxes@kwantu.co.za" -Member "assistant@kwantu.co.za"
Add-DistributionGroupMember -Identity "m365-agent-mcp-mailboxes@kwantu.co.za" -Member "assistant@sapphireglobalfs.com"
New-ApplicationAccessPolicy `
-AppId "<CLIENT_ID>" `
-PolicyScopeGroupId "m365-agent-mcp-mailboxes@kwantu.co.za" `
-AccessRight RestrictAccess `
-Description "Restrict M365 Agent MCP to approved agent mailboxes"
Test-ApplicationAccessPolicy -Identity "reservations@kwantu.co.za" -AppId "<CLIENT_ID>"
Test-ApplicationAccessPolicy -Identity "assistant@kwantu.co.za" -AppId "<CLIENT_ID>"
Test-ApplicationAccessPolicy -Identity "assistant@sapphireglobalfs.com" -AppId "<CLIENT_ID>"
Use a different PrimarySmtpAddress for the security group if kwantu.co.za is not an accepted domain in the tenant.
Environment Variables
Set these four variables in Vercel:
TENANT_ID=<directory-tenant-id>
CLIENT_ID=<application-client-id>
CLIENT_SECRET=<client-secret-value>
AGENT_MAILBOX_MAP={"<reservations-key>":"reservations@kwantu.co.za","<kwantu-assistant-key>":"assistant@kwantu.co.za","<sapphire-assistant-key>":"assistant@sapphireglobalfs.com"}
For local development, copy .env.example to .env.local and replace the placeholders.
1. Generate One Random Key Per Agent
From a terminal:
node -e "const crypto=require('crypto'); for (const name of ['reservations','kwantu-assistant','sapphire-assistant']) console.log(name + '=' + crypto.randomBytes(24).toString('hex'))"
Example output shape:
reservations=<reservations-key>
kwantu-assistant=<kwantu-assistant-key>
sapphire-assistant=<sapphire-assistant-key>
Then create the JSON map:
{
"<reservations-key>": "reservations@kwantu.co.za",
"<kwantu-assistant-key>": "assistant@kwantu.co.za",
"<sapphire-assistant-key>": "assistant@sapphireglobalfs.com"
}
When entering AGENT_MAILBOX_MAP in Vercel, paste it as one line with no outer quotes.
2. Set The Four Environment Variables In Vercel
In Vercel:
- Open the project.
- Go to Settings, then Environment Variables.
- Add
TENANT_ID,CLIENT_ID,CLIENT_SECRET, andAGENT_MAILBOX_MAP. - Apply them to Production, Preview, and Development if you want all environments to work.
With the Vercel CLI, you can also run:
vercel env add TENANT_ID production
vercel env add CLIENT_ID production
vercel env add CLIENT_SECRET production
vercel env add AGENT_MAILBOX_MAP production
Repeat for preview and development if needed.
3. Deploy
Install dependencies and verify the build:
npm install
npm run build
Deploy:
vercel --prod
Or push the repo to GitHub and import it into Vercel, then deploy from the Vercel dashboard.
4. Get The Per-Agent MCP URLs
After deployment, use your Vercel production domain and each generated key:
Reservations agent:
https://<vercel-domain>/api/agents/<reservations-key>/mcp
Kwantu assistant agent:
https://<vercel-domain>/api/agents/<kwantu-assistant-key>/mcp
Sapphire assistant agent:
https://<vercel-domain>/api/agents/<sapphire-assistant-key>/mcp
Paste the relevant URL into each ChatGPT workspace agent as its custom MCP server URL.
Local Run
npm install
Copy-Item .env.example .env.local
npm run dev
Local MCP URL:
http://localhost:3000/api/agents/<agent-key>/mcp
The health page is available at:
http://localhost:3000
Validation Checklist
- Unknown agent key returns HTTP 404.
- Each known key can list/read only its mapped mailbox.
send_emailsends from the mapped mailbox and saves to Sent Items.- Exchange Online application access policy test passes for the three allowed mailboxes.
- Exchange Online application access policy test fails for an unrelated mailbox.
Client Secret Renewal
Client secrets expire. Before expiry, create a new secret in the app registration, update CLIENT_SECRET in Vercel, and redeploy.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。