Fix RequestOptions writing an integer progress token as a JSON string - #1832
Open
dfedoryshchev wants to merge 1 commit into
Open
Fix RequestOptions writing an integer progress token as a JSON string#1832dfedoryshchev wants to merge 1 commit into
dfedoryshchev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RequestOptions.GetMetaForRequest()writes an integer progress token as a JSON string.RequestOptions.cs:82callsProgressToken.ToString()rather than going throughProgressToken's own converter, sonew ProgressToken(42)leaves as"42".That is not cosmetic, because
ProgressTokencompares by boxed value. The peer reads the field back asProgressToken("42")(RequestParams.cs:62-72triesstringfirst), then stamps that token on every progress notification. The caller compares"42"against its own42, boxedlongnever equalsstring, and progress notifications match nothing. They are dropped silently, with no error.It is reachable from every high-level request that takes a
RequestOptions; fourteen call sites feedoptions?.GetMetaForRequest()into the request params.The existing test for exactly this case,
GetMetaForRequest_OnlyProgressTokenSetAsLong_ReturnsNewObjectWithToken, misses it because it asserts onactual["progressToken"]?.ToString(), andJsonNode.ToString()unquotes a string node.Fix: serialize through the converter instead.
[JsonSerializable(typeof(ProgressToken))]is already registered in the source-generated context (McpJsonUtilities.cs:196), so this stays trim and AOT safe and cannot drift from the converter again.One behaviour change worth flagging: a
ProgressTokenwith a null inner value now serializes as""rather thannull. The SDK's own reader throws onnullhere, so this is an improvement, but it is a change on the same line.Verification:
Expected: Number, Actual: String.RequestOptionsTests: 17 passed / 1 failed, to 18 passed.ModelContextProtocol.Testson net10.0: 2298 passed, 0 failed, 2 skipped. ExcludesClientIntegrationTestsandDockerEverythingServerTests, which neednpxand Docker and fail identically before and after.ModelContextProtocol.Corebuilds clean on net10.0, net9.0, net8.0 and netstandard2.0 with 0 warnings under warnings-as-errors.