FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: reject non-JSON Content-Type with 415 and validate protocol version header on initialize by suryateja-g13 · Pull Request #968 · modelcontextprotocol/java-sdk · GitHub

Repository navigation

fix: reject non-JSON Content-Type with 415 and validate protocol version header on initialize - #968

Closed
suryateja-g13 wants to merge 2 commits into
modelcontextprotocol:mainfrom
suryateja-g13:fix/961-content-type-validation
Closed

suryateja-g13 wants to merge 2 commits into
modelcontextprotocol:mainfrom
suryateja-g13:fix/961-content-type-validation

Conversation

Copy link
Copy Markdown

Fixes #961 and #963.

Changes

#961 — Content-Type validation (HTTP 415)

HttpServletStreamableServerTransportProvider.doPost() accepted POST requests regardless of their Content-Type header, processing text/plain, application/x-www-form-urlencoded, and requests with no Content-Type identically to application/json requests.

Added an early guard in doPost() that returns HTTP 415 Unsupported Media Type when Content-Type is absent or does not start with application/json.

#963 — Protocol version header/body consistency on initialize

When the MCP-Protocol-Version request header on an initialize request disagrees with params.protocolVersion in the JSON-RPC body, the server now returns HTTP 400 with a JSON-RPC INVALID_PARAMS error rather than silently accepting the mismatched input.

Test plan

  • POST with Content-Type: text/plain → 415
  • POST with no Content-Type → 415
  • POST with Content-Type: application/json → proceeds normally
  • initialize with header 2025-03-26 and body 2025-11-25 → 400
  • initialize with matching header and body → proceeds normally
  • initialize with no MCP-Protocol-Version header → proceeds normally (header is optional)

…ion on initialize

HttpServletStreamableServerTransportProvider and
HttpServletStatelessServerTransport accepted POST requests regardless
of Content-Type, processing text/plain and form-encoded bodies as if
they were application/json.

Add an early Content-Type guard in doPost() on both transports that
returns HTTP 415 Unsupported Media Type when Content-Type is absent
or does not start with application/json.

Also validate on initialize requests that the MCP-Protocol-Version
HTTP header, when present, is consistent with the protocolVersion
field in the JSON-RPC body. A mismatch returns HTTP 400 with a
JSON-RPC INVALID_REQUEST error.

Fixes modelcontextprotocol#961
Fixes modelcontextprotocol#963

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
suryateja-g13 force-pushed the fix/961-content-type-validation branch from 34d1eb6 to 580cdf3 Compare May 19, 2026 02:33
…idation

Covers the validation added in the previous commit:
- HttpTransportValidationTests: verifies POST with non-JSON or missing
  Content-Type returns 415 for both streamable and stateless transports,
  and that application/json with charset parameter is accepted.
- StreamableTransportProtocolVersionTests: verifies that a matching
  MCP-Protocol-Version header passes, an absent header passes, and a
  mismatched header returns 400.

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>

Kehrlann commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Superseded by #1164 for the content-type
For initialize we're focusing on the new version of the protocol and we probably won't fix it.

Kehrlann closed this Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 POST requests with non-JSON request Content-Type

2 participants


Back | FazBrowse Home | New Git URL