Skip to content

Handle unreadable peer JSON strings without -32603 - #2064

Open
jhrabchak wants to merge 1 commit into
modelcontextprotocol:mainfrom
jhrabchak:fix/issue-2063
Open

jhrabchak wants to merge 1 commit into
modelcontextprotocol:mainfrom
jhrabchak:fix/issue-2063

Conversation

@jhrabchak

Copy link
Copy Markdown

Fixes #2063

Changes

  • **\McpSessionHandler.GetStringProperty**: Catch \InvalidOperationException\ and return
    ull\ so best-effort telemetry tag extraction treats unreadable peer strings/property names as missing instead of aborting the request with -32603.
  • **\McpServerImpl.GetReturnedInputRequiredResult**: Catch \InvalidOperationException\ and return
    ull\ if
    esultType\ or a property name on the result object cannot be read.
  • **\McpServerImpl.ReadRequestMetadata\ & \WrapHandlerWithMrtr**: Catch \InvalidOperationException\ when reading _meta\ or
    equestState\ from
    equest.Params\ and throw \McpProtocolException\ with \McpErrorCode.InvalidParams\ (-32602).
  • **\McpTasksBuilderExtensions.HandleUpdateTask**: Read \params.taskId\ via \TryGetPropertyValue\ / \TryGetValue\ and throw \McpProtocolException\ with \McpErrorCode.InvalidParams\ (-32602) when \ askId\ is missing, non-string, or unreadable.
  • **\McpHeaderEncoder.ConvertToHeaderValue**: Intentionally left throwing \InvalidOperationException\ so \StreamableHttpHandler\ header validation does not skip comparison on unreadable values (matching Return 400 for unreadable strings in Streamable HTTP POST validation #2014).

Testing

  • Added \UnreadablePeerJsonTests\ covering invalid UTF-8 string values, invalid UTF-8 property names, and non-string \ askId.
  • \dotnet test tests/ModelContextProtocol.Tests -f net10.0: 3680 passed, 0 failed, 10 skipped.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle unreadable string values from peer JSON in core without -32603

1 participant