Skip to main content
Glama

@developer.k/ms-graph-mcp

一个用于 Microsoft Graph 和 Microsoft 365 的模块化 Model Context Protocol 服务器。

它使用委派的设备代码认证,并公开了用于 Teams、Outlook 邮件、日历、Microsoft To Do、联系人、邮箱设置和 Outlook 类别的工具。

GitHub 仓库 | npm 包

有关发布说明和升级要求,请参阅更新日志。

功能

模块

能力

Graph

设备代码认证、认证状态、已登录用户资料

Teams

团队、频道、频道消息、聊天、聊天成员、自助聊天消息

邮件

文件夹、消息搜索、附件、草稿、发送/回复/转发、标志、类别、移动/删除、收件箱规则

日历

日历、日期范围事件视图、事件、在线会议、邀请、忙/闲状态、会议建议

To Do

任务列表、任务、重复周期、提醒、完成、检查清单项、链接资源

联系人

联系人文件夹和联系人,包括常见的个人和业务字段

Outlook

邮箱设置、工作时间、自动回复和主类别

Related MCP server: M365 Graph MCP Server

要求

  • Node.js 18 或更高版本

  • 一个启用了公共客户端流的 Microsoft Entra 应用注册

  • 你所用模块所需的委派 Microsoft Graph 权限

  • 用于邮件、日历、联系人和邮箱设置的 Exchange Online 或 Outlook.com 邮箱

  • 包含 Teams 的 Microsoft 365 或 Office 365 许可证,用于 Teams 聊天和频道 API

calendar_get_schedule 和 calendar_find_meeting_times 适用于工作或学校账户,不支持个人 Microsoft 账户。

对于个人 Outlook.com 账户,请注册一个支持个人 Microsoft 账户的应用,并将 MS_TENANT_ID 设置为 common。

按照基于截图的 Microsoft Graph API 设置指南 注册应用、添加权限并启用公共客户端流。

委派权限

默认作用域集请求每个包含模块所需的权限:

模块

权限

核心

User.Read、offline_access

Teams

Team.ReadBasic.All、Channel.ReadBasic.All、ChannelMessage.Read.All、ChannelMessage.Send、Chat.Read、ChatMessage.Send

邮件

Mail.ReadWrite、Mail.Send

日历

Calendars.ReadWrite、Calendars.ReadWrite.Shared

To Do

Tasks.ReadWrite

联系人

Contacts.ReadWrite

Outlook 设置、类别和规则

MailboxSettings.ReadWrite

某些租户策略需要管理员同意。当只需要选定模块时,使用 MS_GRAPH_SCOPES 请求较小的作用域集。

快速开始

配置你的 MCP 客户端以使用 npx 运行已发布的包。配置值可以直接放在 MCP 客户端的 env 块中;否则不需要 shell 环境变量。

{
  "mcpServers": {
    "ms-graph": {
      "command": "npx",
      "args": ["-y", "@developer.k/ms-graph-mcp"],
      "env": {
        "MS_CLIENT_ID": "your-entra-application-client-id",
        "MS_TENANT_ID": "organizations"
      }
    }
  }
}

调用 graph_auth_device_code,打开返回的登录 URL,输入设备代码,然后调用 graph_auth_status。在添加权限后或旧的设备代码流已过期时,使用 force: true。

配置

必需:

  • MS_CLIENT_ID:Microsoft Entra 应用程序(客户端)ID。

可选:

  • MS_TENANT_ID:organizations、common 或目录(租户)ID。默认值:organizations。

  • MS_GRAPH_SCOPES:以逗号或空格分隔的委派作用域,用于替换默认作用域集。

  • MS_GRAPH_TOKEN_CACHE_PATH:本地 MSAL 令牌缓存路径。

  • MS_GRAPH_ACCOUNT_USERNAME:当有多个账户可用时,要选择的缓存账户。

只读型自定义作用域集示例:

{
  "env": {
    "MS_CLIENT_ID": "your-entra-application-client-id",
    "MS_TENANT_ID": "organizations",
    "MS_GRAPH_SCOPES": "User.Read Mail.Read Calendars.Read Tasks.Read Contacts.Read MailboxSettings.Read offline_access"
  }
}

工具

Graph:

graph_auth_device_code
graph_auth_status
graph_get_me

Teams:

teams_list_joined_teams
teams_list_channels
teams_list_channel_messages
teams_send_channel_message
teams_list_chats
teams_list_chat_messages
teams_list_chat_members
teams_find_self_chat
teams_send_chat_message
teams_send_self_message

