Commit 580cdf3
committed
fix: reject non-JSON Content-Type with 415 and validate protocol version 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 #961
Fixes #963
Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>1 parent c09ee67 commit 580cdf3
2 files changed
Lines changed: 23 additions & 0 deletions
File tree
- mcp-core/src/main/java/io/modelcontextprotocol/server/transport
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
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