Repository navigation
Description
Follow-up to #2014.
#2014 makes Streamable HTTP POST validation return 400 / -32600 when a request contains a value that cannot be read, and makes McpServerImpl.ReadRequestMetadata treat an unreadable _meta protocol version as missing. Other places in core still read strings from peer-supplied JSON with GetValue<string>(), which throws InvalidOperationException when:
- a string value is not valid UTF-8 (
Utf8JsonReaderonly validates it when the token is converted to a .NET string), - the value is an escaped lone surrogate such as
"\uD800", - any property name in the containing
JsonObjectis not valid UTF-8 (the first lookup converts all property names), or - the value is not a string.
When this happens during request processing, the peer gets a generic internal error (-32603) instead of an error that identifies the request as malformed.
Sites to review:
return prop.GetValue<string>(); JsonValueKind.String => jsonValue.GetValue<string>(), resultTypeNode.GetValue<string>() == "input_required") requestStateNode.GetValue<string>() is { } requestState) csharp-sdk/src/ModelContextProtocol.Extensions.Tasks/Server/McpTasksBuilderExtensions.cs
Line 334 in 90476da
var taskId = context.Params?["taskId"]?.GetValue<string>()
For each site that reads peer input, decide whether an unreadable value should be rejected as -32600 / -32602 or treated as missing, and add tests with invalid UTF-8 values and property names.
Activity