
playground mcp model_context_protocol
展示使用模型上下文协议(MCP)实现两个应用之间的通信,包含轻量级无状态MCP服务器。
Repository Info
About This Server
展示使用模型上下文协议(MCP)实现两个应用之间的通信,包含轻量级无状态MCP服务器。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Communication Project
Overview
This project demonstrates communication between two applications using the Model Context Protocol (MCP). It implements a Fast MCP style with a lightweight, stateless MCP Server acting as a middleman.
Components
- MCP Server: A FastAPI-based server that manages and routes context between applications using Fast MCP principles (minimal memory, stateless delivery).
- App A: An email summarization service that uses OpenAI's GPT-4 to process emails and forward them through MCP.
- App B: A reply generation service that uses Anthropic's Claude to generate responses based on received context.
Prerequisites
- Python 3.8 or higher
- OpenAI API key (for App A)
- Anthropic API key (for App B)
- Available ports (configured in config.py):
- 9002 (MCP Server)
- 8002 (App A)
- 8003 (App B)
Installation
This project uses the uv package manager for faster dependency management.
- Install uv:
pip install uv
- Create and activate a virtual environment:
uv venv
source .venv/bin/activate # On macOS
- Install the project and its dependencies:
uv pip install -e .
Configuration
-
Configure OpenAI API key in
app_a/llm_client.py:OPENAI_API_KEY = "your_openai_key" -
Configure Anthropic API key in
app_b/llm_client.py:ANTHROPIC_API_KEY = "your_anthropic_key"
Running the Services
Start each service in a separate terminal (make sure your virtual environment is activated):
To start all services at once, simply run:
python main.py
This will start:
- MCP Server on port 9002
- App A on port 8002
- App B on port 8003
Alternatively, you can start each service individually:
-
Start the MCP Server:
cd mcp_server python -m uvicorn app:app --port=9002 -
Start App A:
cd app_a python -m uvicorn app:app --port=8002 -
Start App B:
cd app_b python -m uvicorn app:app --port=8003
Testing the Setup
-
Send a test email to App A:
curl -X POST "http://localhost:8002/summarize" \ -H "Content-Type: application/json" \ -d '{"email":"Hello, I need help with my laptop refund."}' -
Check App B's response:
curl http://localhost:8003/poll
Project Structure
/project-root
/src
/mcp_server
app.py # FastAPI app running the MCP server
router.py # Handles MCP routing with stateless delivery
/app_a
app.py # API to trigger summarization
llm_client.py # OpenAI API client
mcp_handler.py # Creates and sends MCP packages
/app_b
app.py # Polls MCP server for messages
llm_client.py # Anthropic API client
mcp_handler.py # Parses received MCP packages
config.py # Central configuration for ports and URLs
main.py # Process manager to run all services
Flow Diagram
- App A receives an email via
/summarize - App A summarizes it using OpenAI and builds an MCP package
- App A sends the MCP package to MCP Server
- App B polls the MCP Server via
/poll - MCP Server delivers the package to App B
- App B parses the package into a prompt
- App B uses Claude to generate a reply
- App B returns the generated reply
Fast MCP Implementation
This project implements Fast MCP principles:
- Minimal memory usage
- Stateless message delivery
- Simple message queuing
- Direct point-to-point routing
Quick Start
Clone the repository
git clone https://github.com/luketych/playground--mcp-model_context_protocolInstall dependencies
cd playground--mcp-model_context_protocol
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.