Skip to content

fix(server): parse Accept media types exactly#2481

Open
SnowSky1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
SnowSky1:fix/accept-header-media-types
Open

fix(server): parse Accept media types exactly#2481
SnowSky1 wants to merge 1 commit into
modelcontextprotocol:mainfrom
SnowSky1:fix/accept-header-media-types

Conversation

@SnowSky1

Copy link
Copy Markdown

Fixes #2480.

Summary

Streamable HTTP server Accept validation used raw substring checks, so values such as application/jsonx and text/event-stream-bogus incorrectly satisfied the required concrete media types. This affected both POST negotiation and GET SSE requests.

This change:

  • adds an internal listsMediaType helper that parses the comma-separated Accept list and compares media-type essences case-insensitively;
  • handles parameters and quoted parameter values without splitting on commas inside quoted strings;
  • updates GET and POST Streamable HTTP validation to use exact media-type matching;
  • adds regression coverage for substring false positives, valid case/parameter variants, quoted commas, wildcards, and missing headers;
  • includes a patch changeset for the server and core-internal packages.

This follows the same parsed-media-type approach recently applied to Content-Type in #2441 / #2444, while keeping Accept-specific list parsing internal.

Testing

  • pnpm --filter @modelcontextprotocol/core-internal test -- test/shared/mediaType.test.ts — 11 passing
  • pnpm --filter @modelcontextprotocol/server test -- test/server/streamableHttp.test.ts — 50 passing
  • pnpm --filter @modelcontextprotocol/core-internal check — clean
  • pnpm --filter @modelcontextprotocol/server check — clean
  • pre-push hook: full workspace typecheck, lint, and build — clean

Reject Streamable HTTP requests whose Accept values only contain the required media types as substrings, while preserving case-insensitive and parameterized values. Adds GET/POST regression coverage. Fixes modelcontextprotocol#2480.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SnowSky1 SnowSky1 requested a review from a team as a code owner July 13, 2026 02:15
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f897d9

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

This PR includes changesets to release 2 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/core-internal 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

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2481

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2481

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2481

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2481

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2481

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2481

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2481

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2481

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2481

commit: 9f897d9

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.

Streamable HTTP server accepts invalid media types by Accept-header substring

1 participant