Skip to content

fix(http): pass parsed body to StreamableHTTPServerTransport - #8

Open
KRDucky wants to merge 1 commit into
RandomSynergy17:mainfrom
KRDucky:fix/http-parsed-body
Open

KRDucky wants to merge 1 commit into
RandomSynergy17:mainfrom
KRDucky:fix/http-parsed-body

Conversation

@KRDucky

@KRDucky KRDucky commented Nov 12, 2026

Copy link
Copy Markdown

fix(http): pass parsed Express body to MCP transport

Summary

Fixes HTTP 400 responses from the Streamable HTTP MCP endpoint when clients send valid JSON-RPC initialization requests.

Root cause

Express JSON middleware parses the incoming request body before the MCP transport receives it.

The POST handler previously called:

await transport.handleRequest(req, res);

Because the request stream had already been consumed, the transport attempted to parse it again, resulting in JSON-RPC error -32700 (Parse error: Invalid JSON).

Fix

Pass the already-parsed body to the MCP transport:

await transport.handleRequest(req, res, req.body);

The changes also introduce a testable HTTP application factory and a regression test for MCP initialization and session handling.

Validation

  • Reproduced the original HTTP 400 failure before the fix.
  • All 120 tests pass after the fix.
  • Build completed successfully.
  • MCP initialization returns HTTP 200 and a valid session ID.
  • Subsequent requests using the session ID succeed.
  • Docker image smoke test passes.
  • Existing tool registration remains functional.

Additional changes

Includes a Dockerfile and .dockerignore to support reproducible container deployments.

Known limitation

The lint command could not run because ESLint was absent from the existing development dependencies.

Testing environment

Node.js tests and Docker image validation were performed in resource-limited containers.

express.json() consumes the request stream before the /mcp handler runs,
so transport.handleRequest(req, res) found an empty body and rejected
every POST, including valid initialize requests, with HTTP 400 /
JSON-RPC -32700 "Parse error: Invalid JSON". Pass req.body as the
parsedBody argument.

Extract the Express app into an exported createHttpApp() so the
transport can be exercised in tests, and add a regression test that
initializes a session, sends a follow-up notification and deletes it.

Add a multi-stage Dockerfile (non-root node user, /health healthcheck)
and .dockerignore for the HTTP transport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant