🏓 Experimental Ping-Pong server that showcases how to call MCP (Model Context Protocol) tools remotely via FastAPI (HTTP & SSE). Useful as a minimal reference implementation for building your own MCP servers/clients.
https://github.com/kimtth/mcp-remote-call-ping-pongMost MCP servers run locally with stdio transport, but what if you need to expose MCP functionality over HTTP or integrate it into web applications? This experimental ping-pong server shows you exactly how to bridge that gap.
You've got MCP tools that work great locally, but you need them accessible via HTTP endpoints or real-time SSE streams. Standard MCP implementations don't provide web-ready transport out of the box. This reference implementation solves that by wrapping FastMCP with FastAPI, giving you both REST endpoints and Server-Sent Events for your MCP tools.
Two Transport Methods: HTTP endpoints for request-response patterns and SSE streams for real-time communication. The same MCP tools work with both approaches.
Thread-Safe Session Management: Proper session handling when multiple clients access your MCP tools simultaneously.
Ready-to-Extend Structure: Clean separation between the MCP logic and transport layer, so you can swap out the simple ping-pong example with your actual tools.
API Gateway for MCP Tools: Expose your local MCP servers to external applications through HTTP endpoints. Perfect for integrating MCP functionality into existing web services.
Browser-Based MCP Clients: The included HTML client demonstrates how to call MCP tools directly from web applications without complex WebSocket setup.
Microservice Architecture: Deploy MCP tools as independent HTTP services that other services can consume, rather than requiring direct MCP protocol integration.
Real-Time Tool Execution: Use SSE transport for tools that need to stream results progressively, like file processing or long-running computations.
# Clone and install
git clone https://github.com/kimtth/mcp-remote-call-ping-pong.git
cd mcp-remote-call-ping-pong
poetry install
# Run HTTP server
python mcp-api-server.py
# Test with curl
curl -X POST http://localhost:8080/ping-pong \
-H "Content-Type: application/json" \
-d '{"command": "ping"}'
The SSE implementation is equally straightforward:
# Terminal 1: Start SSE server
python mcp-sse-server.py
# Terminal 2: Connect client
python mcp-sse-client.py
Replace the ping-pong tools with your actual MCP implementations. The FastAPI wrapper handles HTTP concerns while your MCP tools focus on business logic. Session management and request routing are already implemented.
For production deployment, you'll want to add authentication, rate limiting, and proper error handling around the existing structure. The foundation handles the complex part - bridging MCP with web protocols.
This isn't a production-ready server, but it's the reference implementation you need to build one. Study the session management, see how MCP tools integrate with FastAPI routes, and adapt the pattern for your specific use case.