Skip to main content

20. Dual MCP Transport Protocol (STDIO + StreamableHTTP)

Date: 2025-10-13

Status

Accepted

Category

Core Architecture

Context

The Model Context Protocol (MCP) is Anthropic’s standard for exposing AI agents and tools. MCP enables:
  • Tool Discovery: Clients discover available tools via standardized protocol
  • Execution: Clients invoke tools with structured inputs/outputs
  • Streaming: Real-time streaming of results
  • Interoperability: Multiple clients can consume same MCP server
However, different deployment environments have different transport requirements:

Deployment Scenarios

  1. Local Development (Claude Desktop, IDEs)
    • Requirement: Simple local process communication
    • Constraint: No network setup, firewall configuration
    • User: Individual developers
  2. Cloud Deployments (Kubernetes, Cloud Run)
    • Requirement: HTTP-based communication
    • Constraint: Pods/containers need standard HTTP endpoints
    • User: Production deployments
  3. CI/CD Pipelines
    • Requirement: Programmatic execution via stdin/stdout
    • Constraint: No persistent processes
    • User: Automated testing
  4. Web Applications
    • Requirement: Browser-compatible streaming
    • Constraint: WebSocket or HTTP streaming support
    • User: End users accessing via web UI

Transport Protocol Trade-offs

Problem: No single transport protocol satisfies all deployment scenarios.

Decision

We will implement dual MCP transport support:
  1. STDIO Transport: For local development and Claude Desktop integration
  2. StreamableHTTP Transport: For cloud deployments and web applications
Both share the same underlying agent logic, differing only in transport layer.

Architecture

Transport 1: STDIO (Standard Input/Output)

Protocol: JSON-RPC over stdin/stdout
Communication Flow:
Entry Point:
Usage:

Transport 2: StreamableHTTP

Protocol: HTTP with Server-Sent Events (SSE) for streaming
Communication Flow:
Entry Point:
Usage:

Consequences

Positive Consequences

  • Flexibility: Support both local and cloud deployments
  • Developer Experience: Easy local testing with STDIO, production deployment via HTTP
  • Streaming: HTTP transport enables real-time streaming to web UIs
  • Compatibility: STDIO works with existing MCP clients (Claude Desktop)
  • No Lock-in: Can switch transports without changing agent logic

Negative Consequences

  • Maintenance Burden: Two codepaths to maintain and test
  • Documentation Overhead: Must document both transports
  • Complexity: Developers must choose correct transport for their use case
  • Testing: Must test both transports independently

Neutral Consequences

  • Separate Entry Points: Two different commands to start server
  • Configuration: Different env vars for each transport (e.g., HTTP port)

Implementation Details

Shared Agent Logic

Both transports use the same core agent:
Benefit: Agent logic defined once, used by both transports

STDIO Transport Details

File: src/mcp_server_langgraph/mcp/server_stdio.py (200+ lines) Key Features:
  • JSON-RPC 2.0 protocol
  • Stdin/stdout communication
  • Synchronous request/response (no streaming)
  • Process lifecycle management
Configuration:
Claude Desktop Integration:

StreamableHTTP Transport Details

File: src/mcp_server_langgraph/mcp/server_streamable.py (300+ lines) Key Features:
  • RESTful HTTP endpoints
  • Server-Sent Events (SSE) for streaming
  • FastAPI for async handling
  • CORS support for web clients
  • Authentication via JWT
Endpoints:
Configuration:
Streaming Example:
Client Usage (JavaScript):

Configuration Matrix

Alternatives Considered

1. STDIO Only

Description: Support only STDIO transport Pros:
  • Simpler (single codebase)
  • Easy local development
  • Works with Claude Desktop
Cons:
  • Cannot deploy to cloud (no HTTP endpoint)
  • No web UI support (no streaming)
  • Limited scalability (single process)
Why Rejected: Cloud deployments are critical for production use

2. HTTP Only

Description: Support only HTTP transport Pros:
  • Cloud-ready
  • Streaming support
  • Scalable
Cons:
  • Poor local dev experience (need to start server, configure port)
  • Incompatible with Claude Desktop (expects STDIO)
  • Firewall issues for local development
Why Rejected: Local development experience is critical for adoption

3. WebSocket Only

Description: Use WebSocket for bidirectional streaming Pros:
  • True bidirectional streaming
  • Real-time updates
  • Efficient for high-frequency messages
Cons:
  • More complex than HTTP/SSE
  • Firewall issues (WS often blocked by corporate firewalls)
  • Browser compatibility (some old browsers lack support)
  • Harder to debug (cannot use curl/postman easily)
Why Rejected: SSE (Server-Sent Events) sufficient for streaming, simpler than WebSocket

4. gRPC

Description: Use gRPC for efficient binary protocol Pros:
  • Efficient binary encoding
  • Built-in streaming
  • Type-safe (Protobuf)
Cons:
  • Browser support poor (requires grpc-web proxy)
  • Debugging difficult (binary protocol)
  • Overkill for MCP use case
  • Complexity (Protobuf definitions, code generation)
Why Rejected: HTTP/SSE is simpler and sufficient for MCP protocol

5. Single Transport with Adapters

Description: Single MCP server with pluggable transport adapters Pros:
  • Cleaner abstraction
  • Easier to add new transports
Cons:
  • More complex architecture
  • Premature abstraction (only 2 transports needed)
  • Testing overhead (adapter layer + transports)
Why Rejected: Two explicit implementations are simpler for current needs

Deployment Examples

Local Development (STDIO)

Kubernetes (StreamableHTTP)

Docker Compose (StreamableHTTP)

Cloud Run (StreamableHTTP)

Performance Characteristics

STDIO Transport

Use Case: Low-frequency, interactive CLI usage

StreamableHTTP Transport

Use Case: High-frequency, production API usage

Testing Strategy

STDIO Transport Tests

StreamableHTTP Transport Tests

Future Enhancements

  • WebSocket Transport: For real-time bidirectional communication
  • gRPC Transport: For microservice integrations
  • HTTP/2 Support: For multiplexed streaming
  • Transport Auto-Detection: Server detects transport from request

References