邮件:

mail_list_folders
mail_list_messages
mail_get_message
mail_list_attachments
mail_get_attachment
mail_add_attachment
mail_create_draft
mail_update_draft
mail_create_reply_draft
mail_create_forward_draft
mail_send_draft
mail_send_message
mail_reply
mail_reply_all
mail_forward
mail_update_message
mail_move_message
mail_delete_message
mail_list_rules
mail_create_rule
mail_update_rule
mail_delete_rule

日历:

calendar_list_calendars
calendar_get_calendar
calendar_create_calendar
calendar_update_calendar
calendar_delete_calendar
calendar_list_events
calendar_get_event
calendar_create_event
calendar_update_event
calendar_delete_event
calendar_cancel_event
calendar_respond_event
calendar_get_schedule
calendar_find_meeting_times

Microsoft To Do:

todo_list_task_lists
todo_get_task_list
todo_create_task_list
todo_update_task_list
todo_delete_task_list
todo_list_tasks
todo_get_task
todo_create_task
todo_update_task
todo_complete_task
todo_delete_task
todo_list_checklist_items
todo_create_checklist_item
todo_update_checklist_item
todo_delete_checklist_item
todo_list_linked_resources
todo_create_linked_resource
todo_delete_linked_resource

联系人:

contacts_list_folders
contacts_get_folder
contacts_create_folder
contacts_update_folder
contacts_delete_folder
contacts_list
contacts_get
contacts_create
contacts_update
contacts_delete

Outlook 设置和类别:

outlook_get_mailbox_settings
outlook_update_mailbox_settings
outlook_set_automatic_replies
outlook_list_categories
outlook_get_category
outlook_create_category
outlook_update_category
outlook_delete_category

示例提示词

Show the 10 most recent unread messages in my Inbox.
Find messages containing "quarterly report" and summarize their subjects and senders.
Create a draft reply to this message, but do not send it.
Create a draft email to user@example.com with the subject "Project update".
Send draft MESSAGE_ID after showing me its current recipients and subject.
Move message MESSAGE_ID to folder FOLDER_ID.
Show my calendar events for next week in Asia/Seoul.
Find a 30-minute time when all three attendees are available.
Create a Teams online meeting tomorrow at 2 PM.
Accept event EVENT_ID and send a response.
List my Microsoft To Do task lists.
Add a high-priority task due Friday with a reminder one day earlier.
Add three checklist items to task TASK_ID.
Mark task TASK_ID as completed.
Find the contact with email user@example.com.
Create a business contact in folder FOLDER_ID.
Schedule automatic replies from Monday morning through Friday evening.
Create an Outlook category named "Customer" using preset7.

建议优先使用草稿工具,然后再使用邮件发送工具,以便可以审阅收件人和内容。发送、回复、转发、取消、移动和删除工具会修改真实的 Microsoft 365 数据。

本地开发

仅当从本地克隆运行时才使用此部分:

npm install
npm test
{
  "mcpServers": {
    "ms-graph": {
      "command": "node",
      "args": ["/path/to/ms-graph-mcp/build/index.js"],
      "env": {
        "MS_CLIENT_ID": "your-entra-application-client-id",
        "MS_TENANT_ID": "organizations"
      }
    }
  }
}

项目结构

src/
|-- auth/
|   +-- msal.ts
|-- graph/
|   +-- client.ts
|-- modules/
|   |-- calendar.ts
|   |-- contacts.ts
|   |-- mail.ts
|   |-- outlook.ts
|   |-- shared.ts
|   |-- teams.ts
|   +-- todo.ts
|-- config.ts
|-- index.ts
|-- tools.ts
+-- types.ts

当前限制

  • 工具作用于已登录用户的 /me 资源。共享邮箱和委派共享文件夹尚未公开。

  • 不包含 Webhook 订阅,因为 stdio MCP 服务器没有永久的公共回调端点。

  • 简单文件附件限制为 3 MiB。更大的附件需要 Microsoft Graph 上传会话。

  • 联系人筛选支持精确的电子邮件地址匹配。Microsoft Graph 不公开联系人集合上的常规名称搜索。

  • 事件和消息正文可能包含 Microsoft Graph 提供的外部 HTML。

此包不包含任何凭据、租户标识符、账户标识符或其他个性化配置。

Related MCP Connectors

Related MCP Servers