Exchange EWS MCP
A local MCP server for on-premises Microsoft Exchange, connecting via EWS and NTLM. It provides mail, template, availability, and calendar workflow tools through stdio, with draft-first safety and Windows Credential Manager integration.
README
Exchange EWS MCP
English | 简体中文
A local, draft-first Model Context Protocol (MCP) server for on-premises Microsoft Exchange. It connects through EWS and NTLM, keeps credentials in Windows Credential Manager, and exposes focused mail and calendar tools to MCP clients over stdio.
[!IMPORTANT] This project is designed for on-premises Exchange environments that expose EWS with NTLM. It is not an OAuth client for Exchange Online or Microsoft Graph.
Why this project
- Local by design — the MCP server runs on the user's Windows machine; no relay service is required.
- Draft-first safety — mail-writing tools create drafts and never send automatically.
- Explicit meeting sends — invitations require an explicit confirmation path.
- Focused tool surface — 18 production tools cover identity, mail, templates, availability, and calendar workflows.
- Opaque local references — Agents work with
message_ref,draft_ref, andtemplate_refinstead of raw Exchange identifiers. - Conversation-aware templates — EWS
UniqueBodyis preferred so quoted history is excluded before a reusable format is stored. - Server-side template rendering — complete templates stay local; the Agent provides only new content when using
template_ref.
Safety model
Exchange EWS MCP intentionally places several boundaries between an Agent and Exchange:
| Boundary | Behavior |
|---|---|
| Credentials | Passwords are stored in Windows Credential Manager, not in project files or MCP responses. |
| Mail writes | Compose, reply, and forward workflows create unsent drafts. |
| Meeting invitations | Sending requires an explicit confirmation flag. |
| Exchange identifiers | Item IDs and change keys remain behind expiring local references. |
| Ambiguous matches | The server returns candidates and a resumable confirmation token. |
| Template HTML | Complete HTML stays in local state; large tool results contain compact previews only. |
| Attachments | Paths are constrained, and template resources are validated before a draft is created. |
These controls reduce risk, but they do not replace Exchange permissions, server policy, MCP client controls, or user review.
Architecture
flowchart LR
A["MCP client / Agent"] -->|stdio| S["Exchange EWS MCP"]
S --> W["Mail and calendar workflows"]
W --> E["EWS client + NTLM"]
E --> X["On-premises Exchange"]
W --> R["Local opaque-reference store"]
S --> C["Windows Credential Manager"]
The production server exposes semantic workflows. A separate debug server adds six lower-level EWS write primitives for protocol troubleshooting.
Requirements
- Windows 10/11 or Windows Server
- Python 3.10 or newer
- An on-premises Microsoft Exchange EWS endpoint reachable from the machine
- An Exchange account allowed to use EWS with NTLM
- An MCP client that supports local stdio servers
Quick start
1. Clone and install
git clone https://github.com/ShermanGu/exchange-ews-mcp.git
cd exchange-ews-mcp
.\install.cmd
The installer creates .venv, installs the package and dependencies, and verifies the installed package version.
2. Configure Exchange
.\.venv\Scripts\exchange-ews-mcp.exe configure
.\.venv\Scripts\exchange-ews-mcp.exe set-current-user `
--email "you@company.example" `
--display-name "Your Name"
.\.venv\Scripts\exchange-ews-mcp.exe status
.\.venv\Scripts\exchange-ews-mcp.exe test
configure prompts for the EWS URL, username, and password. The password is written to Windows Credential Manager.
3. Generate MCP configuration
.\.venv\Scripts\exchange-ews-mcp.exe mcp-config
Equivalent configuration:
{
"mcpServers": {
"exchange-ews": {
"command": "D:\\tools\\exchange-ews-mcp\\.venv\\Scripts\\python.exe",
"args": ["-m", "exchange_ews_mcp.server"]
}
}
}
Restart the MCP client after changing its server configuration. Use the production server for normal operation; reserve exchange_ews_mcp.debug_server for troubleshooting.
4. Verify the local installation
.\.venv\Scripts\exchange-ews-mcp.exe version
.\.venv\Scripts\exchange-ews-mcp.exe tool-list
Production tools
| Area | Tools |
|---|---|
| Identity and mail reads | get_current_user, list_emails, search_emails, get_email, find_email, resolve_people |
| Draft workflows | compose_email, extract_email_template, reply_to_email, forward_email, update_email_draft, add_attachment_to_draft, continue_action |
| Calendar | get_user_availability, list_calendar_events, get_calendar_item, find_meeting_times, schedule_meeting |
See AGENT-TOOLS.md for routing guidance and AGENT-CONNECTION.md for MCP client setup.
Template workflow
Template extraction is read-only and independent from writing a new message or replying:
extract_email_template
↓ template_ref + compact preview
Agent generates only the new content fragment
↓
compose_email or reply_to_email
↓
server renders against the complete local template
The single body-parameter contract is:
- Without
template_ref,body_htmlis the complete HTML body. - With
template_ref,body_htmlis only the new content fragment. - For replies,
message_refselects the conversation and recipients;template_refindependently selects formatting resources.
Example calls:
extract_email_template(...) -> template_ref
compose_email(..., template_ref=template_ref, body_html="<p>New content</p>")
reply_to_email(message_ref=target, template_ref=template_ref, body_html="<p>New reply</p>")
Normal template attachments are not copied unless explicitly requested. Referenced inline cid: resources are copied after preflight validation.
Command-line examples
Extract a template from Sent Items:
.\.venv\Scripts\exchange-ews-mcp.exe extract-email-template `
--folders "Sent Items" `
--subject-contains "weekly report"
Create a templated draft:
.\.venv\Scripts\exchange-ews-mcp.exe compose-email `
--to "recipient@company.example" `
--subject "Weekly project report" `
--html-file ".\new-content.html" `
--template-ref "tmpl_xxx"
Development
py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[test]"
.\.venv\Scripts\python.exe -m pytest -W error::ResourceWarning
The current regression suite contains 185 tests. GitHub Actions runs the strict suite on supported Python versions.
Documentation
| Document | Purpose |
|---|---|
| AGENT-CONNECTION.md | Connect an MCP client and choose the production profile. |
| AGENT-TOOLS.md | Tool inventory and Agent routing guidance. |
| ARCHITECTURE.md | Mail-template architecture and safety properties. |
| TEMPLATE-EXTRACTION.md | Extraction rules, UniqueBody, references, and resources. |
| TEMPLATE-ARCHITECTURE.zh-CN.md | Detailed template architecture in Simplified Chinese. |
| CHANGELOG.md | Release history. |
| CONTRIBUTING.md | Development and pull-request guide. |
| SECURITY.md | Private vulnerability reporting policy. |
Limitations
- The primary runtime target is Windows because credentials use Windows Credential Manager and authentication uses NTLM.
- EWS behavior and availability depend on Exchange version, server configuration, and administrator policy.
- This project does not bypass mailbox permissions or organizational controls.
- Exchange Online tenants should generally prefer Microsoft Graph and modern authentication.
Contributing and security
Contributions are welcome. Start with CONTRIBUTING.md or its Simplified Chinese translation.
Please do not report vulnerabilities in public issues. Follow SECURITY.md or SECURITY.zh-CN.md.
License
Released under the MIT License.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。