Microsoft 365 MCP 服务器
这是一个通过 Graph API 与 Microsoft 365 和 Microsoft Office 服务交互的 Model Context Protocol (MCP) 服务器。
该服务器支持两种可以全局配置的输出格式:
标准 JSON 输出,带格式化:
{
"value": [
{
"id": "1",
"displayName": "Alice Johnson",
"mail": "alice@example.com",
"jobTitle": "软件工程师"
}
]
}
Token-Oriented Object Notation,用于高效地使用 LLM 令牌:
value[1]{id,displayName,mail,jobTitle}:
"1",Alice Johnson,alice@example.com,软件工程师
优点:
用法: (实验性)全局启用 TOON 格式:
通过 CLI 标志:
npx @softeria/ms-365-mcp-server --toon
通过 Claude Desktop 配置:
{
"mcpServers": {
"ms365": {
"command": "npx",
"args": ["-y", "@softeria/ms-365-mcp-server", "--toon"]
}
}
}
通过环境变量:
MS365_MCP_OUTPUT_FORMAT=toon npx @softeria/ms-365-mcp-server
电子邮件(Outlook)
<sub>list-mail-messages, list-mail-folders, list-mail-folder-messages, get-mail-message, send-mail,
delete-mail-message, create-draft-email, move-mail-message</sub>
日历
<sub>list-calendars, list-calendar-events, get-calendar-event, get-calendar-view, create-calendar-event,
update-calendar-event, delete-calendar-event</sub>
OneDrive 文件
<sub>list-drives, get-drive-root-item, list-folder-files, download-onedrive-file-content, upload-file-content,
upload-new-file, delete-onedrive-file</sub>
Excel 操作
<sub>list-excel-worksheets, get-excel-range, create-excel-chart, format-excel-range, sort-excel-range</sub>
OneNote
<sub>list-onenote-notebooks, list-onenote-notebook-sections, list-onenote-section-pages, get-onenote-page-content,
create-onenote-page</sub>
待办事项任务
<sub>list-todo-task-lists, list-todo-tasks, get-todo-task, create-todo-task, update-todo-task, delete-todo-task</sub>
Planner
<sub>list-planner-tasks, get-planner-plan, list-plan-tasks, get-planner-task, create-planner-task</sub>
联系人
<sub>list-outlook-contacts, get-outlook-contact, create-outlook-contact, update-outlook-contact,
delete-outlook-contact</sub>
用户资料
<sub>get-current-user</sub>
搜索
<sub>search-query</sub>
Teams & 聊天
<sub>list-chats, get-chat, list-chat-messages, get-chat-message, send-chat-message, list-chat-message-replies,
reply-to-chat-message, list-joined-teams, get-team, list-team-channels, get-team-channel, list-channel-messages,
get-channel-message, send-channel-message, list-team-members</sub>
SharePoint 站点
<sub>search-sharepoint-sites, get-sharepoint-site, get-sharepoint-site-by-path, list-sharepoint-site-drives,
get-sharepoint-site-drive-by-id, list-sharepoint-site-items, get-sharepoint-site-item, list-sharepoint-site-lists,
get-sharepoint-site-list, list-sharepoint-site-list-items, get-sharepoint-site-list-item,
get-sharepoint-sites-delta</sub>
共享邮箱
<sub>list-shared-mailbox-messages, list-shared-mailbox-folder-messages, get-shared-mailbox-message,
send-shared-mailbox-mail</sub>
用户管理
<sub>list-users</sub>
要访问工作/学校功能(Teams、SharePoint 等),请使用以下标志之一启用组织模式:
{
"mcpServers": {
"ms365": {
"command": "npx",
"args": ["-y", "@softeria/ms-365-mcp-server", "--org-mode"]
}
}
}
必须从开始就启用组织模式才能访问工作账户功能。没有此标志时,只有个人账户功能(电子邮件、日历、OneDrive � 等)可用。
要访问共享邮箱,您需要:
--org-mode 标志(仅限工作/学校账户)Mail.Read.Shared 或 Mail.Send.Shared 范围user-id 参数查找共享邮箱:使用 list-users 工具来发现组织中的可用用户和共享邮箱。
示例:list-shared-mailbox-messages 中将 user-id 设置为 shared-mailbox@公司.com
测试 Claude Desktop 登录:
要将此 MCP 服务器添加到 Claude Desktop:
编辑设置 > 开发者下的配置文件:
{
"mcpServers": {
"ms365": {
"command": "npx",
"args": ["-y", "@softeria/ms-365-mcp-server"]
}
}
}
claude mcp add ms365 -- npx -y @softeria/ms-365-mcp-server
对于支持 MCP 的其他接口,请参阅其各自的文档以获取正确的集成方法。
对于本地开发或测试:
# 从项目目录
claude mcp add ms -- npx tsx src/index.ts --org-mode
或者手动配置 Claude Desktop:
{
"mcpServers": {
"ms365": {
"command": "node",
"args": ["/绝对路径/to/ms-365-mcp-server/dist/index.js", "--org-mode"]
}
}
}
注意:代码更改后运行
npm run build以更新dist/文件夹。
⚠️ 使用工具之前必须进行认证。
该服务器支持三种认证方法:
用于通过设备代码进行交互式认证:
login 工具(自动检查现有令牌)verify-login 工具确认npx @softeria/ms-365-mcp-server --login
按终端中的 URL 和代码提示操作。令牌被安全地缓存在您的操作系统凭证存储中(如果不可用则回退到文件)。
当使用 --http 运行时,服务器需要OAuth 认证:
npx @softeria/ms-365-mcp-server --http 3000
此模式:
/auth/* 提供 OAuth 端点(授权、令牌、元数据)Authorization: Bearer <token> 对所有 MCP 请求--enable-auth-tools 启用它们)当 MCP 客户端看到宣传的能力时,会自动处理 OAuth 流程。
要使用自定义 Azure 凭据(建议用于生产)的 OAuth 模式,您需要设置一个 Azure AD 应用注册:
npm run inspector):http://localhost:6274/oauth/callbackhttp://localhost:6274/oauth/callback/debughttp://localhost:3000/callback(可选,用于服务器回调).env 文件:
MS365_MCP_CLIENT_ID=您的-azure-ad-app-client-id-这里
MS365_MCP_CLIENT_SECRET=您的-azure-ad-app-client-secret-这里
MS365_MCP_TENANT_ID=common
配置完成后,服务器将使用您的自定义 Azure 应用而不是内置应用。
如果您正在将 ms-365-mcp-server 作为更大系统的一部分运行,并且该系统外部管理 Microsoft OAuth 令牌,您可以直接向此 MCP 服务器提供访问令牌:
MS365_MCP_OAUTH_TOKEN=您的_oauth_token npx @softeria/ms-365-mcp-server
此方法:
注意:HTTP 模式需要认证。对于未认证的测试,请使用 stdio 模式和设备代码流。
认证工具:在 HTTP 模式下,默认禁用登录/注销工具,因为 OAuth 处理认证。如需使用它们,请使用
--enable-auth-tools。
在命令行直接运行 ms-365-mcp-server 时,可以使用以下选项:
--login 使用设备代码流登录
--logout 注销并清除保存的凭据
--verify-login 验证登录而不启动服务器
--org-mode 从开始启用组织/工作模式(包括 Teams、SharePoint 等)
--work-mode --org-mode 的别名
--force-work-scopes 向后兼容别名 --org-mode(已弃用)
作为 MCP 服务器运行时,可以使用以下选项:
-v 启用详细日志记录
--read-only 以只读模式启动服务器,禁用写入操作
--http [port] 使用可流传输的 HTTP 传输而不是 stdio(可选指定端口,默认:3000)
启动具有 MCP 端点 /mcp 的 Express.js 服务器
--enable-auth-tools 当使用 HTTP 模式时启用登录/注销工具(默认在 HTTP 模式下禁用)
--enabled-tools <pattern> 使用正则表达式模式筛选工具(例如,"excel|contact" 启用 Excel 和联系人工具)
--toon (实验性)启用 TOON 输出格式以减少 30-60% 的令牌
环境变量:
READ_ONLY=true|1:替代 --read-only 标志ENABLED_TOOLS:使用正则表达式模式筛选工具(替代 --enabled-tools 标志)MS365_MCP_ORG_MODE=true|1:启用组织/工作模式(替代 --org-mode 标志)MS365_MCP_FORCE_WORK_SCOPES=true|1:MS365_MCP_ORG_MODE 的向后兼容性MS365_MCP_OUTPUT_FORMAT=toon:启用 TOON 输出格式(替代 --toon 标志)LOG_LEVEL:设置日志级别(默认:'info')SILENT=true|1:禁用控制台输出MS365_MCP_CLIENT_ID:自定义 Azure 应用客户端 ID(默认为内置应用)MS365_MCP_TENANT_ID:自定义租户 ID(默认为 'common' 用于多租户)MS365_MCP_OAUTH_TOKEN:预存在的 OAuth 令牌用于 Microsoft Graph API(BYOT 方法)我们欢迎贡献!在提交拉取请求之前,请确保您的更改符合我们的质量标准。
运行验证脚本来检查所有代码质量要求:
npm run verify
克隆仓库后,您可能需要从 Microsoft Graph OpenAPI 规范生成客户端代码:
npm run generate
如果您遇到问题或需要帮助:
MIT © 2025 Softeria