Commit 34d1eb6
committed
fix: reject POST requests with non-JSON Content-Type with HTTP 415
HttpServletStreamableServerTransportProvider accepted POST requests
regardless of their Content-Type header, processing them normally even
when declared as text/plain, application/x-www-form-urlencoded, or
with no Content-Type at all.
Add an early Content-Type check in doPost() that returns HTTP 415
Unsupported Media Type when the request Content-Type is absent or
does not start with application/json, consistent with other MCP
server implementations and browser/CORS hardening expectations.
Also validate that the MCP-Protocol-Version request header on
initialize requests is consistent with the protocolVersion field in
the JSON-RPC body, returning HTTP 400 with a JSON-RPC INVALID_PARAMS
error on mismatch.
Fixes #961
Fixes #963
Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>1 parent c09ee67 commit 34d1eb6
1 file changed
Lines changed: 17 additions & 0 deletions
File tree
- mcp-core/src/main/java/io/modelcontextprotocol/server/transport
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
418 | 424 | | |
419 | 425 | | |
420 | 426 | | |
| |||
450 | 456 | | |
451 | 457 | | |
452 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
453 | 470 | | |
454 | 471 | | |
455 | 472 | | |
| |||
0 commit comments