Teams MCP
Teams MCP
一个模型上下文协议 (MCP) 服务器,提供与 Microsoft Graph API 的无缝集成,使 AI 助手能够与 Microsoft Teams、用户、聊天、文件和组织数据进行交互。
📦 安装
要在 Cursor/Claude/VS Code 中使用此 MCP 服务器,请添加以下配置:
{
"mcpServers": {
"teams-mcp": {
"command": "npx",
"args": ["-y", "@floriscornel/teams-mcp@latest"]
}
}
}Related MCP server: Meeting BaaS MCP Server
🚀 功能
🔐 身份验证
使用 Microsoft Graph 进行 OAuth 2.0 设备代码身份验证流程
安全的令牌管理、缓存持久化和刷新令牌更新
身份验证状态检查和注销支持
具有缩减权限范围的只读模式
直接支持
AUTH_TOKEN以使用预签发的 Microsoft Graph 访问令牌
👥 用户管理
获取当前用户信息
按姓名或电子邮件搜索用户
检索详细的用户资料
访问组织目录数据
🏢 Microsoft Teams 集成
团队管理
列出用户加入的团队
访问团队详细信息和元数据
频道操作
列出团队内的频道
检索频道消息和回复
向团队频道发送消息
回复现有的频道主题
编辑和软删除频道消息及回复
支持消息重要性级别 (
normal,high,urgent)支持通过 URL 或 base64 数据进行内联图像附件
团队成员
列出团队成员及其角色
访问成员信息
搜索用户以进行
@mentions
💬 聊天与消息
一对一和群组聊天
列出用户的聊天记录
创建新的一对一或群组对话
检索带有过滤、排序和分页功能的聊天消息历史记录
通过
@odata.nextLink分页获取所有可用消息向现有聊天发送消息
编辑之前发送的聊天消息
软删除聊天消息
✏️ 消息管理
编辑与删除
更新(编辑)在聊天和频道中发送的消息
软删除聊天和频道中的消息(标记为已删除,不进行永久移除)
只有消息发送者可以更新/删除自己的消息
编辑时支持 Markdown 格式、提及和重要性级别
📎 媒体与附件
托管内容
从聊天和频道消息中下载托管内容(图像、文件)
访问对话中共享的内联图像和附件
可选择将托管内容直接保存到磁盘
文件上传
上传并发送任何文件类型(PDF、DOCX、XLSX、ZIP、图像等)到频道和聊天
通过可恢复的上传会话支持大文件 (>4 MB)
频道上传至 SharePoint,聊天上传至 OneDrive
可选的消息文本、自定义文件名、格式和重要性级别
🔍 高级搜索与发现
消息搜索
使用 Microsoft Search API 搜索所有 Teams 频道和聊天
支持 KQL(关键字查询语言)语法
按发送者、提及、附件、读取状态和日期范围进行过滤
获取带有高级过滤选项的最近消息
查找提及当前用户的消息
丰富的消息格式支持
以下工具支持在 Teams 频道和聊天中使用丰富的消息格式:
send_channel_messagesend_chat_messagereply_to_channel_messageupdate_channel_messageupdate_chat_messagesend_file_to_channelsend_file_to_chat
格式选项
您可以指定 format 参数来控制消息格式:
text(默认):纯文本markdown:Markdown 格式(粗体、斜体、列表、链接、代码等),转换为经过清理的 HTML
当 format 设置为 markdown 时,消息内容会使用安全的 markdown 解析器转换为 HTML,并在发送到 Teams 之前进行清理,以移除潜在的危险内容。
如果未指定 format,消息将作为纯文本发送。
使用示例
{
"teamId": "...",
"channelId": "...",
"message": "**Bold text** and _italic text_\n\n- List item 1\n- List item 2\n\n[Link](https://example.com)",
"format": "markdown",
"importance": "high"
}{
"chatId": "...",
"message": "Simple plain text message",
"format": "text"
}安全特性
HTML 清理:所有 markdown 内容都会转换为 HTML 并进行清理,以移除潜在的危险元素(脚本、事件处理程序等)
允许的标签:仅允许安全的 HTML 标签(p, strong, em, a, ul, ol, li, h1-h6, code, pre 等)
安全属性:仅允许安全的属性
XSS 防护:内容会自动清理以防止跨站脚本攻击
支持的 Markdown 特性
文本格式:粗体 (
**text**),斜体 (_text_),删除线 (~~text~~)链接:
[text](url)列表:无序 (
- item) 和有序 (1. item)代码:行内
`code`和代码块标题:
# H1到###### H6引用:
> quoted text表格:GitHub 风格的 markdown 表格
对 LLM 友好的内容格式
从 Microsoft Graph API 检索的消息以包含 Teams 特定标签的原始 HTML 形式返回。为了使这些内容更易于 AI 助手使用,以下工具支持自动 HTML 转 Markdown 转换:
get_chat_messagesget_channel_messagesget_channel_message_repliessearch_messagesget_my_mentions
内容格式选项
使用 contentFormat 参数来控制消息内容的返回方式:
markdown(默认):将 Teams HTML 转换为简洁的 Markdown,针对 LLM 使用进行了优化raw:返回来自 Microsoft Graph API 的原始 HTML
转换内容
HTML 元素 | Markdown 输出 |
|
|
|
|
|
|
|
|
|
|
|
|
| GFM Markdown 表格 |
|
|
| (已移除) |
|
|
| 解码为纯字符 |
附件元数据
包含文件附件或内联图像的消息在响应中包含一个 attachments 数组,其中包含每个附件的元数据(id, name, contentType, contentUrl, thumbnailUrl)。Markdown 内容中的内联 {attachment:id} 标记与此数组中的条目相关联,允许消费者通过 download_message_hosted_content 或 download_chat_hosted_content 识别并下载附件。
使用示例
{
"chatId": "19:meeting_...",
"limit": 10,
"contentFormat": "markdown"
}获取原始 HTML:
{
"chatId": "19:meeting_...",
"limit": 10,
"contentFormat": "raw"
}📦 安装
# Install dependencies
npm install
# Build the project
npm run build
# Set up authentication
npm run auth🔧 配置
先决条件
Node.js 18+
具有适当权限的 Microsoft 365 账户
针对以下范围的 Microsoft Graph 委托权限
所需的 Microsoft Graph 权限
完整模式(默认):
User.Read- 读取用户资料User.ReadBasic.All- 读取基本用户信息Team.ReadBasic.All- 读取团队信息Channel.ReadBasic.All- 读取频道信息ChannelMessage.Read.All- 读取频道消息ChannelMessage.Send- 发送频道消息和回复ChannelMessage.ReadWrite- 编辑和删除频道消息Chat.Read- 读取聊天消息(通过只读范围包含)Chat.ReadWrite- 创建和管理聊天,发送/编辑/删除聊天消息(取代Chat.Read)TeamMember.Read.All- 读取团队成员Files.ReadWrite.All- 频道和聊天文件上传所需
只读模式 (TEAMS_MCP_READ_ONLY=true) — 仅请求这些范围:
User.ReadUser.ReadBasic.AllTeam.ReadBasic.AllChannel.ReadBasic.AllChannelMessage.Read.AllTeamMember.Read.AllChat.Read
身份验证模式
完全访问:
npx @floriscornel/teams-mcp@latest authenticate只读访问:
npx @floriscornel/teams-mcp@latest authenticate --read-only使用现有的 Microsoft Graph JWT 直接注入令牌:
{
"mcpServers": {
"teams-mcp": {
"command": "npx",
"args": ["-y", "@floriscornel/teams-mcp@latest"],
"env": {
"AUTH_TOKEN": "<jwt-for-https://graph.microsoft.com>"
}
}
}
}令牌存储
身份验证元数据存储在本地
~/.msgraph-mcp-auth.json令牌缓存存储在本地
~/.teams-mcp-token-cache.json
🛠️ 使用
启动服务器
# Development mode with hot reload
npm run dev
# Production mode
npm run build && node dist/index.js
# Start in read-only mode (disables all write tools)
TEAMS_MCP_READ_ONLY=true node dist/index.jsCLI 命令
npx @floriscornel/teams-mcp@latest authenticate # Authenticate with full scopes
npx @floriscornel/teams-mcp@latest authenticate --read-only # Authenticate with read-only scopes
npx @floriscornel/teams-mcp@latest check # Check authentication status
npx @floriscornel/teams-mcp@latest logout # Clear authentication
npx @floriscornel/teams-mcp@latest auth # Alias for authenticate
npx @floriscornel/teams-mcp@latest # Start MCP server (default)环境变量
TEAMS_MCP_READ_ONLY=true- 以只读模式启动 MCP 服务器AUTH_TOKEN=<jwt>- 使用预先存在的 Microsoft Graph 访问令牌代替 MSAL 登录
只读模式
服务器支持只读模式,该模式禁用所有写操作(发送消息、创建聊天、上传文件、编辑/删除消息),并且仅从 Microsoft Graph 请求读取权限范围。
启用只读模式,使用以下任一方式:
环境变量:
TEAMS_MCP_READ_ONLY=trueCLI 标志:
--read-only
使用缩减范围进行身份验证:
npx @floriscornel/teams-mcp@latest authenticate --read-onlyMCP 服务器配置(只读):
{
"mcpServers": {
"teams-mcp": {
"command": "npx",
"args": ["-y", "@floriscornel/teams-mcp@latest"],
"env": {
"TEAMS_MCP_READ_ONLY": "true"
}
}
}
}切换模式: 当从只读模式切换到完整模式时,服务器会检测到范围不匹配并警告您重新进行身份验证:
npx @floriscornel/teams-mcp@latest authenticate只读工具 (16):
auth_status, get_current_user, search_users, get_user, list_teams, list_channels, get_channel_messages, get_channel_message_replies, list_team_members, search_users_for_mentions, download_message_hosted_content, list_chats, get_chat_messages, download_chat_hosted_content, search_messages, get_my_mentions
只读模式下禁用的写工具 (10):
send_channel_message, reply_to_channel_message, update_channel_message, delete_channel_message, send_file_to_channel, send_chat_message, create_chat, update_chat_message, delete_chat_message, send_file_to_chat
可用的 MCP 工具
身份验证
auth_status- 检查当前身份验证状态
用户操作
get_current_user- 获取已验证用户信息search_users- 按姓名或电子邮件搜索用户get_user- 按 ID 或电子邮件获取详细用户信息
团队操作
list_teams- 列出用户加入的团队list_channels- 列出特定团队中的频道get_channel_messages- 从团队频道检索消息,包含附件摘要和内容格式选择get_channel_message_replies- 获取特定频道消息的回复send_channel_message- 向团队频道发送消息,支持可选的提及、重要性和图像附件reply_to_channel_message- 回复现有的频道消息update_channel_message- 编辑之前发送的频道消息或回复delete_channel_message- 软删除频道消息或回复list_team_members- 列出特定团队的成员search_users_for_mentions- 搜索团队成员以在消息中进行 @mentionsend_file_to_channel- 上传本地文件并将其作为消息发送到频道
聊天操作
list_chats- 列出用户的聊天(一对一和群组)get_chat_messages- 从特定聊天中检索消息,支持分页、过滤、排序和fetchAllsend_chat_message- 向聊天发送消息create_chat- 创建新的一对一或群组聊天update_chat_message- 编辑之前发送的聊天消息delete_chat_message- 软删除聊天消息send_file_to_chat- 上传本地文件并将其作为消息发送到聊天
媒体操作
download_message_hosted_content- 从频道消息下载托管内容(图像、文件)download_chat_hosted_content- 从聊天消息下载托管内容(图像、文件)
搜索操作
search_messages- 使用 KQL 语法搜索所有 Teams 消息get_my_mentions- 查找提及当前用户的最近消息
📋 示例
身份验证
首先,使用 Microsoft Graph 进行身份验证:
# Full access (default)
npx @floriscornel/teams-mcp@latest authenticate
# Read-only (reduced permission scopes)
npx @floriscornel/teams-mcp@latest authenticate --read-only检查您的身份验证状态:
npx @floriscornel/teams-mcp@latest check如有需要,注销:
npx @floriscornel/teams-mcp@latest logout聊天分页示例
{
"chatId": "19:meeting_...",
"limit": 100,
"fetchAll": true,
"orderBy": "createdDateTime",
"descending": true,
"contentFormat": "markdown"
}带有提及和图像的频道消息
{
"teamId": "team-id",
"channelId": "channel-id",
"message": "Please review **today's update**",
"format": "markdown",
"importance": "high",
"mentions": [
{
"mention": "alex.chen",
"userId": "00000000-0000-0000-0000-000000000000"
}
],
"imageUrl": "https://example.com/status.png"
}文件上传示例
{
"chatId": "19:meeting_...",
"filePath": "/absolute/path/to/report.pdf",
"message": "Please review the attached report",
"format": "markdown"
}与 Cursor/Claude 集成
此 MCP 服务器旨在通过模型上下文协议与 Claude/Cursor/VS Code 等 AI 助手配合使用。
{
"mcpServers": {
"teams-mcp": {
"command": "npx",
"args": ["-y", "@floriscornel/teams-mcp@latest"]
}
}
}🔒 安全
所有身份验证均通过 Microsoft 的 OAuth 2
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Appeared in Searches
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/floriscornel/teams-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server