Guide build/
Run a remote MCP server: Streamable HTTP, sessions and auth
What changes when an MCP server leaves localhost: one POST endpoint, no protocol sessions in revision 2026-07-28, a Host allowlist, and bearer tokens bound to your server.
Short answer
A remote MCP server exposes one Streamable HTTP endpoint, such as https://example.com/mcp, that takes each JSON-RPC message as its own POST. In protocol revision 2026-07-28, current as of December 6, 2026, there is no initialize handshake and no Mcp-Session-Id, so any instance can answer any request; sessions remain only for 2025-era clients. Validate the Origin header, allowlist your hostname, and act as an OAuth 2.1 resource server that accepts only tokens issued for your server.
Checked against: the MCP specification’s Streamable HTTP, authorization and changelog pages for revision 2026-07-28, the TypeScript SDK’s Express and authorization guides, and the Python SDK’s deploy and authorization pages, December 6, 2026.
Run by us: no. Commands are copied from the MCP specification, the official SDKs’ docs and Anthropic’s Claude Code docs.
What does a remote MCP server have to accept?
A remote MCP server must accept HTTP POST on one MCP endpoint, where each POST carries one JSON-RPC request or notification plus headers that mirror the body.
POST /mcp HTTP/1.1
Host: mcp.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/list
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}
This request is from the authorization spec. The versioning page lists 2026-07-28 as the current revision as of December 6, 2026. The Streamable HTTP spec sets these rules:
- The client’s
Acceptheader lists bothapplication/jsonandtext/event-stream, and the server answers each request with one JSON object or an SSE stream scoped to that request. MCP-Protocol-Versionmust match the version in the body’s_meta.Mcp-Methodis required on every request, andMcp-Nameontools/call,resources/readandprompts/get.- A missing or mismatched header gets
400 Bad Requestwith JSON-RPC error-32020(HeaderMismatch). - An accepted notification gets
202 Acceptedwith no body. - Servers must validate the
Originheader and answer an invalid one with403. They should bind to127.0.0.1when local and authenticate all connections. - Servers should send
X-Accel-Buffering: noon SSE responses so reverse proxies don’t buffer events.
Do I still need sessions and sticky routing?
Not for clients on revision 2026-07-28, which removed protocol-level sessions; you need them only to serve 2025-era clients that send initialize.
| Client’s protocol version | Session | What the load balancer must do |
|---|---|---|
| 2026-07-28 | None; no Mcp-Session-Id |
Nothing. Any instance serves any request. |
| 2025-11-25 and earlier | Mcp-Session-Id, held in one process’s memory |
Route a session’s requests to the same process, or serve those clients statelessly |
The 2026-07-28 changelog also removed the initialize handshake, the standalone GET stream and Last-Event-ID resumability. A client whose response stream breaks re-issues the request with a new ID. A server that speaks only 2026-07-28 should answer GET or DELETE on the endpoint with 405 and ignore any Mcp-Session-Id header.
The two official SDKs serve both eras from one endpoint by default:
- TypeScript.
createMcpHandlerdefaults tolegacy: 'stateless', which answers each 2025-era request from a fresh instance with no sessions.legacy: 'reject'makes the endpoint modern-only, per the legacy clients guide. - Python.
streamable_http_app()routes by theMCP-Protocol-Versionheader and keeps legacy sessions in an in-process dict. More than one worker then needs sticky routing, orstateless_http=True, per the legacy clients page.
State that spans calls now travels as a server-minted handle in an ordinary tool argument. The security best practices say a server must not treat possession of such a handle as authentication, and should bind each handle to the user from the verified token.
How do I expose the endpoint safely with the TypeScript SDK?
Name the hostnames you serve when you bind to all interfaces, and put requireBearerAuth in front of the /mcp route.
const publicApp = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['api.example.com'] });
import { requireBearerAuth } from '@modelcontextprotocol/express';
const auth = requireBearerAuth({ verifier });
publicApp.all('/mcp', auth, (req, res) => void node(req, res, req.body));
Both snippets are from the SDK’s Express recipe, where node is toNodeHandler(handler) and handler comes from createMcpHandler. On a localhost bind, createMcpExpressApp validates Host and Origin by default; binding 0.0.0.0 drops that default, so allowedHosts names the hosts you serve. verifier is your token check. The authorization guide adds expectedResource, which accepts only tokens issued for this server’s URL. That guide warns that @modelcontextprotocol/express 2.0.1 does not pass expectedResource on, so upgrade it together with @modelcontextprotocol/server.
How do I deploy the Python SDK behind a real hostname?
Pass transport_security with your hostnames, because the default accepts only requests addressed to localhost.
from mcp.server import MCPServer
from mcp.server.transport_security import TransportSecuritySettings
mcp = MCPServer("Notes")
@mcp.tool()
def add_note(text: str) -> str:
"""Save a note."""
return f"Saved: {text}"
security = TransportSecuritySettings(
allowed_hosts=["mcp.example.com", "mcp.example.com:*"],
allowed_origins=["https://app.example.com"],
)
app = mcp.streamable_http_app(transport_security=security)
uvicorn server:app --proxy-headers --forwarded-allow-ips='<proxy address>'
Per the deploy page, without transport_security every request behind a real hostname gets 421 Misdirected Request, and the reason appears only in the server log. Behind a TLS-terminating proxy, --proxy-headers stops redirects from pointing at http://, which the Python client refuses to follow. Scale out with uvicorn server:app --workers 4; the SDK has no workers= option. A multi-round-trip tool needs every worker to share RequestStateSecurity(keys=[...]) and the same server name. Otherwise a retry that reaches another worker fails with Invalid or expired requestState.
How does a client find out how to authenticate?
The server answers an unauthenticated request with 401 and a WWW-Authenticate header that points to its Protected Resource Metadata.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token", error_description="Authentication required", resource_metadata="http://127.0.0.1:8000/.well-known/oauth-protected-resource/mcp"
{"error": "invalid_token", "error_description": "Authentication required"}
{
"resource": "http://127.0.0.1:8000/mcp",
"authorization_servers": ["https://auth.example.com/"],
"scopes_supported": ["notes:read"],
"bearer_methods_supported": ["header"]
}
Both outputs are from the Python SDK’s authorization page. The client reads authorization_servers, gets a token there and retries. Under the authorization spec, the server is an OAuth 2.1 resource server with these duties:
| Rule | Level in the spec |
|---|---|
| Implement RFC 9728 Protected Resource Metadata | MUST |
| Validate that a token was issued for this server as its audience | MUST |
Answer invalid or expired tokens with 401 |
MUST |
| Accept or transit no other tokens | MUST NOT |
Answer a token missing a scope with 403 and error="insufficient_scope" |
SHOULD |
In both SDKs’ docs, the MCP server is the resource server: it verifies tokens and never issues them. In Python, set validate_token_resource=True in AuthSettings; leaving it unset while resource_server_url is set warns and behaves as False. Forwarding a client’s token to an upstream API is token passthrough, which the spec forbids.
How do I connect a client to the deployed server?
Give the client the endpoint URL; in Claude Code, that is claude mcp add --transport http.
claude mcp add --transport http <name> <url>
claude mcp add --transport http secure-api https://api.example.com/mcp \
--header "Authorization: Bearer your-token"
Both commands are from Anthropic’s Claude Code docs. For a server that uses OAuth, run /mcp in a Claude Code session and sign in through the browser. To check the endpoint first, point MCP Inspector at it with --server-url and --transport http, as in Debug an MCP server with MCP Inspector.
What breaks after deploy, and how do I fix it?
| Symptom | Cause | Fix |
|---|---|---|
421 Misdirected Request / Invalid Host header |
Python Host allowlist still set to localhost | Pass transport_security with allowed_hosts |
403 with Invalid Origin header |
A browser Origin not in the allowlist |
Add it to allowed_origins |
Redirect to http://... not followed |
The app sees http:// behind a TLS proxy |
Run uvicorn with --proxy-headers --forwarded-allow-ips |
Session not found with a 404 |
A 2025-era session hit a different worker or expired | Sticky routing, or stateless_http=True |
Invalid or expired requestState |
Workers seal state with different keys or names | Share RequestStateSecurity(keys=[...]) and the server name |
SSE stream disconnected: TypeError: terminated |
An idle stream was cut by a timeout | Keep the TypeScript SDK’s 15-second keep-alive on (keepAliveMs) |
What to read next
Sources
- Streamable HTTP (specification 2026-07-28)
- Authorization (specification 2026-07-28)
- Key Changes (specification 2026-07-28)
- Versioning
- Security Best Practices
- Serve with Express (TypeScript SDK)
- Sessions, state, and scaling (TypeScript SDK)
- Support legacy clients (TypeScript SDK)
- Require authorization (TypeScript SDK)
- Deploy & scale (Python SDK)
- Serving legacy clients (Python SDK)
- Authorization (Python SDK)
- Connect Claude Code to tools via MCP
Changelog
- First published.
Cite this page
Agents for Devs. "Run a remote MCP server: Streamable HTTP, sessions and auth." Published Dec 6, 2026. https://agentsfordevs.com/guides/deploy-remote-mcp-server - Page: https://agentsfordevs.com/guides/deploy-remote-mcp-server
- Markdown version: https://agentsfordevs.com/guides/deploy-remote-mcp-server.md
- Reuse: quote or summarize with a link to this page. Reuse terms
Cite one section
- What does a remote MCP server have to accept?
- Do I still need sessions and sticky routing?
- How do I expose the endpoint safely with the TypeScript SDK?
- How do I deploy the Python SDK behind a real hostname?
- How does a client find out how to authenticate?
- How do I connect a client to the deployed server?
- What breaks after deploy, and how do I fix it?
- What to read next