Skip to content

mcp: allow Content-Type parameters in streamable transport - #878

Merged
maciej-kisiel merged 2 commits into
modelcontextprotocol:mainfrom
rafaeljusto:content-type-check
Apr 3, 2026
Merged

maciej-kisiel merged 2 commits into
modelcontextprotocol:mainfrom
rafaeljusto:content-type-check

Conversation

@rafaeljusto

Copy link
Copy Markdown
Contributor

Use mime.ParseMediaType to parse the Content-Type header instead of exact string matching. Previously, the server required an exact match on application/json.

This allows the server to accept application/json with parameters (e.g. charset=utf-8), even though they are not required, following the robustness principle.

Per RFC 8259 (section 8.1), application/json is always UTF-8, so such parameters are technically redundant. However, parsing the media type makes the server more tolerant of client behaviour, improving compatibility without compromising security.

Use `mime.ParseMediaType` to parse the `Content-Type` header instead of
exact string matching. Previously, the server required an exact match on
`application/json`.

This allows the server to accept `application/json` with parameters
(e.g. `charset=utf-8`), even though they are not required [1],
following the robustness principle.

Per RFC 8259 (section 8.1) [2], `application/json` is always UTF-8, so
such parameters are technically redundant. However, parsing the media
type makes the server more tolerant of client behavior, improving
compatibility without compromising security.

[1] https://datatracker.ietf.org/doc/html/rfc4627.html#section-6
[2] https://datatracker.ietf.org/doc/html/rfc8259.html#section-8.1
Comment thread mcp/streamable.go Outdated

@maciej-kisiel maciej-kisiel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

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