Skip to content

fix(transport): answer malformed Streamable HTTP bodies with 400 - #1464

Open
DaleSeo wants to merge 2 commits into
mainfrom
fix/streamable-http-malformed-body-400
Open

DaleSeo wants to merge 2 commits into
mainfrom
fix/streamable-http-malformed-body-400

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Motivation and Context

According to the transport spec, StreamableHttpService should respond to a POST body that isn’t a JSON-RPC message with 400 Bad Request and a JSON-RPC parse error, instead of 415 Unsupported Media Type.

How Has This Been Tested?

Added tests

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Every malformed body gets -32700, including valid JSON of the wrong shape (e.g. null), where -32600 would be more precise. Telling the two apart means re-parsing the body, and serde's limits (trailing bytes, number range, recursion depth) make that re-parse misclassify some inputs. The spec doesn't require the split, so this keeps one path.

@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-transport Transport layer changes labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@michaelneale is on triage rotation this week and is the reviewer for this one.

Labels come from the PR labeler. Please review the change.

Automated triage. Labels are a first pass and the assigned maintainer has the final say.

@DaleSeo DaleSeo self-assigned this Nov 16, 2026
@DaleSeo
DaleSeo marked this pull request as ready for review November 16, 2026 19:28
@DaleSeo
DaleSeo requested a review from a team as a code owner November 16, 2026 19:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T14:40:34.396619Z 63d8ae8 New commits
🔒 Security Review ✅ Completed 2026-11-20T14:42:01.705005Z 63d8ae8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

tsarlandie-oai
tsarlandie-oai previously approved these changes Nov 20, 2026

@tsarlandie-oai tsarlandie-oai 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.

Looks good to me - two minor suggestions.

}
serde_json::from_slice::<ClientJsonRpcMessage>(&collected).map_err(|e| {
let error = JsonRpcError::new(
None,

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.

Could we echo the ID when it is readable? The wrong-version fixture has id: 1, and MCP requires the matching ID when the server can recover it. MCP error responses

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. A body with valid JSON but an invalid message now echoes its id if it’s a number or string, so the jsonrpc: "1.0" fixture gets id: 1 back.

serde_json::from_slice::<ClientJsonRpcMessage>(&collected).map_err(|e| {
let error = JsonRpcError::new(
None,
ErrorData::parse_error(format!("Parse error: {e}"), None),

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.

{ is a parse error (-32700), while null is valid JSON and warrants invalid request (-32600). Could we check the full body on the deserialization error path and test both codes, including trailing garbage as a parse error? JSON-RPC error codes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants