Skip to content

fix(client): send MCP standard POST headers#2178

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/streamable-http-standard-headers
Open

fix(client): send MCP standard POST headers#2178
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/streamable-http-standard-headers

Conversation

@he-yufeng
Copy link
Copy Markdown

Fixes #2176.

This makes the streamable HTTP client include the SEP-2243 standard POST headers for non-batch JSON-RPC requests:

  • Mcp-Method is set from the JSON-RPC method name.
  • Mcp-Name is set from params.name or params.uri when present.
  • Batch requests keep the existing behavior.

Validation:

  • pnpm --filter @modelcontextprotocol/client test -- streamableHttp.test.ts
  • pnpm --filter @modelcontextprotocol/client typecheck
  • pnpm --filter @modelcontextprotocol/client lint
  • pnpm --filter @modelcontextprotocol/client build
  • git diff --check
  • pre-push hook: full repo lint, build, and typecheck

@he-yufeng he-yufeng requested a review from a team as a code owner May 29, 2026 08:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

🦋 Changeset detected

Latest commit: 487fd15

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2178

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2178

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2178

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server-legacy@2178

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2178

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2178

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2178

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2178

commit: 487fd15

@caomengxuan666
Copy link
Copy Markdown

Code looks correct for the single-request happy path. A few test coverage gaps I'd like to see addressed before merge:

  1. Notification test: Send a notification like {jsonrpc: "2.0", method: "notifications/initialized"} and verify Mcp-Method is set to notifications/initialized and Mcp-Name is absent. Per SEP-2243, notifications also require Mcp-Method.

  2. Response test: Send a JSON-RPC response {jsonrpc: "2.0", id: "1", result: {}} and verify neither Mcp-Method nor Mcp-Name is set — the guard on 'method' in message should skip it.

  3. Batch test: The existing 'should send batch messages' test doesn't assert header behavior. Send a JSONRPCMessage[] and verify mcp-method is not set.

  4. No-params test: Send {jsonrpc: "2.0", method: "initialize", id: "1"} (no params) and verify Mcp-Method is set but Mcp-Name is absent.

The implementation itself is solid — the ternary with typeof guard is the right call over ?? for the mcpName assignment. Just needs the tests to document the edge cases.

@he-yufeng he-yufeng force-pushed the fix/streamable-http-standard-headers branch from 4ef7e48 to 487fd15 Compare June 4, 2026 04:31
@he-yufeng
Copy link
Copy Markdown
Author

Rebased this onto current main and pushed the refreshed branch.

I also checked the current head against the requested coverage points. The PR now has focused Streamable HTTP client tests for:

  • JSON-RPC notifications including the MCP method header
  • JSON-RPC responses not including MCP method/name headers
  • JSON-RPC batch requests not including MCP method/name headers
  • requests without params omitting the MCP name header

Local validation:

pnpm --filter @modelcontextprotocol/client test -- streamableHttp.test.ts
# 58 passed

pnpm --filter @modelcontextprotocol/client run typecheck
pnpm --filter @modelcontextprotocol/client run lint
git diff --check

The pre-push hook also completed after reinstalling the workspace links:

pnpm -r build
pnpm -r typecheck
pnpm -r lint

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.

fix: Send required Mcp-Method/Mcp-Name headers per SEP-2243

2 participants