MSGraph MCP

io.github.timfurlong由 GitHub 账号 timfurlong 发布v0.5.1更新于 Oct 24, 2026

MCP server for Microsoft Graph: Outlook mail and calendar, plus read-only Microsoft Teams

已验证STDIO仅桌面效率与工作流沟通与协作

概览

AI 生成的概览

让助手以登录用户身份通过 Microsoft Graph 读取和管理 Outlook 邮件、日历,以及只读的 Teams 消息。

可以做什么
这是一个本地 stdio MCP 服务器,面向 Microsoft Graph,提供 Outlook 邮件与日历功能,以及只读的 Teams 消息历史。邮件工具支持列出、搜索、读取、发送、回复、转发、草稿、文件夹、规则、标记,以及对最多 1000 封邮件执行批量操作。日历工具可列出、创建、更新、取消和回复事件,并查找会议时间。Teams 工具可列出聊天、已加入的团队、频道、频道消息、回复和托管内容。返回结果会为助手做精简,也可选择返回完整正文或原始 Graph 数据。
适用场景
当助手需要处理 Microsoft 365 邮箱或日历时适用,例如整理和搜索邮件、起草或发送回复、管理文件夹和规则、安排或回复会议,或阅读 Teams 聊天与频道历史。它以登录用户身份运行,因此只能访问该账号有权访问的内容。
运行要求
需要 Python 3.11 或更高版本,可通过 uv tool 或 pip 安装,也可用 uvx 运行。需要一个 Entra(Azure AD)应用注册,启用公共客户端流、配置 nativeclient 重定向 URI,并授予邮件、日历和 Teams 的委托 Graph 权限;ChannelMessage.Read.All 和部分共享权限需要租户管理员同意。设置 MSGRAPH_MCP_CLIENT_ID 和 MSGRAPH_MCP_TENANT_ID,执行一次设备代码登录,可选设置 MSGRAPH_MCP_TOKEN_CACHE_PATH。仅限桌面,通过 stdio 运行。
安装前请注意
该服务器可以发送、回复、转发、更新、移动和删除邮件,也可以创建、更新、取消或回复日历事件,因此助手的操作会改动真实的邮箱和日历数据。位于 ~/.msgraph-mcp/token_cache.bin 的令牌缓存保存刷新令牌,可换取访问你邮件、日历和 Teams 数据的访问令牌,应视为凭据。旧名称 outlook-mcp 留下的缓存仍会作为后备使用,撤销时需同时删除两者。权限范围是一次性全部请求:若未获得 ChannelMessage.Read.All 的管理员同意,登录会直接失败,邮件和日历也无法使用。每封邮件的附件总大小上限为 3 MB。

安装

在 SourceWeft 中

  1. 打开 控制台中的 MSGraph MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

MSGraph MCP

[PyPI] [Python versions] [CI] [License: MIT]

A Model Context Protocol (MCP) server for Microsoft Graph. It exposes Microsoft Outlook mail and calendar, plus read-only Microsoft Teams message history, to AI agents via the Microsoft Graph SDK. It acts as the signed-in user, using delegated permissions and MSAL device code flow, so it can only reach what that user can reach.

Install

You need Python ≥ 3.11 and an Entra (Azure AD) app registration. The app registration takes about ten minutes and may need an administrator, so do that first: see the Entra setup section below.

bash
uv tool install msgraph-mcp-server   # or: pip install msgraph-mcp-server

The package is msgraph-mcp-server. It installs three commands: msgraph-mcp and its alias msgraph-mcp-server, which both start the stdio server, plus msgraph-mcp-login for the one-time sign-in.

Setup

1. Set your Entra app credentials.

bash
export MSGRAPH_MCP_CLIENT_ID=<your app's client ID>export MSGRAPH_MCP_TENANT_ID=<your tenant ID>   # or: common / organizations / consumers

2. Sign in once. This prints a URL and a code; visit the URL and enter the code. No client secret is involved or stored.

bash
msgraph-mcp-login# running via uvx instead of installing: uvx --from msgraph-mcp-server msgraph-mcp-login

A token cache is written to ~/.msgraph-mcp/token_cache.bin.

3. Wire the server into your MCP host.

Claude Code:

bash
claude mcp add msgraph \  --env MSGRAPH_MCP_CLIENT_ID=$MSGRAPH_MCP_CLIENT_ID \  --env MSGRAPH_MCP_TENANT_ID=$MSGRAPH_MCP_TENANT_ID \  -- msgraph-mcp

Any other host, over stdio:

json
{  "mcpServers": {    "msgraph": {      "command": "msgraph-mcp",      "args": [],      "env": {        "MSGRAPH_MCP_CLIENT_ID": "<your app's client ID>",        "MSGRAPH_MCP_TENANT_ID": "<your tenant ID>"      }    }  }}

To run without installing, use "command": "uvx" with "args": ["msgraph-mcp-server"]. Note that uvx does not put msgraph-mcp-login on your PATH, so sign in with the uvx --from form shown in step 2.

MSGRAPH_MCP_TOKEN_CACHE_PATH optionally overrides the cache location. All three variables can also come from a .env file in the working directory; the process environment wins over it.

Entra setup

The app registration requires:

  • Account type: single tenant (multi-tenant works too; set MSGRAPH_MCP_TENANT_ID to common, organizations, or consumers)
  • Redirect URI (public client): https://login.microsoftonline.com/common/oauth2/nativeclient
  • Allow public client flows: Yes, under Authentication → Advanced settings. Device code flow fails without it.
  • Delegated permissions (Microsoft Graph):
    • Mail: Mail.ReadWrite, Mail.ReadWrite.Shared, Mail.Send
    • Rules: MailboxSettings.ReadWrite (Graph requires this for the messageRules endpoints)
    • Calendar: Calendars.ReadWrite, Calendars.ReadWrite.Shared
    • Identity: User.Read
    • Teams: Chat.Read, Team.ReadBasic.All, Channel.ReadBasic.All, ChannelMessage.Read.All

ChannelMessage.Read.All always needs tenant admin consent, and the *.Shared permissions may need it depending on your tenant.

The scope list is all-or-nothing. Sign-in requests every scope at once, so without admin consent for ChannelMessage.Read.All the login fails outright and mail and calendar are unavailable too. For the same reason, adding scopes later means re-running msgraph-mcp-login; until you do, every tool fails with NotAuthenticatedError, not just the ones needing the new scope.

Tools

GroupTools
Utilwhoami
Mail — readlist_messages, search_messages, get_message, list_attachments, download_attachment
Mail — writesend_message, create_draft, reply_message, reply_all_message, forward_message, update_message, delete_message
Mail — folderslist_folders, create_folder, update_folder, delete_folder, move_message
Mail — actionsarchive_message, mark_read, mark_unread, flag_message, unflag_message
Mail — batchbatch_archive_messages, batch_move_messages, batch_mark_read, batch_mark_unread, batch_flag_messages, batch_unflag_messages
Mail — ruleslist_rules, get_rule, create_rule, update_rule, delete_rule
Calendarlist_calendars, list_events, get_event, create_event, update_event, delete_event, cancel_event, respond_to_event, find_meeting_times
Teams (read)list_chats, list_chat_messages, list_joined_teams, list_channels, list_channel_messages, list_message_replies, download_hosted_content

Behavior shared across tools:

  • Trimmed responses. Results are reshaped for agents, and message and event bodies are replaced by a short snippet. Pass include_body=true to get_message, list_chat_messages, list_channel_messages, or list_message_replies for the full body, which for Teams is also what surfaces Adaptive Card content. Pass include_raw=true to any tool returning a Graph object to get the full payload alongside the trimmed one; the batch_* tools return per-message status only and do not accept it.
  • Other mailboxes. Every mail and calendar tool takes an optional mailbox (email or user ID) to target a shared or delegated mailbox. Omit it for your own. Teams tools are read-only, cover only your own chats, and take no mailbox.
  • Pagination. List and search tools take limit (1-100, default 25) and page_token, except list_channel_messages and list_message_replies, which Graph caps at 50. list_folders, list_rules, list_attachments, and list_calendars return the whole collection and take neither. On list_joined_teams and list_channels, limit is applied after fetching because Graph rejects $top there, so it saves tokens rather than round-trips.
  • Batch actions. The batch_* tools apply one action to up to 1000 messages via Graph's $batch endpoint, returning a per-message result plus a {total, succeeded, failed} summary.
  • Downloads. download_attachment and download_hosted_content return images as native MCP image blocks the agent can view. Pass save_path (a file, or an existing directory) to write bytes to disk and get back a path instead.
  • Finding mail. list_messages defaults to the inbox; pass folder_id for another folder, unread_only=true, or a raw OData filter for predicates KQL cannot express. search_messages passes your query to Graph's $search as KQL.

Outgoing attachments are capped at 3 MB total per message; chunked upload is not supported. SharePoint-backed Teams file attachments cannot be downloaded, only inline hosted content.

Security

The token cache holds your refresh token, which can mint access tokens for your mail, calendar, and Teams data. Treat the file as a credential. It lives at ~/.msgraph-mcp/token_cache.bin with mode 0600 inside a 0700 directory.

To revoke access, or to switch accounts, delete the cache and sign in again:

bash
rm -f ~/.msgraph-mcp/token_cache.bin ~/.outlook-mcp/token_cache.bin

The second path matters if you ever ran this server under its former name outlook-mcp: that cache is still used as a fallback when the current one is absent, so deleting only the first file leaves a working refresh token on disk. To revoke fully, also remove the app at https://account.microsoft.com or in your organization's identity portal.

Troubleshooting

  • NotAuthenticatedError: Not authenticated — run msgraph-mcp-login. If it recurs immediately, a requested scope has not been consented yet; see the note under Entra setup.
  • ConfigError: Missing required env var — set it in your shell, in a .env in the working directory, or in your MCP host's env config.
  • Graph API 403: ErrorAccessDenied — the Entra app is missing a delegated permission, or it needs admin consent. Check the list above, then re-consent and sign in again.
  • Graph API 400: BadRequest — Syntax error from search_messages — the query goes to Graph's $search as KQL. Quote literal phrases ("weekly report") or use fielded forms (from:alice). For predicates KQL cannot express, use list_messages with filter=.
  • The host starts the server but lists no tools — confirm it launches msgraph-mcp (or uvx) over stdio and can find that binary on its PATH.

Development

See CONTRIBUTING.md.

来源:README.md,提交 e541cdb

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.5.1最新Sep 21, 2026
  2. v0.3.2Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分