Streamable HTTP turns an MCP server into a network service. That adds authentication, authorization, origin validation, proxy behavior, and a much larger blast radius. This guide uses a stateless request pattern with the official TypeScript SDK and keeps the HTTP boundary explicit.
The 2026-07-28 specification removed HTTP sessions and requires protocol metadata headers. SDK versions differ in what they implement. Pin the SDK, test against the protocol revision you claim, and read the current SDK docs before copying a session-based example from an older tutorial.
A stateless endpoint
import express from "express";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import { z } from "zod";
function buildServer(): McpServer {
const server = new McpServer({ name: "status-mcp", version: "1.0.0" });
server.registerTool(
"get_status",
{
title: "Get service status",
description: "Return a static, non-sensitive service status for demonstration.",
inputSchema: {},
annotations: { readOnlyHint: true },
},
async () => ({
content: [{ type: "text", text: JSON.stringify({ status: "ok" }) }],
}),
);
return server;
}
const app = express();
app.use(express.json({ limit: "1mb" }));
app.post("/mcp", async (req, res) => {
const server = buildServer();
const transport = new StreamableHTTPServerTransport({
// Stateless: a new transport per request; do not reuse across clients.
sessionIdGenerator: undefined,
});
res.on("close", () => {
void transport.close();
void server.close();
});
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
});
app.listen(3000, "127.0.0.1", () => {
console.error("status-mcp listening on http://127.0.0.1:3000/mcp");
});
This is intentionally minimal. It creates a server and transport per POST, which suits stateless tools. A stateful server needs a different lifecycle and careful isolation; do not share one transport across users.
Validate the origin and authentication
Browsers and local clients can reach a localhost port. A malicious website should not be able to drive your MCP server through the user’s browser. Validate the Origin header against an allow-list and require authentication before invoking tools.
const allowedOrigins = new Set(["https://app.example.com"]);
app.use((req, res, next) => {
if (req.method === "POST") {
const origin = req.headers.origin;
if (origin && !allowedOrigins.has(origin)) {
res.status(403).json({ error: "origin_not_allowed" });
return;
}
const auth = req.headers.authorization;
if (!auth?.startsWith("Bearer ")) {
res.status(401).json({ error: "unauthorized" });
return;
}
// Verify the token with your identity provider; do not compare to a
// long-lived secret in source code.
}
next();
});
Bearer tokens in headers are one option. OAuth with short-lived access tokens is preferable for user-facing services. Either way, authentication is not authorization: verify that the caller can access the specific project, repository, or tenant behind each tool.
Protocol headers and methods
For the 2026-07-28 revision, the client sends MCP-Protocol-Version and method metadata headers that must agree with the request body. Do not strip or rewrite them in a proxy. Preserve Accept, Content-Type, and MCP headers exactly.
POST is the required interaction at the single /mcp endpoint. Depending on the protocol revision, GET and DELETE may be optional or removed. Do not assume a GET health check proves the MCP endpoint works. Add a separate /healthz for liveness, and test MCP behavior with an MCP client.
Reverse proxies and TLS
Terminate TLS at a trusted reverse proxy or load balancer. Configure:
- No response buffering for streaming responses.
- Timeouts long enough for tool calls but short enough to bound hung requests.
- Request body size limits.
- Forwarding of Authorization and MCP headers.
- Access logs that exclude tokens and full bodies.
Bind to 127.0.0.1 during local development. Expose a public interface only through the proxy, with authentication, rate limits, and network policy in front of it.
Test the failure paths
At minimum:
- A valid token completes server discovery and tools/list.
- A missing token gets 401.
- An invalid Origin gets 403.
- A malformed JSON body gets a controlled 400.
- A large body is rejected by the size limit.
- A proxy does not buffer the streaming response.
- A tool error returns a structured MCP result, not a process crash.
The 401, 405, and HeaderMismatch guides cover the three most common remote transport failures.
For deployment steps, continue with deploy an MCP server. For the local alternative, compare the tradeoffs in MCP transports explained.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.