Skip to content

fix(http): return HTTP 200 for dispatched INVALID_PARAMS - #3872

Closed
Muzaqil555 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Muzaqil555:fix/issue-3855
Closed

Muzaqil555 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Muzaqil555:fix/issue-3855

Conversation

@Muzaqil555

@Muzaqil555 Muzaqil555 commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #3855.

Motivation and Context

In modern Streamable HTTP, a malformed request envelope can produce JSON-RPC INVALID_PARAMS with HTTP 400. If the request passes inbound validation and dispatch rejects its typed parameters, the same JSON-RPC error belongs in the reply on HTTP 200.

The transport selects the status table where it writes the response. Inbound rejections use the validation table. Dispatched responses use the table of HTTP statuses specified for that path. This also covers Pydantic validation raised by ServerRunner, and preserves explicitly defined statuses such as 404 for METHOD_NOT_FOUND.

How Has This Been Tested?

  • Real in-process HTTP requests check typed tool parameters in JSON-response mode and in SSE mode before the response stream starts. Both return INVALID_PARAMS on HTTP 200. A malformed required _meta envelope returns HTTP 400.
  • ./scripts/test passed with 6,235 passed, 8 skipped, and 1 expected failure. Coverage was 100% and strict-no-cover passed. The run excluded the workspace's proxy variables so localhost tests could run directly.
  • Ruff and Pyright passed for the changed Python files.

Breaking Changes

Clients that treated dispatched INVALID_PARAMS as an HTTP 400 now receive the JSON-RPC error in an HTTP 200 response on the modern transport.

Types of changes

  • Bug fix
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

AI assistance was used to prepare and verify the follow-up. The branch tip with the follow-up is fa85c7a.

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3855.

If a maintainer assigns you to #3855, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Nov 18, 2026

Copy link
Copy Markdown

Thanks for the implementation. I think there is one important gap in the origin classification.

_execute_jsonrpc() marks only MCPError as from_handler=True; every other exception, including Pydantic ValidationError, is marked False. However, after classify_inbound_request() accepts the envelope, ServerRunner._on_request() can still raise a ValidationError while validating the method's typed parameters via entry.params_type.model_validate(...). modern_error_data() converts that to INVALID_PARAMS, but with from_handler=False it is sent through ERROR_CODE_HTTP_STATUS and becomes HTTP 400.

This is also reflected in the new test_execute_jsonrpc_maps_validation_error_to_invalid_params, which currently asserts from_handler is False. The clarification in #3855 was that errors arising after the inbound validation ladder—including kernel typed-parameter validation such as invalid tool arguments—should remain in-band on HTTP 200 unless the error code has an explicitly specified non-200 status. Malformed envelope / ladder rejections still go through _write_rejection() and remain HTTP 400; explicit statuses such as METHOD_NOT_FOUND should still be preserved.

Could you add an end-to-end regression test for invalid typed tool arguments that pass the envelope ladder but fail ServerRunner parameter validation, and ensure it returns HTTP 200 while a malformed _meta envelope still returns HTTP 400?

Thanks!

@Muzaqil555 Muzaqil555 changed the title fix(http): return HTTP 200 for handler-origin INVALID_PARAMS in moder… fix(http): return HTTP 200 for dispatched INVALID_PARAMS Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks for pointing out the typed-parameter path. I pushed the follow-up to the existing branch. The transport now selects HTTP status at the dispatch boundary. The wire tests cover INVALID_PARAMS on HTTP 200 for typed tool parameters in both response modes and HTTP 400 for a malformed required _meta envelope. The full local suite passed with 6,235 tests and 100% coverage. The PR now links #3855.

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

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modern Streamable HTTP: handler-produced -32602 answers HTTP 400 instead of 200

2 participants