Skip to content

fix(server): return HTTP 200 for handler-origin INVALID_PARAMS in modern streamable HTTP - #3864

Closed
Cemilcanoz wants to merge 1 commit into
modelcontextprotocol:mainfrom
Cemilcanoz:fix/streamable-http-32602-status
Closed

Cemilcanoz wants to merge 1 commit into
modelcontextprotocol:mainfrom
Cemilcanoz:fix/streamable-http-32602-status

Conversation

@Cemilcanoz

Copy link
Copy Markdown

Summary

On the 2026-07-28 modern Streamable HTTP path (src/mcp/server/_streamable_http_modern.py), _write previously mapped every JSONRPCError through ERROR_CODE_HTTP_STATUS regardless of error origin. Because ERROR_CODE_HTTP_STATUS maps INVALID_PARAMS (-32602) to HTTP 400 for inbound envelope rejections, handler-origin -32602 errors (such as reading an unknown resource URI via MCPServer) were incorrectly returned with HTTP 400 instead of in-band HTTP 200.

This PR separates pre-dispatch boundary rejections from post-ladder dispatched responses:

  • Introduce _HANDLER_ERROR_HTTP_STATUS in src/mcp/server/_streamable_http_modern.py containing only the four spec-assigned non-200 status codes for dispatched responses (HEADER_MISMATCH -> 400, MISSING_REQUIRED_CLIENT_CAPABILITY -> 400, UNSUPPORTED_PROTOCOL_VERSION -> 400, METHOD_NOT_FOUND -> 404), leaving handler/dispatch INVALID_PARAMS (-32602) and INTERNAL_ERROR (-32603) at HTTP 200.
  • Parameterize _write(..., *, error_statuses=ERROR_CODE_HTTP_STATUS) so _write_rejection and malformed-body/parse rejections retain ERROR_CODE_HTTP_STATUS, while both post-dispatch JSON write paths (direct json_response=True and the SSE deferral fallback if done:) pass error_statuses=_HANDLER_ERROR_HTTP_STATUS.
  • Clarify the ERROR_CODE_HTTP_STATUS docstring in src/mcp/shared/inbound.py to reflect inbound/boundary rejections vs. dispatched handler errors.
  • Update test_modern_tools_call_mis_shaped_envelope_skips_validation_without_an_error_log to expect HTTP 200 and add wire-level regression tests covering JSON mode, SSE deferral fallback, SSE streaming after report_progress, and pre-dispatch ladder HTTP 400 preservation.

Fixes #3855

Testing

  • uv run pytest tests/server/test_streamable_http_modern.py tests/shared/test_inbound.py tests/interaction/transports/test_hosting_http_modern.py -q (269 passed)
  • uv run ruff check src/mcp/server/_streamable_http_modern.py src/mcp/shared/inbound.py tests/server/test_streamable_http_modern.py
  • uv run pyright src/mcp/server/_streamable_http_modern.py src/mcp/shared/inbound.py tests/server/test_streamable_http_modern.py

@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 16, 2026
@github-actions

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.

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

1 participant