Teams Messenger MCP App
A Model Context Protocol server that bridges Microsoft Teams with MCP-compatible clients (LLMs, agentic frameworks, CLI), enabling chat integration, message search, and event streaming without traditional REST API endpoints.
README
Teams Messenger MCP App
This project implements a pure Model Context Protocol (MCP) server that bridges Microsoft Teams and MCP-compatible clients (LLMs, agentic frameworks, and a rich CLI MCP client). All features are exposed via MCP tools, resources, and events—no REST API endpoints.
Features
- Microsoft Teams chat/message integration via MCP
- PostgreSQL-based Information Retrieval (IR) server for advanced search capabilities
- Persistent storage in DuckDB for chat/message history
- Hybrid semantic and lexical search (BM25 + vector, FlockMTL-style)
- CLI for login/token management and a rich MCP client for local testing
- Polling-based event emission for new messages
- Live event streaming and search for LLMs and CLI
- Single-agent (bot) account, not multi-user
Architecture
+-------------------+ +-------------------+ +-------------------+
| CLI MCP Client |<---->| MCP Server |<---->| Microsoft Teams |
| (rich terminal UI)| | (Python, FastMCP) | | (Graph API) |
+-------------------+ +-------------------+ +-------------------+
| |
| v
| +-------------------+ +-------------------+
| | DuckDB DB | | IR Server |
| +-------------------+ | (PostgreSQL, API) |
+-------------------+
|
v
+-------------------+
| PostgreSQL DB |
| (with pgvector) |
+-------------------+
- All chat/message/search logic is via MCP tools/resources/events
- Teams MCP server uses DuckDB for message storage
- IR server provides advanced search capabilities with PostgreSQL and pgvector
- IR server exposes an HTTP API for MCP server communication
Installation
Requirements
- Python 3.9+
- pip
- Docker and Docker Compose (for containerized deployment)
Option 1: Local Installation
1. Clone the repository
git clone <your-repo-url>
cd mcp-teams
2. Install dependencies
pip install -r requirements.txt
3. Configure environment variables
Copy the template and fill in your Azure AD/Teams credentials:
cp .env.template .env
# Edit .env and fill in your Azure AD and other settings
See the table below for variable descriptions.
Option 2: Docker Deployment (Recommended)
1. Clone the repository
git clone <your-repo-url>
cd mcp-teams
2. Configure environment variables
Copy the template and fill in your credentials:
cp .env.template .env
# Edit .env and fill in your settings
3. Build and start services
docker-compose up -d
Environment Variables (.env)
| Variable | Description | Example / Default |
|---|---|---|
| AZURE_CLIENT_ID | Azure AD Application (client) ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| AZURE_CLIENT_SECRET | Azure AD Application secret | your-secret |
| AZURE_TENANT_ID | Azure AD Tenant ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| AZURE_APP_OBJECT_ID | Azure AD Application object ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| DUCKDB_PATH | Path to DuckDB database file | db/teams_mcp.duckdb |
| TOKEN_PATH | Path to store persistent token cache | db/token_cache.json |
| POLL_INTERVAL | Polling interval (seconds) for new messages | 10 |
| DEMO_MODE | Set to true for mock/demo mode (no real Teams API calls) |
false |
| OPENAI_API_KEY | OpenAI API key for embedding generation | sk-... |
| POSTGRES_USER | PostgreSQL username | postgres |
| POSTGRES_PASSWORD | PostgreSQL password | postgres |
| POSTGRES_DB | PostgreSQL database name | mcp_ir |
| IR_SERVER_HOST | IR server hostname | ir_server |
| IR_SERVER_PORT | IR server port | 8090 |
Running the MCP Server
Local Mode (without Docker)
python mcp_server/server.py
Docker Mode (All Services)
docker-compose up -d
To check logs:
docker-compose logs -f teams_mcp # Teams MCP server logs
docker-compose logs -f ir_server # IR server logs
Demo Mode (no real Teams API calls)
Set DEMO_MODE=true in your .env and run as above.
CLI Usage
1. Login and Token Management
python cli/login.py login
python cli/login.py status
python cli/login.py logout
2. Rich CLI MCP Client
All commands below use the MCP stdio protocol to talk to the server.
List chats
python cli/mcp_client.py list_chats
Get messages from a chat
python cli/mcp_client.py get_messages <chat_id>
Send a message
python cli/mcp_client.py send_message <chat_id> "Hello from CLI!"
Create a new 1:1 chat
python cli/mcp_client.py create_chat <user_id_or_email>
Search messages (hybrid, BM25, or vector)
python cli/mcp_client.py search_messages "project update" --mode hybrid --top_k 5
Stream new incoming messages (live event subscription)
python cli/mcp_client.py stream
IR Server Usage
The IR server provides advanced search capabilities with PostgreSQL and pgvector. It exposes an HTTP API for MCP server communication.
IR Server API Endpoints
1. Health Check
GET http://localhost:8090/
2. List Available Tools
GET http://localhost:8090/api/tools
3. Search Content
POST http://localhost:8090/api/tools/search
Body:
{
"query": "your search query",
"search_type": "hybrid",
"limit": 10
}
4. Index Content
POST http://localhost:8090/api/tools/index_content
Body:
{
"content": "Text content to index",
"source_type": "teams",
"metadata": {
"author": "User Name",
"created": "2025-04-01T12:00:00Z"
}
}
For more detailed IR server documentation, see ir/README.md.
Search and Event Streaming
- Hybrid search: Combines BM25 and vector search with LLM reranking
- Live streaming: Subscribe to
messages/incomingfor real-time updates
Development & Extension
- Add new MCP tools/resources in
mcp_server/server.py - Extend Teams integration in
teams/graph.py - Modify IR capabilities in the IR server
- Add analytics, summarization, or RAG features using DuckDB, PostgreSQL, and LLMs
- Use the CLI as a test harness for all MCP features
Troubleshooting & FAQ
- Login fails: Check your Azure AD credentials and
.envvalues - No messages appear: Ensure polling is running and your bot account is in the Teams chat
- DuckDB errors: Check file permissions and paths in
.env - IR server not responding: Check Docker logs and ensure the container is running
- Demo mode: Set
DEMO_MODE=truefor local testing without real Teams
References
- Beyond Quacking: Deep Integration of Language Models and RAG into DuckDB (FlockMTL)
- Model Context Protocol documentation
- Microsoft Graph API docs
- PostgreSQL with pgvector extension
For full product details, see specs/app-spec.md.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。