mcp-teams-gateway
A robust Model Context Protocol (MCP) adapter facilitating seamless bidirectional communication between Microsoft Teams infrastructure and external agentic systems. It leverages PostgreSQL for advanced indexing/retrieval operations and DuckDB for rapid local persistence, managing all interactions exclusively through defined MCP mechanisms (tools, resources, events). Includes a specialized Command Line Interface (CLI) utility for operational management and client simulation.
Author

aech-ai
Quick Info
Actions
Tags
Teams Communication Bridge via MCP
This implementation provides a dedicated MCP server component designed to interface Microsoft Teams capabilities with any compliant MCP client framework (e.g., LLM orchestration engines, autonomous agents). Interaction is strictly governed by the Model Context Protocol—no conventional REST endpoints are exposed.
Core Capabilities
- Native integration of MS Teams messaging streams into the MCP ecosystem.
- High-performance Information Retrieval (IR) subsystem powered by PostgreSQL (with vector indexing).
- Durable, transactional storage for message provenance utilizing DuckDB.
- Sophisticated querying mixing traditional lexical methods (BM25) and vector similarity (akin to FlockMTL techniques).
- A dedicated utility for credential management and a full-featured local MCP client application accessible via CLI.
- Event-driven architecture using a polling mechanism to capture new Teams activities.
- Support for real-time event subscriptions and live data stream access for consuming agents.
- Operates using a single service account identity (bot).
System Schematic
+-------------------+ +-------------------+ +-----------------------+
| CLI Simulator |<---->| MCP Adapter |<---->| Microsoft Teams API |
| (Terminal Client) | | (FastMCP Core) | | (MS Graph Interface) |
+-------------------+ +-------------------+ +-----------------------+
| |
| v
| +-------------------+ +-----------------------+
| | Local Storage | | Semantic Indexer |
| | (DuckDB) | | (PostgreSQL/pgvector) |
| +-------------------+ +-----------------------+
|
v
+-------------------+
| Persistent Index |
+-------------------+
- All application functions are exposed through standardized MCP verbs (tools, resources, events).
- Message history and short-term state are managed within DuckDB.
- The dedicated IR service handles complex indexing and retrieval logic using PostgreSQL.
- The IR service communicates with the core adapter via its internal HTTP interface.
Deployment Guide
Prerequisites
- Execution environment: Python version 3.9 or newer.
- Package management: Standard
piputility. - Containerization: Availability of Docker and Docker Compose.
Method A: On-Premise Setup
1. Obtain Source Code
git clone <your-repo-url>
cd mcp-teams-gateway
2. Install Dependencies
pip install -r requirements.txt
3. Configuration
Duplicate the environment template and populate required Azure credentials:
cp .env.template .env
# Modify .env with necessary connection and authentication parameters
Refer to the configuration table below for variable definitions.
Method B: Containerized Deployment (Recommended)
1. Obtain Source Code
git clone <your-repo-url>
cd mcp-teams-gateway
2. Configuration
Setup your secrets in the .env file:
cp .env.template .env
# Populate secrets in .env
3. Launch Services
docker-compose up -d
To monitor system operation:
docker-compose logs -f adapter_service # Core MCP adapter logs
docker-compose logs -f indexing_engine # IR engine logs
Demo Mode
Enable mock interactions by setting DEMO_MODE=true in the environment file, allowing testing without live Teams API interaction.
Configuration Parameters (.env)
| Parameter | Role | Sample Value / Default |
|---|---|---|
| AZURE_CLIENT_ID | Identifier for the registered Azure AD application | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| AZURE_CLIENT_SECRET | Application secret key | your-secret |
| AZURE_TENANT_ID | Directory tenant identifier | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| AZURE_APP_OBJECT_ID | Object ID corresponding to the application registration | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| DUCKDB_PATH | File path for transient message database storage | data/teams_mcp.duckdb |
| TOKEN_PATH | Location to persist OAuth tokens | data/token_cache.json |
| POLL_INTERVAL | Frequency (seconds) for checking Teams for new activities | 10 |
| DEMO_MODE | Activates simulation mode (disables Teams API interaction) | false |
| OPENAI_API_KEY | Key for generating semantic embeddings | sk-... |
| POSTGRES_USER | Database authentication user | postgres |
| POSTGRES_PASSWORD | Database access credential | postgres |
| POSTGRES_DB | Target database name for the IR service | mcp_archive |
| IR_SERVER_HOST | Network address for the indexing service | indexing_service |
| IR_SERVER_PORT | Network port for the indexing service | 8090 |
Executing the MCP Adapter
Local Execution (Non-Containerized)
python core/adapter_main.py
Containerized Execution (Via Docker)
docker-compose up -d
Command Line Interface (CLI) Operations
Token Management
python cli/auth_util.py authenticate
python cli/auth_util.py show_status
python cli/auth_util.py revoke_session
Primary MCP Client Functions (Using stdio protocol)
Retrieve known conversation identifiers
python cli/mcp_client.py enumerate_chats
Fetch message history for a specific thread
python cli/mcp_client.py fetch_history <thread_id>
Transmit a message payload
python cli/mcp_client.py dispatch_message <thread_id> "Urgent data packet."
Initiate a new direct conversation
python cli/mcp_client.py initiate_chat <recipient_identifier>
Execute knowledge retrieval (hybrid, lexical, or vector)
python cli/mcp_client.py query_archive "system health status" --method combined --limit 5
Subscribe to real-time event feed
python cli/mcp_client.py subscribe_events
Indexing Service Interface (IR Server)
The IR service, running on PostgreSQL, exposes an external HTTP interface exclusively for the MCP adapter to manage and query indexed content.
Available HTTP Methods
1. Operational Status
GET http://localhost:8090/
2. Tool Directory
GET http://localhost:8090/api/tools_manifest
3. Content Search Operation
POST http://localhost:8090/api/tools/execute_search
Payload:
{
"query_text": "retrieval target",
"strategy": "combined",
"count": 10
}
4. Content Ingestion (Indexing)
POST http://localhost:8090/api/tools/ingest
Payload:
{
"payload": "Raw textual data to store",
"context_tag": "teams_chat_log",
"attributes": {
"sender": "Agent_X",
"timestamp": "2025-04-01T12:00:00Z"
}
}
Consult indexer/API_SPEC.md for comprehensive IR server documentation.
Search Paradigm and Data Flow
- Advanced Retrieval: Employs a fusion of BM25 ranking and vector similarity measurements, potentially enhanced by subsequent LLM evaluation.
- Live Feeds: Real-time message ingress is managed via subscription to the
messages/incomingevent channel.
Development & Customization Points
- Extend adapter functionality by defining new MCP verbs in
core/adapter_main.py. - Modify Teams integration logic within the
teams_connector/graph_api_handler.pymodule. - Enhance retrieval algorithms inside the IR service implementation.
- Integrate auxiliary processing layers such as RAG pipelines or summarization routines utilizing DuckDB and PostgreSQL data stores.
- Leverage the CLI utility as the primary regression testing harness for all protocol interactions.
Diagnostics and Common Issues
- Authentication Failure: Validate Azure AD credentials and path settings in
.env. - No Data Ingestion: Verify that the polling service is active and the service account is a member of the target Teams channels.
- Storage Errors: Inspect file system permissions for the directory specified by
DUCKDB_PATH. - Indexing Service Unreachable: Check container health via
docker-compose logsfor the indexing component. - Testing Locally: Use
DEMO_MODE=trueto isolate logic from external dependencies.
Referenced Materials
- Deep Dive: Integrating LLMs and RAG within Columnar Stores (FlockMTL Reference)
- Model Context Protocol Standard
- Microsoft Graph API Documentation
- PostgreSQL Vector Indexing Extension
Detailed architectural blueprints are located in design/system_v2.md.
WIKIPEDIA: Business administrative solutions encompass the methodologies, software systems, controls, and analytical frameworks employed by organizations to navigate evolving commercial landscapes, maintain competitive advantage, and optimize operational efficacy. These tools address departmental necessities across planning, process orchestration, record keeping, human capital management, and strategic decision-making.
== Management Tool Categories == Business tools can be functionally categorized based on organizational aspects such as:
- Data entry and integrity verification mechanisms.
- Process monitoring and refinement frameworks.
- Data aggregation and strategic assessment platforms.
Technological maturation over the last decade has drastically altered the landscape of available business software. The pressure to reduce expenditures, maximize sales conversion, deeply understand client requirements, and consistently deliver products matching those needs compels managers toward strategic selection and rigorous customization of tools, rather than passive adoption of novel systems. Ineffective tool adaptation often results in organizational fragility.
== 2013 Benchmarks == A 2013 analysis by Bain & Company highlighted global tool utilization patterns, reflecting regional market dynamics and economic conditions. Leading categories included:
- Strategic Planning Frameworks
- Customer Relationship Management (CRM)
- Workforce Sentiment Analysis
- Competitive Benchmarking
- Performance Measurement Systems (e.g., Balanced Scorecard)
- Core Capability Definition
- Outsourcing Strategy
- Organizational Change Management Programs
- Supply Chain Optimization
- Vision/Mission Articulation
- Market Segmentation Analysis
- Total Quality Management (TQM)
== Business Software Evolution == Commercial software evolved from foundational Management Information Systems (MIS) through integrated Enterprise Resource Planning (ERP) suites, later incorporating Customer Relationship Management (CRM), culminating in modern cloud-based management platforms. Sustained organizational value derives not just from IT investment, but critically from the efficacy of the implementation process and the precise alignment between selected tools and enterprise-specific requirements.
