Model Context Protocol – Advanced Patterns for Production
Lesson 4: Transport Mechanisms for Production
Lesson Objectives
By the end of this lesson, students should be able to:
- Apply the transport selection criteria for stdio vs. HTTP/SSE
- Implement an HTTP/SSE transport server
- Add authentication to a remote MCP server
- Choose the right transport for their deployment topology
Lesson Content
Transport selection criteria.
- Factor: Deployment; stdio: Local, same machine as host; HTTP/SSE: Remote or shared infrastructure
- Factor: Multiple clients; stdio: One client (child process model); HTTP/SSE: Multiple simultaneous clients
- Factor: Authentication; stdio: OS process permissions; HTTP/SSE: Explicit (bearer token, mTLS)
- Factor: Latency; stdio: Lowest (IPC); HTTP/SSE: Higher (network)
- Factor: Complexity; stdio: Lower; HTTP/SSE: Higher
- Factor: Production infrastructure; stdio: Limited; HTTP/SSE: Full (load balancing, health checks)
Default choice: stdio for personal tools and development. HTTP/SSE for production servers, shared organizational tools, and remote deployments.
HTTP/SSE server implementation (Python pattern).
from mcp.server.sse import SseServerTransport
from starlette.applications import Starlette
from starlette.routing import Route, Mountsse = SseServerTransport("/messages/")
async def handle_sse(request):
async with sse.connect_sse(request.scope, request.receive, request._send) as streams:
await app.run(streams[0], streams[1], app.create_initialization_options())starlette_app = Starlette(routes=[
Route("/sse", endpoint=handle_sse),
Mount("/messages/", app=sse.handle_post_message),
])
Run with an ASGI server (uvicorn). Verify current HTTP/SSE implementation patterns at modelcontextprotocol.io/sdk.
Authentication for remote servers.
Remote MCP servers should require authentication. Common patterns:
- Bearer token: Client includes an Authorization header; server validates the token before accepting the connection
- mTLS (mutual TLS): Both client and server present certificates; appropriate for server-to-server deployments
For Claude Code connecting to a remote server, configure the bearer token in the MCP server configuration entry. The client includes it on every connection.
Health checks and load balancing.
HTTP/SSE servers integrate with standard infrastructure:
- Add a
/healthendpoint that returns 200 when the server is ready - Configure load balancer health checks against
/health - Use standard HTTP monitoring for server availability
stdio servers have no HTTP surface – health checking must be via process monitoring.
Enroll to continue this lesson.
The preview above shows the lesson objectives and opening lesson content. Enroll to view the full lesson, complete the practice work, and take the lesson quiz.
