This directory contains examples of MCP servers using the StreamableHTTP protocol, which enables bidirectional communication over HTTP.
The StreamableHTTP protocol allows MCP servers to handle requests and responses over HTTP while maintaining the bidirectional nature of the MCP protocol. This is particularly useful for web-based integrations and scenarios where stdio transport is not suitable.
A complete MCP server implementation using the StreamableHTTP protocol with the following features:
- HTTP Transport: Uses
mcp.StreamableServerTransportfor bidirectional communication over HTTP - Multiple Tools: Includes weather, news, database query, and HTTP testing tools
- OpenTelemetry Integration: Full tracing and metrics support via Last9 wrapper
- CORS Support: Configured for browser compatibility
- Health Checks: Built-in health and info endpoints
- Graceful Shutdown: Signal handling (SIGINT/SIGTERM) with 10-second timeout for proper cleanup
- httpReadWriteCloser: Implements
io.ReadWriteCloserto bridge HTTP request/response with MCP transport - StreamableServerTransport: Enables bidirectional communication over HTTP
- HTTP Handler: Manages incoming HTTP requests and sets up MCP connections
- Tool Registration: Demonstrates various tool types with OpenTelemetry tracing
get-weather: Simulated weather API calls with HTTP tracingget-news: Mock news API integration with external HTTP requestsquery-database: Database query simulation with execution metricshttp-client-test: HTTP client testing with different endpoints
- Go 1.24.6 or later
- Dependencies installed via
go mod tidy
cd examples/http
go mod tidy
go run streamable-http-server.goThe server will start on port 8080 by default (configurable via PORT environment variable).
The server supports graceful shutdown via signal handling:
# Start the server
go run streamable-http-server.go
# In another terminal, send SIGINT (Ctrl+C) or SIGTERM
# The server will:
# 1. Stop accepting new connections
# 2. Wait up to 10 seconds for active requests to complete
# 3. Clean up resources and shut down gracefullyhttp://localhost:8080/mcp- Main MCP endpoint for StreamableHTTP protocolhttp://localhost:8080/health- Health check endpointhttp://localhost:8080/info- Server information and capabilities
You can test the server using curl or any HTTP client:
# Health check
curl http://localhost:8080/health
# Server info
curl http://localhost:8080/info
# MCP communication (requires proper MCP client)
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/list", "id": 1}'The StreamableHTTP protocol implementation:
- HTTP Request Handling: Each HTTP POST request to
/mcpcreates a new MCP session - Transport Creation:
StreamableServerTransportwraps the HTTP request/response in anio.ReadWriteCloser - Bidirectional Communication: The transport enables reading from the request body and writing to the response
- Session Management: Each HTTP request is treated as a complete MCP session
The examples include comprehensive OpenTelemetry integration:
- Automatic Tracing: All tool calls are automatically traced
- HTTP Request Tracing: External HTTP calls are traced with spans
- Custom Metrics: Performance and usage metrics collection
- Trace Propagation: Proper trace context propagation across service boundaries
Environment variables:
PORT: Server port (default: 8080)OTEL_EXPORTER_OTLP_ENDPOINT: OpenTelemetry collector endpointOTEL_SERVICE_NAME: Service name for tracing (default: streamable-http-mcp-server)
The StreamableHTTP protocol is ideal for:
- Web-based MCP integrations
- Browser-compatible MCP clients
- HTTP-based service architectures
- Scenarios requiring CORS support
- Integration with existing HTTP infrastructure
For stdio-based examples, see the ../stdio/ directory.