Skip to content

feat: add exact raw JSON request handling - #273

Open
steipete wants to merge 1 commit into
modelcontextprotocol:mainfrom
steipete:codex/exact-raw-json
Open

steipete wants to merge 1 commit into
modelcontextprotocol:mainfrom
steipete:codex/exact-raw-json

Conversation

@steipete

Copy link
Copy Markdown

Summary

  • add RawJSONValue and ExactJSONObject for ordered members, duplicate keys, exact Unicode-scalar identity, exact number lexemes, and strings that never auto-decode as data URLs
  • add a source-compatible two-argument Server.withMethodHandler overload that receives the normal typed request alongside RawRequestContext
  • route raw-aware single and batch requests with zero-copy, cancellation-aware parsing and explicit document/string/depth/entry limits while leaving legacy handlers, notifications, and inbound responses on their existing decoding path
  • keep malformed batch documents as top-level parse errors while isolating structurally invalid or over-limit items so valid siblings still run and available request IDs are retained
  • preflight programmatic data URL sizes with overflow-checked base64 length arithmetic before allocation

Validation

  • swift test (575 tests on macOS)
  • swift build -c release
  • swift package generate-documentation --target MCP --warnings-as-errors
  • Swift 6.1.2 Linux: swift test (494 tests) and swift build -c release
  • Swift 6.1.2 static Linux SDK: upstream install-and-build-with-sdk.sh --static

Documentation

  • document exact JSON method handlers and custom RawJSONLimits in the README

@varun06

varun06 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Please fix the conflicts.

@jeanmatthieu jeanmatthieu added the pending-close awaiting author confirmation for final closure label Dec 5, 2026
@jeanmatthieu

Copy link
Copy Markdown
Contributor

Hi @steipete, thank you for this PR and for the detailed work on exact JSON handling and batch error isolation!

Because rel/1.0.0 (#372) is now finalized and ready to merge into main, this PR conflicts heavily with the new server dispatch (withMethodHandler was replaced by setHandler(for:_:) passing (Parameters, HandlerContext) in #416). Several of the underlying issues this PR addressed also landed directly in 1.0.0:

For the remaining new public API (RawJSONValue, ExactJSONObject, ordered/duplicate keys, exact number lexemes), we'd prefer to discuss the design in an issue for a future release rather than merge it directly into 1.0.0. Could you please close this PR against main? We've added the pending-close label in the meantime — if you still need exact raw JSON access on top of 1.0.0, please open a design issue so we can align on an additive API!

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

Labels

pending-close awaiting author confirmation for final closure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants