HTTP/SSE transport for MCP servers with hot reload support
Project description
mcp-http-transport
HTTP/SSE transport for MCP servers with hot reload support
๐ฏ Problem Solved
When developing MCP servers, every code change requires restarting Claude Desktop. This breaks:
- โ Your conversation context
- โ Your development flow
- โ Your productivity (>1 minute per iteration)
With mcp-http-transport:
- โ Hot reload without Claude Desktop restart
- โ Automatic reconnection on server restart
- โ Development cycle < 5 seconds
- โ Zero modification to your MCP handlers
๐ Quick Start
Installation
pip install mcp-http-transport
Basic Usage
import os
from mcp.server import Server
from mcp_http_transport import MCPTransportManager
# Your existing MCP server
server = Server("my-mcp-server")
@server.list_tools()
async def list_tools():
return [...] # Your tools
@server.call_tool()
async def call_tool(name, arguments):
return [...] # Your handlers
# Add transport layer (NO changes to handlers!)
async def main():
transport = MCPTransportManager(
server=server,
transport_mode=os.getenv("MCP_TRANSPORT", "stdio"),
host=os.getenv("MCP_HTTP_HOST", "localhost"),
port=int(os.getenv("MCP_HTTP_PORT", "3000")),
)
await transport.start()
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Configuration
.env file:
# Transport mode: "stdio" (default) or "http"
MCP_TRANSPORT=http
MCP_HTTP_HOST=localhost
MCP_HTTP_PORT=3000
Claude Desktop config:
{
"mcpServers": {
"my-server": {
"url": "http://localhost:3000/sse"
}
}
}
That's it! Now when you modify your code:
- Watchdog detects change โ restarts server
- Claude Desktop reconnects automatically
- No manual restart needed!
๐ Documentation
Transport Modes
| Mode | Use Case | Pros | Cons |
|---|---|---|---|
| stdio (default) | Production | Simple, minimal overhead | No hot reload |
| http | Development | Hot reload, auto-reconnect | Requires port |
Environment Variables
MCP_TRANSPORT:"stdio"or"http"(default:"stdio")MCP_HTTP_HOST: HTTP server host (default:"localhost")MCP_HTTP_PORT: HTTP server port (default:3000)
With Watchdog (Hot Reload)
Install watchdog:
pip install watchdog
Create wrapper script (mcp-server-wrapper.sh):
#!/bin/bash
cd /path/to/your/project
if [ "$MCP_DEV_MODE" = "1" ]; then
echo "[MCP] Dev mode - auto-reload enabled"
exec python -m watchdog.watchmedo auto-restart \
-d your_package \
-p "*.py" \
-R \
--interval 1.0 \
--debounce-interval 0.5 \
-- python -m your_package.mcp_server
else
exec python -m your_package.mcp_server
fi
Claude Desktop config:
{
"mcpServers": {
"my-server": {
"command": "/path/to/mcp-server-wrapper.sh",
"env": {
"MCP_DEV_MODE": "1",
"MCP_TRANSPORT": "http",
"MCP_HTTP_PORT": "3000"
}
}
}
}
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโ
โ Claude Desktop โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโ stdio (default)
โ โโ> stdin/stdout pipes
โ
โโโโ http (dev)
โโ> GET /sse (Server-Sent Events)
โโ> POST /messages/ (JSON-RPC)
HTTP/SSE Flow:
- Client:
GET http://localhost:3000/sseโ establishes SSE stream - Client:
POST http://localhost:3000/messages/โ sends JSON-RPC requests - Server: responds via SSE stream
- Watchdog restarts server โ Client reconnects automatically
๐ง Advanced Usage
Multiple MCP Servers
Run multiple MCP servers on different ports:
{
"mcpServers": {
"server-1": {
"url": "http://localhost:3000/sse"
},
"server-2": {
"url": "http://localhost:3001/sse"
}
}
}
Custom Host/Port
transport = MCPTransportManager(
server=server,
transport_mode="http",
host="0.0.0.0", # Listen on all interfaces
port=8080,
)
Switching Back to Stdio
Just remove or change the environment variable:
# Back to stdio (production)
MCP_TRANSPORT=stdio
Or omit it entirely (defaults to stdio).
๐งช Testing
# Install dev dependencies
pip install mcp-http-transport[dev]
# Run tests
pytest
# With coverage
pytest --cov=mcp_http_transport
๐ค Contributing
Contributions welcome! This package was extracted from a real-world MCP server to benefit the community.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Credits
- Built for MCP (Model Context Protocol)
- Inspired by real-world pain points in MCP development
- Uses Starlette and Uvicorn
โ ๏ธ Known Issues (v0.2.0)
Compatibility with mcp-remote
Status: The HTTP/SSE server implementation is not yet fully compatible with mcp-remote (the official Node.js proxy).
Symptoms:
mcp-remotefails with SSE header errors- POST endpoint works (HTTP 202) but connection drops
Workaround:
- Use stdio transport (default) for Claude Desktop
- Use
mcp-stdio-proxy(Python) when available - Or implement your own client that follows MCP HTTP/SSE spec
Contributing: We welcome PRs to fix compatibility! See the repository for details.
๐ Troubleshooting
Port Already in Use
# Find process using port
lsof -ti:3000
# Kill process
lsof -ti:3000 | xargs kill -9
# Or use different port
MCP_HTTP_PORT=3001
Claude Desktop Not Reconnecting
Cause: SSE retry delay (2-5s is normal)
Solution: Wait a few seconds after server restart. Claude Desktop will show "Reconnecting..." then connect automatically.
HTTP Mode Not Working
Check:
- Server logs:
tail -f /tmp/mcp-server-debug.log - Test endpoint:
curl http://localhost:3000/sse - Verify Claude Desktop config has correct URL
๐ Comparison
| Feature | stdio | http |
|---|---|---|
| Setup | Simple | Medium |
| Hot Reload | โ | โ |
| Auto-Reconnect | โ | โ |
| Production Ready | โ | โ ๏ธ Dev only |
| Multi-client | โ | โ |
| Overhead | Minimal | Very Low |
Made with โค๏ธ for the MCP community
If this package saves you time, consider โญ starring the repo!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_http_transport-0.2.0.tar.gz.
File metadata
- Download URL: mcp_http_transport-0.2.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
768549ef16c209740320da63eecfcd6c8bb20fded89d2d5ecfccc7c57e0a6320
|
|
| MD5 |
d1791862f50caad65f398fc32bee1762
|
|
| BLAKE2b-256 |
58842e6dd7fd4901e4c721a6068a0dd18f1259e906f46daf81653d360da9c77a
|
File details
Details for the file mcp_http_transport-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mcp_http_transport-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4c9df3f3318b242675c2332bf415c423fe4e66c222863826c25f086c217d9b8
|
|
| MD5 |
8cb5960dea2778b08dcb8b13684101d4
|
|
| BLAKE2b-256 |
c8455ca5f1c4a1f3e5c268b6290d8f32fbf9bc2f7e7a0fa38cdaa06e68314e5f
|