Skip to content

Conversation

@ochafik
Copy link
Contributor

@ochafik ochafik commented Jan 16, 2026

Problem

The MCP SDK's StreamableHTTPServerTransport returns 406 Not Acceptable when clients send:

  • Accept: */*
  • No Accept header

This happens because:

  1. The SDK uses @hono/node-server to convert Node.js requests to Web Standard Requests
  2. @hono/node-server reads from req.rawHeaders (immutable array), not req.headers
  3. Simply modifying req.headers.accept in middleware doesn't affect the SDK's header check

Solution

Patch rawHeaders using Object.defineProperty() to normalize the Accept header before the SDK processes the request.

Changes

  • Add normalizeAcceptHeader middleware that patches both req.headers and rawHeaders
  • Add HTTP logging middleware for debugging (with request correlation IDs)
  • Use app.post() with explicit 405 handlers for GET/DELETE (per SDK examples)

Testing

# All three now return 200:
curl -X POST http://localhost:5015/mcp -H 'Accept: application/json, text/event-stream' ...
curl -X POST http://localhost:5015/mcp -H 'Accept: */*' ...
curl -X POST http://localhost:5015/mcp ...  # no Accept header

Next Steps

Will copy main.ts to other example servers that use the same pattern.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/ext-apps@287

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-react@287

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-basic-vanillajs@287

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-budget-allocator@287

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-cohort-heatmap@287

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-customer-segmentation@287

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-map@287

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-pdf@287

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-scenario-modeler@287

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-shadertoy@287

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-sheet-music@287

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-system-monitor@287

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-threejs@287

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-transcript@287

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-video-resource@287

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/server-wiki-explorer@287

commit: 3c1cc34

…tibility

- Patch rawHeaders (not just req.headers) for @hono/node-server compatibility
- The SDK reads from rawHeaders which is normally immutable
- Add HTTP logging middleware for debugging
- Use app.post() with explicit 405 for GET/DELETE (per SDK examples)
@ochafik ochafik force-pushed the ochafik/fix-accept-header-normalization branch from cf885fe to a5d117f Compare January 16, 2026 14:20
@ochafik ochafik marked this pull request as draft January 16, 2026 14:27
Apply the same Accept header normalization fix to all example servers:
- Patch rawHeaders for @hono/node-server compatibility
- Use app.post() with explicit 405 for GET/DELETE
- Fixes 406 errors when clients send Accept: */* or no Accept header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants