Labsco
floriscornel logo

Teams MCP

β˜… 118

from floriscornel

Interact with Microsoft Teams, users, and organizational data via the Microsoft Graph API.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredNeeds API keys

Teams MCP

npm version npm downloads codecov License: MIT GitHub stars

A Model Context Protocol (MCP) server that provides seamless integration with Microsoft Graph APIs, enabling AI assistants to interact with Microsoft Teams, users, chats, files, and organizational data.

<a href="https://glama.ai/mcp/servers/@floriscornel/teams-mcp"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@floriscornel/teams-mcp/badge" alt="Teams MCP server" /> </a>

πŸš€ Features

πŸ” Authentication

  • OAuth 2.0 device code authentication flow with Microsoft Graph
  • Secure token management, cache persistence, and refresh token renewal
  • Authentication status checking and logout support
  • Read-only mode with reduced scopes
  • Direct AUTH_TOKEN support for pre-issued Microsoft Graph access tokens

πŸ‘₯ User Management

  • Get current user information
  • Search users by name or email
  • Retrieve detailed user profiles
  • Access organizational directory data

🏒 Microsoft Teams Integration

  • Teams Management

    • List user's joined teams
    • Access team details and metadata
  • Channel Operations

    • List channels within teams
    • Retrieve channel messages and replies
    • Send messages to team channels
    • Reply to existing channel threads
    • Edit and soft delete channel messages and replies
    • Support for message importance levels (normal, high, urgent)
    • Support for inline image attachments via URL or base64 data
  • Team Members

    • List team members and their roles
    • Access member information
    • Search users for @mentions

πŸ’¬ Chat & Messaging

  • 1:1 and Group Chats
    • List user's chats
    • Create new 1:1 or group conversations
    • Retrieve chat message history with filtering, ordering, and pagination
    • Fetch all available messages via @odata.nextLink pagination
    • Send messages to existing chats
    • Edit previously sent chat messages
    • Soft delete chat messages

✏️ Message Management

  • Edit & Delete
    • Update (edit) sent messages in chats and channels
    • Soft delete messages in chats and channels (marks as deleted without permanent removal)
    • Only message senders can update/delete their own messages
    • Support for Markdown formatting, mentions, and importance levels on edits

πŸ“Ž Media & Attachments

  • Hosted Content

    • Download hosted content (images, files) from chat and channel messages
    • Access inline images and attachments shared in conversations
    • Optionally save hosted content directly to disk
  • File Upload

    • Upload and send any file type (PDF, DOCX, XLSX, ZIP, images, etc.) to channels and chats
    • Large file support (>4 MB) via resumable upload sessions
    • Channel uploads go to SharePoint and chat uploads go to OneDrive
    • Optional message text, custom filename, formatting, and importance levels

πŸ” Advanced Search & Discovery

  • Message Search
    • Search across all Teams channels and chats using Microsoft Search API
    • Support for KQL (Keyword Query Language) syntax
    • Filter by sender, mentions, attachments, read state, and date ranges
    • Get recent messages with advanced filtering options
    • Find messages mentioning the current user

Rich Message Formatting Support

The following tools support rich message formatting in Teams channels and chats:

  • send_channel_message
  • send_chat_message
  • reply_to_channel_message
  • update_channel_message
  • update_chat_message
  • send_file_to_channel
  • send_file_to_chat

Format Options

You can specify the format parameter to control the message formatting:

  • text (default): Plain text
  • markdown: Markdown formatting (bold, italic, lists, links, code, etc.) converted to sanitized HTML

When format is set to markdown, the message content is converted to HTML using a secure markdown parser and sanitized to remove potentially dangerous content before being sent to Teams.

If format is not specified, the message will be sent as plain text.

Example Usage

Copy & paste β€” that's it
{
  "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"
}
Copy & paste β€” that's it
{
  "chatId": "...",
  "message": "Simple plain text message",
  "format": "text"
}

Security Features

  • HTML Sanitization: All markdown content is converted to HTML and sanitized to remove potentially dangerous elements (scripts, event handlers, etc.)
  • Allowed Tags: Only safe HTML tags are permitted (p, strong, em, a, ul, ol, li, h1-h6, code, pre, etc.)
  • Safe Attributes: Only safe attributes are allowed
  • XSS Prevention: Content is automatically sanitized to prevent cross-site scripting attacks

