Skip to main content

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

PyPI version Python 3.11+ License: MIT

๐ŸŽฏ 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:

  1. Watchdog detects change โ†’ restarts server
  2. Claude Desktop reconnects automatically
  3. 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:

  1. Client: GET http://localhost:3000/sse โ†’ establishes SSE stream
  2. Client: POST http://localhost:3000/messages/ โ†’ sends JSON-RPC requests
  3. Server: responds via SSE stream
  4. 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.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Credits

โš ๏ธ 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-remote fails with SSE header errors
  • POST endpoint works (HTTP 202) but connection drops

Workaround:

  1. Use stdio transport (default) for Claude Desktop
  2. Use mcp-stdio-proxy (Python) when available
  3. 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:

  1. Server logs: tail -f /tmp/mcp-server-debug.log
  2. Test endpoint: curl http://localhost:3000/sse
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_http_transport-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_http_transport-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for mcp_http_transport-0.2.0.tar.gz
Algorithm Hash digest
SHA256 768549ef16c209740320da63eecfcd6c8bb20fded89d2d5ecfccc7c57e0a6320
MD5 d1791862f50caad65f398fc32bee1762
BLAKE2b-256 58842e6dd7fd4901e4c721a6068a0dd18f1259e906f46daf81653d360da9c77a

See more details on using hashes here.

File details

Details for the file mcp_http_transport-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_http_transport-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4c9df3f3318b242675c2332bf415c423fe4e66c222863826c25f086c217d9b8
MD5 8cb5960dea2778b08dcb8b13684101d4
BLAKE2b-256 c8455ca5f1c4a1f3e5c268b6290d8f32fbf9bc2f7e7a0fa38cdaa06e68314e5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page