teams-mcp-server
v1.0.12
Published
Microsoft Teams MCP server with direct messaging support
Downloads
74
Maintainers
Readme
Teams MCP Server
A Model Context Protocol (MCP) server that enables AI assistants to interact with Microsoft Teams through the Microsoft Graph API. Send messages, create chats, and manage conversations programmatically.
Features
- Send Messages: Send text and HTML messages to Teams chats
- Create Chats: Create one-on-one or group chats
- List Chats: Retrieve and filter user's chat list
- Read Messages: Get chat history and messages
- Secure Authentication: OAuth2 flow with PKCE and secure token storage
- Rate Limiting: Automatic handling of Microsoft Graph API limits
Prerequisites
- Node.js 18+
- Microsoft Teams account
- Azure app registration with appropriate permissions
Azure App Setup
- Go to Azure Portal
- Navigate to "Azure Active Directory" > "App registrations"
- Click "New registration"
- Configure your app:
- Name:
Teams MCP Server - Supported account types: "Accounts in this organizational directory only"
- Redirect URI:
http://localhost:3000/auth/callback(Web platform)
- Name:
- After creation, note the:
- Application (client) ID
- Directory (tenant) ID
- Navigate to "API permissions" and add:
- Microsoft Graph > Delegated permissions:
Chat.ReadWriteChatMessage.SendUser.Readoffline_access(for refresh tokens)
- Microsoft Graph > Delegated permissions:
- Grant admin consent for the permissions
Installation
Via npm
npm install -g teams-mcp-serverFrom source
git clone https://github.com/mgklabs/teams-mcp-server.git
cd teams-mcp-server
npm install
npm run buildConfiguration
Create a .env file in your project directory:
AZURE_CLIENT_ID=your-app-client-id
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_SECRET=your-client-secret # Optional: For confidential client flow
AZURE_REDIRECT_URI=http://localhost:3000/auth/callback
MCP_SERVER_PORT=3000
DEBUG=true # Optional: Enable debug loggingUsage
Running the Server
npm startFor development with auto-reload:
npm run devAvailable MCP Tools
Once configured, the MCP server provides these tools:
Authentication
teams_auth_statusCheck authentication status and initiate login if needed. This will open your browser for Microsoft authentication on first use.
List Chats
teams_list_chatsList all your Teams chats. Supports OData filtering:
teams_list_chats --filter "chatType eq 'oneOnOne'"Create Chat
teams_create_chat --chatType "oneOnOne" --members "[{\"email\": \"[email protected]\"}]"Create a new chat. For group chats, include a topic:
teams_create_chat --chatType "group" --topic "Project Discussion" --members "[{\"email\": \"[email protected]\"}, {\"email\": \"[email protected]\"}]"Send Message
teams_send_message --chatId "chat-id" --content "Hello from MCP!"Send HTML formatted messages:
teams_send_message --chatId "chat-id" --content "<b>Important:</b> Meeting at 3pm" --contentType "html"Get Messages
teams_get_messages --chatId "chat-id" --limit 20MCP Client Configuration
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"teams": {
"command": "npx",
"args": ["teams-mcp-server"],
"env": {
"AZURE_CLIENT_ID": "your-app-client-id",
"AZURE_TENANT_ID": "your-tenant-id",
"AZURE_CLIENT_SECRET": "your-client-secret", // Optional: For confidential client flow
"AZURE_REDIRECT_URI": "http://localhost:3000/auth/callback", // Optional: Custom redirect URI
"MCP_SERVER_PORT": "3000", // Optional: Custom port
"DEBUG": "true" // Optional: Enable debug logging
}
}
}
}Other MCP Clients
For development or other MCP clients:
# With environment variables
AZURE_CLIENT_ID=your-client-id AZURE_TENANT_ID=your-tenant-id node dist/index.js
# Or with .env file
node dist/index.jsAuthentication Flow
- First tool usage triggers authentication check
- If not authenticated, opens browser for Microsoft login
- User grants permissions to the app
- Tokens are securely stored for future use
- Automatic token refresh before expiration
Security
- Uses OAuth2 public client flow (no client secret required)
- Tokens stored securely in system keychain (via keytar) with encrypted file fallback
- Automatic token refresh
- PKCE protection for authorization flow
- No credentials are logged or exposed
Troubleshooting
Debug Mode
Enable debug logging to troubleshoot issues:
DEBUG=true npm startDebug logs are written to:
- Console output (stderr)
- File:
.teams-mcp/debug.log
Authentication Issues
- Ensure redirect URI matches exactly in Azure and
.env - Check that all required permissions are granted
- Try clearing tokens: delete
.teams-mcp/auth-cache - Enable "Allow public client flows" in Azure app settings
Rate Limiting
- The server automatically handles rate limits
- Current usage is shown in
teams_auth_statusresponse - Implements exponential backoff for retries
Common Errors
"Missing required environment variables"
Ensure AZURE_CLIENT_ID and AZURE_TENANT_ID are set in your environment or .env file.
"Need admin approval" Your organization requires admin consent for the app permissions. Contact your IT administrator.
Port 3000 already in use
Change the port by setting MCP_SERVER_PORT in your .env file.
Authentication errors
- Clear stored tokens: The server stores tokens securely. If you have issues, try re-authenticating.
- Verify redirect URI matches exactly:
http://localhost:3000/auth/callback - Check app permissions in Azure Portal
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Run tests
npm test
# Lint
npm run lint
# Type check
npm run typecheckArchitecture
- MCP Server: Implements Model Context Protocol for AI assistant integration
- Auth Manager: Handles OAuth2 flow with PKCE and secure token storage
- Teams Client: Wraps Microsoft Graph API calls with rate limiting
- Rate Limiter: Enforces Microsoft Graph API limits (10,000 requests/10 min)
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and feature requests, please use the GitHub issues page.
