---
title: "Run a remote MCP server: Streamable HTTP, sessions and auth"
type: guide
url: https://agentsfordevs.com/guides/deploy-remote-mcp-server
markdown: https://agentsfordevs.com/guides/deploy-remote-mcp-server.md
publisher: Agents for Devs
author: Agents for Devs desk
reviewed_by: Agents for Devs desk
published: 2026-12-06
updated: 2026-12-06
license: https://agentsfordevs.com/reuse
citation: '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'
attribution: Credit Agents for Devs and link to https://agentsfordevs.com/guides/deploy-remote-mcp-server
format: Guide
topics:
  - build
description: "Deploy a remote MCP server over Streamable HTTP: 2026-07-28 request rules, why sessions are gone, Host allowlists, scaling and OAuth bearer tokens."
---

# 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](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http), [authorization](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization) and [changelog](https://modelcontextprotocol.io/specification/2026-07-28/changelog) pages for revision 2026-07-28, the TypeScript SDK's [Express](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/express.md) and [authorization](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/authorization.md) guides, and the Python SDK's [deploy](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/deploy.md) and [authorization](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/authorization.md) 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.

```http
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](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization). The [versioning page](https://modelcontextprotocol.io/specification/versioning) lists 2026-07-28 as the current revision as of December 6, 2026. The [Streamable HTTP spec](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http) sets these rules:

- The client's `Accept` header lists both `application/json` and `text/event-stream`, and the server answers each request with one JSON object or an SSE stream scoped to that request.
- `MCP-Protocol-Version` must match the version in the body's `_meta`. `Mcp-Method` is required on every request, and `Mcp-Name` on `tools/call`, `resources/read` and `prompts/get`.
- A missing or mismatched header gets `400 Bad Request` with JSON-RPC error `-32020` (`HeaderMismatch`).
- An accepted notification gets `202 Accepted` with no body.
- Servers must validate the `Origin` header and answer an invalid one with `403`. They should bind to `127.0.0.1` when local and authenticate all connections.
- Servers should send `X-Accel-Buffering: no` on 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](https://modelcontextprotocol.io/specification/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.** `createMcpHandler` defaults to `legacy: '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](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/legacy-clients.md).
- **Python.** `streamable_http_app()` routes by the `MCP-Protocol-Version` header and keeps legacy sessions in an in-process dict. More than one worker then needs sticky routing, or `stateless_http=True`, per the [legacy clients page](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/legacy-clients.md).

State that spans calls now travels as a server-minted handle in an ordinary tool argument. The [security best practices](https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/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.

```ts
const publicApp = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['api.example.com'] });
```

```ts
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](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/express.md), 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](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/authorization.md) 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.

```python
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)
```

```console
uvicorn server:app --proxy-headers --forwarded-allow-ips='<proxy address>'
```

Per the [deploy page](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/deploy.md), 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.

```text
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"}
```

```json
{
  "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](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/authorization.md). The client reads `authorization_servers`, gets a token there and retries. Under the [authorization spec](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization), the server is an [OAuth 2.1](/glossary/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](/guides/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`.

```bash
claude mcp add --transport http <name> <url>
```

```bash
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](https://code.claude.com/docs/en/mcp). 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](/guides/debug-mcp-server-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

- [MCP authorization step by step](/guides/mcp-oauth-flow)
- [Token passthrough](/guides/token-passthrough)
- [Security checklist for shipping an MCP server](/guides/mcp-server-security-checklist)
- [Streamable HTTP](/glossary/streamable-http)

## Sources

1. [Streamable HTTP (specification 2026-07-28), Model Context Protocol](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http)
2. [Authorization (specification 2026-07-28), Model Context Protocol](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization)
3. [Key Changes (specification 2026-07-28), Model Context Protocol](https://modelcontextprotocol.io/specification/2026-07-28/changelog)
4. [Versioning, Model Context Protocol](https://modelcontextprotocol.io/specification/versioning)
5. [Security Best Practices, Model Context Protocol](https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/security_best_practices)
6. [Serve with Express (TypeScript SDK), Model Context Protocol](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/express.md)
7. [Sessions, state, and scaling (TypeScript SDK), Model Context Protocol](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/sessions-state-scaling.md)
8. [Support legacy clients (TypeScript SDK), Model Context Protocol](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/legacy-clients.md)
9. [Require authorization (TypeScript SDK), Model Context Protocol](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/authorization.md)
10. [Deploy & scale (Python SDK), Model Context Protocol](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/deploy.md)
11. [Serving legacy clients (Python SDK), Model Context Protocol](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/legacy-clients.md)
12. [Authorization (Python SDK), Model Context Protocol](https://github.com/modelcontextprotocol/python-sdk/blob/main/docs/run/authorization.md)
13. [Connect Claude Code to tools via MCP, Anthropic](https://code.claude.com/docs/en/mcp)

## Changelog

- 2026-12-06: 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: https://agentsfordevs.com/guides/deploy-remote-mcp-server.md
- Reuse: quote or summarize with a link to the page. Terms: https://agentsfordevs.com/reuse
