MCP Shipyard
← Guides

MCP server CORS errors in browser clients: the headers that fix them

Why a remote MCP server works with curl and fails from a web page, which headers to allow and expose for Streamable HTTP, what changes in the 2026-07-28 revision, and a tested preflight.

corsbrowserstreamable-httpsessionsheaderssecurity
<!-- Evidence of demand (checked 2026-12-03 via WebSearch "MCP server CORS error browser client Mcp-Session-Id expose headers"): the Python SDK pull request modelcontextprotocol/python-sdk #1059 (merged August 21, 2025, opened and read) exists because browser clients could not read Mcp-Session-Id; Apollo MCP Server ships a dedicated CORS configuration page that lists mcp-session-id in both allow and expose lists; a TypeScript SDK issue (#764, seen in search results, not opened) reports browser clients losing sessions. Facts below come from the spec, MDN and the PR, cited inline. -->

MCP server CORS errors in browser clients: the headers that fix them

Your server answers curl and the MCP Inspector CLI. A web page that calls it gets blocked by CORS policy in the console, or it connects and then every call fails because the client never saw a session id. Both come from the same place: browsers enforce rules that curl does not. This guide covers who is affected, the headers to send, and a preflight you can test.

Who needs this

Only JavaScript running in a browser. A server-side client, a desktop app or a CLI does not apply CORS.

  • Claude connectors. Anthropic documents that its outbound traffic to your server comes from 160.79.104.0/21, and lists the same infrastructure for claude.ai, Desktop, mobile and Claude Code (authentication docs). Our inference: the requests come from servers, not from a page, so CORS does not decide whether a Claude connector works. If a connector fails, see works in Inspector, fails in Claude.
  • ChatGPT widgets. Widget code runs in a browser sandbox and calls your backend, so CORS matters there. That is covered in the widget origin change guide.
  • Your own web client. A page using the TypeScript SDK's StreamableHTTPClientTransport, or any fetch to your /mcp URL from another origin, needs everything below.

Why MCP trips browsers

A cross-origin request is "preflighted" unless it sticks to a small set of headers. MDN lists the only manually settable ones: Accept, Accept-Language, Content-Language, Content-Type (only with application/x-www-form-urlencoded, multipart/form-data or text/plain) and Range. MCP breaks that rule on every call:

  • Messages are POSTed with Content-Type: application/json, which is not on the list.
  • In the 2025-11-25 transport, clients MUST send MCP-Protocol-Version on all requests after initialization, and MCP-Session-Id once a session exists. Both are custom headers.
  • Session end uses DELETE, and the standalone stream uses GET with Last-Event-ID.

So the browser first sends OPTIONS and checks your answer. The response side has its own rule: JavaScript can read a response header only if it is in the safelist or in Access-Control-Expose-Headers (MDN). The session id arrives in the response to initialize, and it is not exposed by default. That is the exact bug the Python SDK fixed: its PR #1059 says browser clients "cannot access the Mcp-Session-Id header from initialization responses due to CORS restrictions", and the fix exposes it.

What to send

Allow these request headers: Content-Type, Accept, Authorization (if you use bearer tokens), Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID.

Expose Mcp-Session-Id. If your browser client needs to read WWW-Authenticate from a 401, expose that too. We did not check a source for which response headers are readable by default, so test it.

Allow methods GET, POST, DELETE, OPTIONS.

The 2026-07-28 revision changes the list. It removes protocol-level sessions and the GET stream, so Mcp-Session-Id and Last-Event-ID stop mattering for servers that only speak that revision. It adds required request headers: Mcp-Method on every request and Mcp-Name on tools/call, resources/read and prompts/get. Servers may also mirror tool parameters into Mcp-Param-{name} headers. All of these are custom headers, so a server that serves both eras should allow all of them. Header names are case-insensitive per the same page.

Do not use * when requests carry credentials. MDN says the wildcard is not allowed for Access-Control-Allow-Origin, -Headers, -Methods or -Expose-Headers on a credentialed request, so list explicit names. That includes explicit Mcp-Param-* names if you use that feature.

A tested example

This runs on Node with the TypeScript SDK 1.32 and no framework. We started it on a local port and sent the requests below with curl.