Supported Markdown Features

  • Text formatting: Bold (**text**), italic (_text_), strikethrough (~~text~~)
  • Links: [text](https://github.com/floriscornel/teams-mcp/blob/HEAD/url)
  • Lists: Bulleted (- item) and numbered (1. item)
  • Code: Inline `code` and fenced code blocks
  • Headings: # H1 through ###### H6
  • Blockquotes: > quoted text
  • Tables: GitHub-flavored markdown tables

LLM-Friendly Content Format

Messages retrieved from the Microsoft Graph API are returned as raw HTML containing Teams-specific tags. To make this content more consumable by AI assistants, the following tools support automatic HTML-to-Markdown conversion:

  • get_chat_messages
  • get_channel_messages
  • get_channel_message_replies
  • search_messages
  • get_my_mentions

Content Format Options

Use the contentFormat parameter to control how message content is returned:

  • markdown (default): Converts Teams HTML to clean Markdown, optimized for LLM consumption
  • raw: Returns the original HTML from the Microsoft Graph API

What Gets Converted

HTML ElementMarkdown Output
<at id="0">Name</at> (Teams mention)@Name (multi-word names merged using mentions metadata)
<strong>text</strong>**text**
<em>text</em>*text*
<code>text</code>`text`
<a href="url">text</a>[text](https://github.com/floriscornel/teams-mcp/blob/HEAD/url)
<ul><li>item</li></ul>- item
<table>...</table>GFM Markdown table
<attachment id="...">{attachment:id}
<systemEventMessage/>(removed)
<hr>---
&nbsp;, &amp;, etc.Decoded to plain characters

Attachment Metadata

Messages that contain file attachments or inline images include an attachments array in the response with metadata for each attachment (id, name, contentType, contentUrl, thumbnailUrl). The inline {attachment:id} markers in the markdown content correlate with entries in this array, allowing consumers to identify and download attachments via download_message_hosted_content or download_chat_hosted_content.

Example Usage

Copy & paste β€” that's it
{
  "chatId": "19:meeting_...",
  "limit": 10,
  "contentFormat": "markdown"
}

To get the original HTML:

Copy & paste β€” that's it
{
  "chatId": "19:meeting_...",
  "limit": 10,
  "contentFormat": "raw"
}

πŸ“‹ Examples

Authentication

First, authenticate with Microsoft Graph:

Copy & paste β€” that's it
# Full access (default)
npx @floriscornel/teams-mcp@latest authenticate

# Read-only (reduced permission scopes)
npx @floriscornel/teams-mcp@latest authenticate --read-only

Check your authentication status:

Copy & paste β€” that's it
npx @floriscornel/teams-mcp@latest check

Logout if needed:

Copy & paste β€” that's it
npx @floriscornel/teams-mcp@latest logout

Chat Pagination Example

Copy & paste β€” that's it
{
  "chatId": "19:meeting_...",
  "limit": 100,
  "fetchAll": true,
  "orderBy": "createdDateTime",
  "descending": true,
  "contentFormat": "markdown"
}

Channel Message with Mentions and Image

Copy & paste β€” that's it
{
  "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"
}

File Upload Example

Copy & paste β€” that's it
{
  "chatId": "19:meeting_...",
  "filePath": "/absolute/path/to/report.pdf",
  "message": "Please review the attached report",
  "format": "markdown"
}

Integrating with Cursor/Claude

This MCP server is designed to work with AI assistants like Claude/Cursor/VS Code through the Model Context Protocol.

Copy & paste β€” that's it
{
  "mcpServers": {
    "teams-mcp": {
      "command": "npx",
      "args": ["-y", "@floriscornel/teams-mcp@latest"]
    }
  }
}

πŸ”’ Security

  • All authentication is handled through Microsoft's OAuth 2.0 flow or a caller-provided Microsoft Graph token
  • Refresh token support: Access tokens are automatically renewed using cached refresh tokens, so you don't need to re-authenticate every hour
  • Token cache is stored locally at ~/.teams-mcp-token-cache.json
  • Auth metadata is stored locally at ~/.msgraph-mcp-auth.json
  • Markdown content is sanitized before sending HTML to Teams
  • AUTH_TOKEN is validated to ensure it targets https://graph.microsoft.com
  • No sensitive data is logged or exposed
  • Follows Microsoft Graph API security best practices

πŸ“ License

MIT License - see LICENSE file for details

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run build, linting, and tests
  5. Submit a pull request

πŸ“ž Support

For issues and questions:

  • Check the existing GitHub issues
  • Review Microsoft Graph API documentation
  • Ensure proper authentication and permissions are configured