MCP HTTP Wrapper - Expose stdio-based Model Context Protocol servers via HTTP using official Streamable HTTP transport. Supports tools, prompts, resources with JSON-RPC 2.0, SSE streaming, session management & security. Transform any MCP server into a REST API.
- ✅ Standards Compliant: Implements MCP Streamable HTTP transport specification
- ✅ Full MCP Support: Tools, prompts, resources, and initialization
- ✅ JSON-RPC 2.0: Proper request/response handling with error codes
- ✅ Server-Sent Events: Streaming support for real-time communication
- ✅ Session Management: Optional session tracking with
Mcp-Session-Id - ✅ Security: Origin validation, localhost binding by default
- ✅ Thread Safe: Robust concurrent request handling
- ✅ Error Handling: Comprehensive error messages and port conflict detection
Use docker-compose up -d to run. Modify these values in docker-compose.yml for different MCP servers:
- image:
mcp-wrapper:filesystem→mcp-wrapper:your-server - container_name:
mcp-server-filesystem→mcp-server-your-server - ports:
"3000:5000"→"your-port:5000" - command: MCP server command after
"--host", "0.0.0.0" - volumes: Mount directories as needed
Examples:
# SQLite server
command: ["python3", "http_wrapper.py", "--host", "0.0.0.0", "npx", "-y", "@modelcontextprotocol/server-sqlite", "/opt/data/db.sqlite"]
# Git server
command: ["python3", "http_wrapper.py", "--host", "0.0.0.0", "npx", "-y", "@modelcontextprotocol/server-git", "--repository", "/opt/repo"]No additional dependencies required beyond Python standard library + Flask:
pip install flask# Start with default settings (localhost:5000)
python http_wrapper.py python your-mcp-server.py
# Custom host and port
python http_wrapper.py --host 0.0.0.0 --port 8080 python your-mcp-server.py
python http_wrapper.py --port 3000 npx -y @modelcontextprotocol/server-filesystem .--host HOST Host to bind to (default: 127.0.0.1 - localhost only)
Use 0.0.0.0 to allow network access
--port PORT Port to bind to (default: 5000)
--debug Enable Flask debug mode
| Method | Endpoint | Description |
|---|---|---|
POST |
/mcp |
Main JSON-RPC endpoint |
GET |
/mcp |
Server-Sent Events streaming |
GET |
/health |
Health check |
initialize- MCP handshake and capability negotiationtools/list- List available toolstools/call- Execute a toolprompts/list- List available promptsprompts/get- Retrieve a promptresources/list- List available resourcesresources/read- Read a resource
curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {"tools": {}, "prompts": {}, "resources": {}},
"clientInfo": {"name": "my-client", "version": "1.0.0"}
},
"id": 1
}'curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "id": 2}'curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "read_file",
"arguments": {"path": "/path/to/file.txt"}
},
"id": 3
}'curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "prompts/get",
"params": {
"name": "code_review",
"arguments": {"language": "python"}
},
"id": 4
}'curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "resources/read",
"params": {
"uri": "file:///path/to/resource.txt"
},
"id": 5
}'curl -H "Accept: text/event-stream" http://127.0.0.1:5000/mcpcurl http://127.0.0.1:5000/healthUse the optional Mcp-Session-Id header to maintain session state:
curl -X POST http://127.0.0.1:5000/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: unique-session-123" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'All responses follow JSON-RPC 2.0 format:
{
"jsonrpc": "2.0",
"result": {
"tools": [...]
},
"id": 1
}{
"jsonrpc": "2.0",
"error": {
"code": -32601,
"message": "Method not found",
"data": "Unknown method: invalid/method"
},
"id": 1
}| Code | Message | Description |
|---|---|---|
-32700 |
Parse error | Invalid JSON |
-32600 |
Invalid Request | Malformed JSON-RPC |
-32601 |
Method not found | Unknown MCP method |
-32602 |
Invalid params | Missing/invalid parameters |
-32603 |
Internal error | Server-side error |
# Install and run
npm install -g @modelcontextprotocol/server-filesystem
python http_wrapper.py -- npx @modelcontextprotocol/server-filesystem /path/to/directory# Install and run
npm install -g @modelcontextprotocol/server-sqlite
python http_wrapper.py -- npx @modelcontextprotocol/server-sqlite /path/to/database.db# Install and run
npm install -g @modelcontextprotocol/server-git
python http_wrapper.py -- npx @modelcontextprotocol/server-git --repository /path/to/repo- Default localhost binding: Server binds to
127.0.0.1by default for security - Origin validation: Validates
Originheaders when provided - Network access: Use
--host 0.0.0.0only when network access is needed - Input validation: All JSON-RPC requests are validated
- Error handling: Sensitive information is not exposed in error messages
❌ Error: Port 5000 is already in use!
Suggestions:
• Try a different port: --port 5001
• Check what's using port 5000: netstat -tulpn | grep 5000
• Kill the conflicting process if it's safe to do so
- Check that the MCP server command is correct
- Verify the MCP server executable is in your PATH
- Look at the console output for MCP server error messages
- Verify the host and port are correct
- Check firewall settings if accessing from another machine
- Ensure the MCP server is running and responding
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source. Please check the license file for details.