Deploying & Hosting Remote MCP Servers
A complete, hands-on production guide to hosting remote Model Context Protocol servers on Cloudflare Workers, Docker containers, Fly.io, and AWS with SSE transports, reverse proxies, and enterprise security.
TL;DR — Production Deployment Quickstart
Running a local stdio MCP server is ideal for personal dev tools. To share tools across your team or AI agent fleet, wrap your MCP logic in an HTTP/SSE transport, package it as a Docker image or Cloudflare Worker, enforce TLS & Bearer token auth, and route requests to dedicated /sse and /message endpoints.
Stdio vs Remote HTTP/SSE: When to Deploy
The Model Context Protocol (MCP) supports two primary transport mechanisms for communicating between host AI applications (Claude Desktop, Claude Code, Cursor, Windsurf) and MCP servers:
- Standard Input/Output (stdio): The client launches the server as a local child process. Messages stream over OS IPC pipes (
stdinandstdout). This requires zero network setup and is perfect for desktop tools touching local files. - Server-Sent Events (SSE) & Streamable HTTP: The server operates as an independent web service listening on an HTTP port. The client connects over network endpoints (
/ssefor streaming server-to-client events and/messagefor client-to-server POST requests).
Deploying a remote MCP server is necessary when:
- Multiple team members or autonomous AI agents need to query a shared centralized database or private microservice without replicating database credentials locally.
- Your MCP server requires high-throughput compute, GPU acceleration, or persistent background tasks that cannot run on end-user laptops.
- You are building a SaaS product or commercial tool that exposes MCP capabilities to subscribers over API authentication. Once that server is monetized, tools like AgentMRR let you publish provider-verified recurring revenue for the agent product it powers.
Remote MCP Architecture & Transport Flow
Understanding the lifecycle of a remote SSE MCP session helps avoid common network disconnects and connection leaks:
- Session Initialization (HTTP GET /sse): The AI client opens an HTTP GET request to the server’s
/sseendpoint. The server responds withContent-Type: text/event-streamand sends an initial event payload containing anendpointURL with a unique session ID: - Client Request Dispatch (HTTP POST /message): Whenever the host model calls an MCP tool or requests a resource, the client sends an HTTP POST to
/message?sessionId=sess_987654321_abccontaining standard JSON-RPC 2.0 requests: - Server Execution & SSE Stream Response: The server receives the POST request, processes the handler asynchronously, and pushes the JSON-RPC response back down the persistent SSE connection.
Deploying on Cloudflare Workers (Edge Serverless)
Cloudflare Workers provide an ultra-low latency, globally distributed edge environment for hosting stateless or durable MCP tools. Using Cloudflare’s official agents framework, you can deploy a remote MCP server in minutes:
Write your server logic inside src/index.ts:
Deploy to Cloudflare Workers with a single command:
Containerizing MCP Servers with Docker
For microservices, enterprise Linux servers, or Kubernetes deployments, containerizing your MCP server guarantees consistent runtimes and isolates host system dependencies.
Below is an optimized, multi-stage Dockerfile for a TypeScript MCP server:
Combine your server container with Docker Compose for local testing or production deployment:
Deploying to Fly.io & Cloud Platforms
Platforms like Fly.io, Railway, and Render excel at hosting containerized SSE services because they support persistent, long-lived TCP/HTTP connections without strict gateway timeouts.
To deploy to Fly.io using their CLI:
Configure secrets securely using Fly CLI instead of committing credentials to source code:
Express SSE Remote Server Code (TypeScript)
Below is a complete, production-ready Express.js server written in TypeScript that configures the official SSEServerTransport from @modelcontextprotocol/sdk with session tracking:
Reverse Proxies (Nginx & Caddy) & SSL Setup
Never expose Node.js or Python application processes directly to the public internet. Always place a reverse proxy like Nginx or Caddy in front to handle HTTPS TLS termination, HTTP/1.1 response streaming, and client request buffering.
Caddyfile Configuration (Automatic Let’s Encrypt SSL)
Nginx Configuration (For Long-Lived SSE Connections)
Secrets Management & CORS Hardening
When hosting an MCP server in the cloud, security is a paramount concern. Review our comprehensive MCP Security Guide and Remote Authentication Guide for enterprise threat models. Always follow these infrastructure rules:
- Never hardcode API Keys: Inject credentials using environment variables (
process.env.API_KEY) or platform secret vaults (AWS Secrets Manager, Cloudflare Environment Secrets, Vault). - Restrict CORS Origins: If your remote server will be accessed from browser-based web clients or extensions, restrict
Access-Control-Allow-Originto known explicit domain origins rather than wildcard (*). - Rate Limiting: Use Nginx
limit_req_zoneor Redis rate-limiting middleware to cap incoming tool calls per token, protecting downstream APIs from runaway agent loops.
Health Monitoring & Log Hygiene
Maintaining operational observability for remote MCP servers requires separating stdout, stderr, and HTTP response channels cleanly:
⚠️ Critical Logging Rule for Stdio vs SSE Transports
In stdio mode, writing raw console.log() text to standard output corrupts the JSON-RPC transport stream and crashes the client. In remote HTTP/SSE mode, standard output is safe for application logs, but server metrics should still route to structured log aggregators (Datadog, CloudWatch, Axiom).
Expose a lightweight /health endpoint for load balancer health probes:
Connecting Clients to Remote Servers
Once your remote MCP server is deployed over HTTPS, users and developers can connect their AI clients by updating their JSON configuration snippets.
Example claude_desktop_config.json configuration for a remote SSE server:
For step-by-step instructions across Claude Code, Cursor, Windsurf, and VS Code, consult our detailed LLM Agents Integration Guide.
Frequently Asked Questions
Next Steps & Ecosystem Resources
Now that your remote MCP server is live in production, explore the rest of the AllMCPs documentation hub:
- Need to build a custom server first? Follow our step-by-step How to Build an MCP Server Guide.
- Deep dive into OAuth 2.0 PKCE and JWT auth with our guide to Securing Remote MCP Servers.
- Review complete threat models and prompt injection safety in our MCP Security Best Practices.
- Ready to publish your server to thousands of AI developers? Submit your MCP server to AllMCPs or check out our Free Developer Tools.
- If your deployed server is powering a paid AI agent product, AgentMRR tracks provider-verified MRR for AI-native products, a way to show real revenue instead of just traffic numbers.