import http from 'node:http';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';

const ALLOWED_ORIGINS = new Set(['https://app.example.com']);

function cors(req, res) {
  const origin = req.headers.origin;
  if (!origin) return true;                       // not a browser request
  if (!ALLOWED_ORIGINS.has(origin)) {             // the spec requires 403 for an invalid Origin
    res.writeHead(403).end();
    return false;
  }
  res.setHeader('Access-Control-Allow-Origin', origin);
  res.setHeader('Vary', 'Origin');
  res.setHeader('Access-Control-Expose-Headers', 'Mcp-Session-Id');
  return true;
}

http.createServer(async (req, res) => {
  if (req.url !== '/mcp') return res.writeHead(404).end();
  if (!cors(req, res)) return;                    // runs for every response, errors included
  if (req.method === 'OPTIONS') {
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
    res.setHeader('Access-Control-Allow-Headers',
      'Content-Type, Accept, Authorization, Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID');
    res.setHeader('Access-Control-Max-Age', '600');
    return res.writeHead(204).end();
  }
  // ...create the McpServer and transport, then transport.handleRequest(req, res, body)
}).listen(3000, '127.0.0.1');

Two details matter. The preflight returns 204 with no MCP handling at all, and the CORS headers are set before any other code can fail. A reviewer on the Python PR pointed out that middleware added the simple way lets a 500 skip the CORS headers, so the PR was changed to wrap the whole app instead. An error response without the CORS headers reaches the page as a CORS failure, which hides the real error.

The checks, with the output we got:

# Preflight from an allowed origin: 204 with the allow and expose headers
curl -si -X OPTIONS http://127.0.0.1:3000/mcp \
  -H 'Origin: https://app.example.com' \
  -H 'Access-Control-Request-Method: POST' \
  -H 'Access-Control-Request-Headers: content-type,mcp-protocol-version,mcp-session-id'

# An origin you did not list: 403
curl -si -X POST http://127.0.0.1:3000/mcp -H 'Origin: https://evil.example'

The first returned 204 with Access-Control-Allow-Origin: https://app.example.com, the allow lists and Access-Control-Expose-Headers: Mcp-Session-Id. The second returned 403. A real initialize POST with the allowed origin also carried the CORS headers on the 200.

CORS is not your security boundary

CORS only tells a browser whether a page may read your response. It does not stop a script from sending the request. The spec's protection is separate: servers MUST validate the Origin header on all incoming connections and answer an invalid one with 403 Forbidden, to prevent DNS rebinding, and local servers SHOULD bind to 127.0.0.1 only. Authentication is a third layer. The SDK ships allowedOrigins, allowedHosts and DNS rebinding options on its transports and a createMcpExpressApp helper, which we confirmed in the installed 1.32 type definitions. Keep an explicit origin list and do not echo back whatever Origin arrives.

Other ways it still fails

  • Redirects. MDN notes that some browsers refuse to follow a redirect after a preflighted request. Make the exact URL users enter the final URL, with no trailing-slash or http to https redirect.
  • Preflight behind auth. OPTIONS carries no credentials, so a 401 on the preflight blocks everything. Answer it before the auth check.
  • A CDN or WAF in front. Check that it passes OPTIONS and does not strip your headers. Compare curl -si against the origin and against the public hostname.
  • Cached preflights. Access-Control-Max-Age caches your answer, so a header you added may not take effect until it expires. Test in a fresh profile.

Checklist

  • OPTIONS returns 2xx without auth and without redirects
  • Allow list covers Content-Type, Accept, Authorization, MCP-Protocol-Version, Mcp-Session-Id, Last-Event-ID, plus Mcp-Method and Mcp-Name if you serve 2026-07-28
  • Mcp-Session-Id is in the expose list
  • CORS headers are present on 401, 403 and 500 responses too
  • Origin allowlist is explicit and unlisted origins get 403
  • No * on credentialed requests

Check your server

Run the free scan at /scan to confirm the endpoint answers the handshake from outside your network. Use the curl checks above for the browser-specific part.

Check your server against these rules

Scan runs the checks from this guide against a live URL and lists each failing rule with its fix.

Scan a server