Streamable HTTP MCP Server
Implements a Model Context Protocol server that enables streaming communication between Azure OpenAI GPT-4o and tool services, allowing for real-time intelligent tool usage via Server-Sent Events.
README
Streamable HTTP MCP Server with Azure OpenAI GPT-4o
This project implements a Streamable HTTP MCP (Model Context Protocol) Server using FastAPI and integrates it with Azure OpenAI GPT-4o for intelligent tool usage.
🚀 Features
- MCP Server: Streamable HTTP server with SSE support
- Azure OpenAI Integration: GPT-4o with tool calling capabilities
- Simple Tools: Calculator, Weather (mock), and Time tools
- Docker Setup: Easy deployment with docker-compose
- Real-time Communication: Server-Sent Events (SSE) for streaming responses
📋 Prerequisites
- Docker and Docker Compose
- Azure OpenAI account with GPT-4o deployment
- Python 3.11+ (for local development)
🛠️ Quick Setup
- Clone and setup:
# Copy environment file
cp .env.example .env
# Edit .env with your Azure OpenAI credentials
nano .env
- Configure Azure OpenAI:
AZURE_OPENAI_API_KEY=your_api_key_here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
AZURE_OPENAI_API_VERSION=2024-02-01
- Start the MCP server:
./setup.sh start
- Run the GPT-4o client:
./setup.sh client
📖 Usage Examples
Basic Tool Usage
The client automatically demonstrates various tool interactions:
Query: What's the current time?
Response: The current time is 2024-01-15T14:30:45.123456
Query: Calculate 15 * 42 + 33
Response: The result is 663
Query: What's the weather like in New York?
Response: The weather in New York is currently sunny with a temperature of 22°C...
Complex Multi-tool Usage
Query: Can you get the weather for London and then calculate the percentage if the temperature was 20 degrees and now it's 25 degrees?
Response: The weather in London is currently 22°C and sunny...
The percentage increase from 20°C to 25°C is 25%.
🔧 Available Tools
- Calculator: Evaluate mathematical expressions
- Weather: Get mock weather data for any location
- Time: Get current timestamp
🏗️ Architecture
[GPT-4o Client] <--HTTP--> [MCP Server] <--SSE--> [Tools]
| |
| [Calculator]
| [Weather]
| [Time]
🌐 API Endpoints
POST /sse- Main MCP communication endpointGET /health- Health checkGET /tools- List available tools
📝 Manual Testing
Test the MCP server directly:
# Health check
curl http://localhost:8000/health
# List tools
curl http://localhost:8000/tools
# Test SSE endpoint
curl -X POST http://localhost:8000/sse \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "1", "method": "tools/list", "params": {}}'
🐳 Docker Commands
# Start MCP server only
docker-compose up -d mcp-server
# Run client once
docker-compose run --rm client
# View logs
docker-compose logs -f mcp-server
# Stop everything
docker-compose down
🧪 Development
Local Development
# Install dependencies
pip install -r requirements.txt
# Run server locally
python mcp_server.py
# Run client locally (in another terminal)
source .env
python client.py
Adding New Tools
- Create a new tool class in
mcp_server.py - Add tool definition to
TOOLSdictionary - Add handler in
MCPHandler.handle_tools_call
Example:
class NewTool:
@staticmethod
def do_something(param: str) -> Dict[str, Any]:
return {"result": f"Processed: {param}"}
# Add to TOOLS dictionary
TOOLS["new_tool"] = {
"name": "new_tool",
"description": "Does something useful",
"inputSchema": {
"type": "object",
"properties": {
"param": {"type": "string", "description": "Input parameter"}
},
"required": ["param"]
}
}
🐛 Troubleshooting
Common Issues
- Connection refused: Make sure MCP server is running on port 8000
- Authentication errors: Check your Azure OpenAI credentials in
.env - Tool call failures: Check MCP server logs for detailed error messages
Debug Mode
Enable debug logging:
docker-compose logs -f mcp-server
🔒 Security Notes
- Never commit your
.envfile with real credentials - Use environment variables in production
- Consider adding authentication for production deployments
📄 License
MIT License - feel free to use and modify as needed.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。