UNPKG

msteams-mcp-server

Version:

Microsoft Teams MCP Server - Complete Teams integration for Claude Desktop and MCP clients with secure OAuth2 authentication and comprehensive team management

720 lines (577 loc) • 21.1 kB
# šŸš€ Microsoft Teams MCP Server A comprehensive **Model Context Protocol (MCP) server** that enables complete Microsoft Teams integration through natural language interactions. Built for **Claude Desktop**, **SIYA Desktop**, and any MCP-compatible application with **production-ready security**. [![NPM Package](https://img.shields.io/badge/npm-msteams--mcp--server-blue)](https://www.npmjs.com/package/msteams-mcp-server) [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-green)](https://nodejs.org/) [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE) ## ✨ Key Features - **šŸŽÆ Complete Teams Management** - Full control over teams, channels, members, and messages - **šŸ’¬ Advanced Messaging** - Send messages, replies, reactions with rich formatting and mentions - **šŸ“ File Management** - Upload, download, and manage files in teams and channels - **šŸ‘„ Group Chat Management** - Create and manage group chats with multiple participants - **šŸ“… Meeting Management** - Create online meetings and manage calendar events - **🟢 Presence Management** - Get and set user status and availability - **šŸ” Enterprise Security** - OAuth2 redirect flow with secure token storage - **šŸ¤– AI-First Design** - Intuitive tools perfect for natural language interactions - **🌐 Cross-Platform** - Works on macOS, Linux, and Windows - **⚔ NPX Ready** - Zero installation required, works out of the box ## šŸ› ļø Available Tools (12 Total) ### **šŸ” Authentication** - **`authenticate`** - Complete authentication management (login, logout, status) ### **šŸ‘„ Teams & Channel Management** - **`manage_teams`** - **UNIFIED**: List, search, create teams, and manage team members - **`manage_channels`** - **UNIFIED**: List, search, and create channels within teams - **`manage_members`** - **UNIFIED**: Add and remove team members with roles ### **šŸ’¬ Messaging & Communication** - **`send_message`** - Send messages to team channels with rich formatting and mentions - **`manage_messages`** - **UNIFIED**: Get and search messages in channels - **`send_direct_message`** - Send direct/private messages to users - **`get_direct_messages`** - Retrieve direct message conversations - **`manage_reactions`** - **NEW**: Add/remove emoji reactions to messages (šŸ‘ā¤ļøšŸ˜‚šŸ˜®šŸ˜¢šŸ˜ ) - **`manage_replies`** - **NEW**: Reply to messages and get threaded conversations ### **šŸ“ File Management** - **`manage_files`** - **NEW**: Upload, download, and list files in teams and channels ### **šŸ‘„ Group Chat Management** - **`manage_group_chats`** - **NEW**: Create group chats, manage members, and chat settings ### **šŸ“… Meeting & Calendar** - **`manage_meetings`** - **NEW**: Create online meetings, manage calendar events ### **🟢 Presence & Status** - **`manage_presence`** - **NEW**: Get and set user presence/status information ### **šŸ” Search & Discovery** - **`search_users`** - Find users in your organization ## šŸš€ Quick Start (2 Minutes) ### Option A: NPX (Recommended - Zero Installation) ```bash # 1. Authenticate with Microsoft Teams (one-time setup) npx msteams-mcp-server --login # 2. Verify authentication npx msteams-mcp-server --verify-login # 3. Add to Claude Desktop (see configuration below) # 4. Start chatting with Claude about your Teams! ``` ### Option B: Global Installation ```bash # Install globally npm install -g msteams-mcp-server # Authenticate msteams-mcp-server --login # Verify setup msteams-mcp-server --verify-login ``` ## šŸ”§ Claude Desktop Setup ### 1. Configuration File Location **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` **Linux**: `~/.config/Claude/claude_desktop_config.json` ### 2. Add MCP Server Configuration **For NPX (Recommended):** ```json { "mcpServers": { "teams": { "command": "npx", "args": ["msteams-mcp-server"] } } } ``` **For Global Installation:** ```json { "mcpServers": { "teams": { "command": "msteams-mcp-server" } } } ``` ### 3. Restart Claude Desktop After adding the configuration, restart Claude Desktop to load the MCP server. ## šŸ” Authentication Flow ### Step 1: Initial Authentication When you first use the authenticate tool or any Teams command: 1. **Call authenticate tool**: ``` Use the authenticate tool with action "login" ``` 2. **Get OAuth redirect URL**: Claude will show you: ``` šŸ” Microsoft Teams Authentication Required 🌐 Please complete authentication: 1. Visit: [OAuth Authentication URL] 2. Sign in with your Microsoft account 3. Complete the authorization process šŸ’” Direct link: [Click here to authenticate] ``` 3. **Complete in browser**: Follow the link and sign in with your Microsoft account 4. **Automatic completion**: The system automatically detects when authentication is complete ### Step 2: Using Teams Commands Once authenticated, you can: - "Show me my teams and their recent activity" - "Create a new team called 'Project Alpha' with Alice and Bob" - "Send a message to the general channel with a thumbs up reaction" - "Upload this document to the project team's files" - "Schedule a meeting for tomorrow at 2 PM with the development team" - "Set my status to 'In a meeting' for the next 2 hours" ### Authentication Actions | Action | Purpose | When to Use | |--------|---------|-------------| | `login` | Start OAuth redirect flow | First time or when tokens expire | | `status` | Check current auth state | Verify you're logged in | | `logout` | Clear all stored tokens | When switching accounts | ## šŸ’” Usage Examples ### Natural Language Commands (Talk to Claude) ``` šŸ”µ Team Management: "What teams am I a member of?" "Create a new private team called 'Secret Project' with john@company.com as owner" "Add sarah@company.com to the marketing team as an owner" "List all channels in the development team" šŸ”µ Messaging & Communication: "Send a message to the general channel saying 'Hello team! šŸ‘‹'" "Reply to the latest message in the project channel with 'Great work!'" "Add a heart reaction to the latest message in the team chat" "Send a direct message to Alice saying 'Can we schedule a call?'" šŸ”µ File Management: "Upload the project plan document to the team files" "List all files in the marketing channel" "Download the latest budget spreadsheet from the finance team" šŸ”µ Group Chats: "Create a group chat with Bob, Carol, and Dave for project discussion" "List all my group chats" "Add Emma to the project planning group chat" šŸ”µ Meeting Management: "Create a meeting tomorrow at 2 PM for project review with the team" "Show me my calendar events for this week" "List all my online meetings" šŸ”µ Presence & Status: "Set my status to 'Do Not Disturb' for the next hour" "Check Alice's availability status" "Show me the status of all development team members" šŸ”µ Advanced Operations: "Search for messages containing 'project update' in the last 7 days" "Find all files shared in the marketing channel this month" "Get all replies to the latest announcement in the general channel" ``` ### Direct Tool Usage (Advanced) <details> <summary>šŸ“‹ Authentication Examples</summary> ```javascript // Start authentication { "tool": "teams_authenticate", "arguments": { "action": "login" } } // Check current status { "tool": "teams_authenticate", "arguments": { "action": "status" } } ``` </details> <details> <summary>šŸ’¬ New Messaging Features</summary> ```javascript // Add reaction to message { "tool": "manage_reactions", "arguments": { "action": "add", "messageType": "channel", "teamId": "team-id", "channelId": "channel-id", "messageId": "message-id", "reactionType": "heart" } } // Reply to message { "tool": "manage_replies", "arguments": { "action": "reply", "messageType": "channel", "teamId": "team-id", "channelId": "channel-id", "messageId": "message-id", "content": "Thanks for the update!" } } // Send direct message { "tool": "send_direct_message", "arguments": { "displayName": "Alice Johnson", "content": "Can we schedule a quick call?" } } ``` </details> <details> <summary>šŸ“ File Management Examples</summary> ```javascript // Upload file to team { "tool": "manage_files", "arguments": { "action": "upload", "location": "team", "teamId": "team-id", "fileName": "project-plan.pdf", "fileContent": "base64-encoded-content", "mimeType": "application/pdf" } } // List files in channel { "tool": "manage_files", "arguments": { "action": "list", "location": "channel", "teamId": "team-id", "channelId": "channel-id" } } // Download file { "tool": "manage_files", "arguments": { "action": "download", "driveId": "drive-id", "itemId": "file-id" } } ``` </details> <details> <summary>šŸ‘„ Group Chat Management</summary> ```javascript // Create group chat { "tool": "manage_group_chats", "arguments": { "action": "create", "topic": "Project Planning", "members": ["user1-id", "user2-id", "user3-id"] } } // List group chats { "tool": "manage_group_chats", "arguments": { "action": "list" } } // Add members to group chat { "tool": "manage_group_chats", "arguments": { "action": "add_members", "chatId": "chat-id", "members": ["new-user-id"] } } ``` </details> <details> <summary>šŸ“… Meeting Management</summary> ```javascript // Create online meeting { "tool": "manage_meetings", "arguments": { "action": "create_meeting", "subject": "Project Review", "startDateTime": "2024-01-15T14:00:00Z", "endDateTime": "2024-01-15T15:00:00Z", "attendees": ["alice@company.com", "bob@company.com"], "isRecordingEnabled": true } } // Get calendar events { "tool": "manage_meetings", "arguments": { "action": "get_calendar", "startTime": "2024-01-15T00:00:00Z", "endTime": "2024-01-22T23:59:59Z" } } ``` </details> <details> <summary>🟢 Presence Management</summary> ```javascript // Set user presence { "tool": "manage_presence", "arguments": { "action": "set_presence", "availability": "DoNotDisturb", "activity": "InAMeeting", "expirationDuration": "PT2H" } } // Get user presence { "tool": "manage_presence", "arguments": { "action": "get_presence", "userId": "user-id" } } // Get bulk presence { "tool": "manage_presence", "arguments": { "action": "get_bulk_presence", "userIds": ["user1-id", "user2-id", "user3-id"] } } ``` </details> ## šŸ”§ Advanced Configuration ### Environment Variables (Custom Azure Apps) For enterprise scenarios with custom Azure applications: ```bash export TEAMS_CLIENT_ID="your-azure-app-client-id" export TEAMS_TENANT_ID="your-tenant-id-or-common" export TEAMS_CLIENT_SECRET="your-client-secret" export TEAMS_REDIRECT_URI="http://localhost:44005/oauth2callback" export TEAMS_AUTH_TYPE="redirect" # OAuth redirect flow export USER_ID="your-user-identifier" # Used for OAuth state parameter ``` ### Azure App Registration Guide <details> <summary>šŸ¢ Enterprise Setup (Optional)</summary> For advanced scenarios or enterprise requirements: 1. **Go to Azure Portal**: https://portal.azure.com 2. **Navigate to**: Azure Active Directory > App registrations 3. **Create new registration**: - Name: "Teams MCP Server" - Supported account types: Choose based on your needs - Redirect URI: `http://localhost:44005/oauth2callback` 4. **Configure API Permissions**: ``` Microsoft Graph > Delegated permissions: āœ… Team.ReadBasic.All - List teams āœ… Team.Create - Create teams āœ… TeamMember.ReadWrite.All - Manage members āœ… Channel.ReadBasic.All - List channels āœ… ChannelMessage.Send - Send messages āœ… ChannelMessage.ReadWrite - Read/reply to messages āœ… Chat.ReadWrite - Access chats and group chats āœ… ChatMessage.Send - Send chat messages āœ… ChatMessage.Read - Read chat messages āœ… OnlineMeetings.ReadWrite - Manage meetings āœ… Calendars.ReadWrite - Calendar access āœ… Presence.ReadWrite - Read/write presence āœ… Files.ReadWrite.All - File management āœ… User.Read - User profile āœ… Directory.Read.All - Search users ``` 5. **Grant admin consent** for the permissions 6. **Get credentials** and set environment variables </details> ## šŸ” Troubleshooting ### Quick Diagnostics ```bash # Check if server is working npx msteams-mcp-server --help # Verify authentication npx msteams-mcp-server --verify-login # Test with MCP Inspector npx @modelcontextprotocol/inspector npx msteams-mcp-server # Check configuration directory ls -la ~/.msteams-mcp/ ``` ### Common Issues & Solutions <details> <summary>šŸ” Authentication Issues</summary> **Problem**: Authentication fails or expires ```bash # Solution: Reset and re-authenticate npx msteams-mcp-server --reset-auth npx msteams-mcp-server --login ``` **Problem**: "Invalid client" error - Ensure you're using the OAuth redirect authentication flow - Check if your Azure app is configured as confidential or public client - Verify redirect URI matches exactly: `http://localhost:44005/oauth2callback` **Problem**: "Insufficient privileges" - Check that your Azure app has the required Microsoft Graph permissions - Ensure admin consent has been granted for the permissions - Verify your user account has appropriate Teams licenses </details> <details> <summary>šŸ› ļø Server Issues</summary> **Problem**: NPX command not found ```bash # Ensure Node.js >= 18 is installed node --version npm --version # If not installed, get Node.js from: https://nodejs.org/ ``` **Problem**: MCP server won't start in Claude 1. Check Claude Desktop configuration syntax 2. Restart Claude Desktop completely 3. Check console logs in Claude Desktop 4. Verify server works standalone: `npx msteams-mcp-server --help` **Problem**: "Permission denied" errors for new features - Verify your Azure app has the new permissions (OnlineMeetings, Presence, Files) - Re-grant admin consent after adding new permissions - Some features require specific Teams licenses (e.g., meeting recording) </details> <details> <summary>šŸ“Š Performance Issues</summary> **Problem**: Slow responses - Microsoft Graph API has rate limits - Large teams/channels take longer to process - Consider using `maxResults` parameter to limit data **Problem**: File upload/download timeouts - Large files may timeout during upload/download - Check network connectivity and bandwidth - Consider chunked upload for files > 4MB **Problem**: Bulk operations slow - Presence lookups and bulk operations are rate-limited - Use reasonable batch sizes (recommended: 20-50 users max) **āœ… Fixed**: Timeout issues with core operations (v1.0.25) - `manage_teams` list operations now use optimized direct HTTP requests - `manage_channels` list operations bypass Graph SDK hanging issues - `manage_messages` get operations use direct HTTP for better reliability - `manage_meetings` list operations handle unsupported query parameters correctly - All timeout issues with MCP framework have been resolved </details> ### Debug Mode ```bash # Enable detailed logging npx msteams-mcp-server --debug # Check log files cat /tmp/msteams-mcp-server.log ``` ### Configuration Files Location ```bash # Configuration directory ls ~/.msteams-mcp/ # Files stored: # - credentials.json (if using custom Azure app) # - msal-cache.json (token cache) # - token.json (authentication tokens) ``` ## šŸ›”ļø Security & Privacy ### Authentication Security - **OAuth2 Redirect Flow**: Secure authorization code flow with PKCE - **Token Storage**: Secure storage in user directory with restricted permissions - **Automatic Refresh**: Tokens refreshed automatically before expiration - **Scoped Permissions**: Only requests necessary Teams permissions ### Data Privacy - **No Data Storage**: Server doesn't store your Teams data permanently - **Local Processing**: All operations happen locally on your machine - **Audit Trail**: Check `~/.msteams-mcp/` for stored credentials and tokens - **Easy Cleanup**: `--reset-auth` removes all stored authentication data ### Enterprise Considerations - Works with Azure AD B2B/B2C - Supports conditional access policies - Compatible with MFA requirements - Audit logs available in Azure AD - Compliant with enterprise security policies ## šŸ“š API Reference ### Complete Tool Overview | Tool | Actions | Description | |------|---------|-------------| | `authenticate` | login, logout, status | Authentication management | | `manage_teams` | list, search, create, get, get_members | Team operations | | `manage_channels` | list, search, create | Channel operations | | `send_message` | - | Send channel messages | | `manage_messages` | get, search | Retrieve and search messages | | `send_direct_message` | - | Send direct/private messages | | `get_direct_messages` | - | Get direct message conversations | | `manage_reactions` | add, remove | Add/remove emoji reactions | | `manage_replies` | reply, get_replies | Reply to messages and get threads | | `manage_files` | upload, download, list | File management | | `manage_group_chats` | create, list, get_members, add_members, remove_member | Group chat management | | `manage_meetings` | create_meeting, list_meetings, get_calendar | Meeting and calendar management | | `manage_presence` | get_presence, set_presence, get_bulk_presence | User presence/status | | `manage_members` | add, remove | Team member management | | `search_users` | - | Find users in organization | ### Supported Reaction Types - šŸ‘ `like` - Thumbs up - ā¤ļø `heart` - Heart/love - šŸ˜‚ `laugh` - Laughing - 😮 `surprised` - Surprised - 😢 `sad` - Sad - 😠 `angry` - Angry ### Supported Presence States **Availability**: Available, Busy, DoNotDisturb, BeRightBack, Away **Activity**: Available, Busy, DoNotDisturb, BeRightBack, Away, InAMeeting, InACall ## šŸ”„ Development ### Local Development Setup ```bash # Clone repository git clone https://github.com/your-org/msteams-mcp-server.git cd msteams-mcp-server # Install dependencies npm install # Build project npm run build # Test locally npm run dev # Test with MCP Inspector npx @modelcontextprotocol/inspector ./dist/index.js ``` ### Project Structure ``` msteams-mcp-server/ ā”œā”€ā”€ src/ │ ā”œā”€ā”€ index.ts # Main MCP server with 12 tools │ └── utils/ │ ā”œā”€ā”€ api.ts # Logging utilities │ ā”œā”€ā”€ credential-store.ts # Secure credential storage │ ā”œā”€ā”€ teams-auth.ts # OAuth2 authentication │ └── teams-operations.ts # Complete Teams API integration ā”œā”€ā”€ bin/ │ └── cli.js # NPX entry point ā”œā”€ā”€ dist/ # Compiled JavaScript └── package.json # NPM configuration ``` ## šŸ“ˆ Feature Status ### āœ… Completed Features - **Core Teams Management** - Teams, channels, members - **Advanced Messaging** - Messages, reactions, replies, mentions - **File Management** - Upload, download, list files - **Group Chat Management** - Create, manage group chats - **Meeting Management** - Online meetings, calendar integration - **Presence Management** - User status and availability - **Secure Authentication** - OAuth2 flows, token management - **Direct Messaging** - Private user-to-user communication ### šŸ”„ Future Enhancements - Real-time notifications via webhooks - Advanced search with filters and sorting - Bulk operations for large-scale management - Meeting recording management - Advanced file permissions and sharing - Teams app installation and management - Analytics and usage reporting ## šŸ“„ License MIT License - see [LICENSE](LICENSE) file for details. ## šŸ™ Acknowledgments - Built with the [Model Context Protocol SDK](https://github.com/modelcontextprotocol/typescript-sdk) - Uses [Microsoft Graph API](https://docs.microsoft.com/en-us/graph/) for Teams integration - Authentication powered by [MSAL Node](https://github.com/AzureAD/microsoft-authentication-library-for-js) - Inspired by the Claude Desktop and SIYA Desktop communities --- ## šŸš€ Get Started Now ```bash # One command to get started: npx msteams-mcp-server --login # With custom user identifier for OAuth state: npx msteams-mcp-server --login --user-id "user123" # With custom redirect URI for OAuth: npx msteams-mcp-server --login --redirect-uri "http://localhost:8080/callback" # Then add to Claude Desktop and start chatting: "Show me my Teams and create a group chat with my project team!" ``` **Ready to supercharge your Teams workflow with AI?** šŸš€ **Questions?** Check the [troubleshooting section](#-troubleshooting) or [open an issue](https://github.com/your-org/msteams-mcp-server/issues).