fix: JSON-RPC ID round-trip preservation for numeric IDs#119
Merged
brandonh-msft merged 7 commits intomainfrom Aug 1, 2025
Merged
fix: JSON-RPC ID round-trip preservation for numeric IDs#119brandonh-msft merged 7 commits intomainfrom
brandonh-msft merged 7 commits intomainfrom
Conversation
Co-authored-by: brandonh-msft <20270743+brandonh-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] If you send a jsonrpc request with ID as a number, the round trip response id will be turned into a string
Fix JSON-RPC ID round-trip preservation for numeric IDs
Jul 30, 2025
7fe6841 to
340a1fb
Compare
brandonh-msft
approved these changes
Jul 30, 2025
adamsitnik
approved these changes
Aug 1, 2025
Collaborator
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, but I wish we could just use some library for JSON-RPC related things..
| throw new ArgumentNullException(nameof(exception)); | ||
| } | ||
|
|
||
| exception.Data[RequestIdKey] = requestId.ToString(); |
Collaborator
There was a problem hiding this comment.
I wonder if the conversion to string is necessary. Can't we just stick the requestId as is into the data dictionary without conversion? Then, new JsonRpcId(ex.GetRequestId()) won't be necessary.
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.
This PR resolves an issue where JSON-RPC requests with numeric IDs were having their ID values converted to strings in responses, breaking the JSON-RPC specification requirement for ID preservation.
Problem
When sending a JSON-RPC request with a numeric ID (e.g.,
123), the A2A server would return responses with the same value converted to a string (e.g.,"123"). This violated the JSON-RPC 2.0 specification which requires that response IDs match the exact type and value of the request ID.Before:
After:
Solution
Introduced a new
JsonRpcIdstruct that preserves the original JSON type (string or number) of JSON-RPC request IDs:object?field to store eitherstringorlongvaluesIsString,IsNumber, andHasValuepropertiesAsString()andAsNumber()methods for retrieving typed valuesJsonRpcIdConverterthat maintains the original JSON type during serialization/deserializationstring,int, andlongtypesChanges
JsonRpcIdstruct with proper equality, conversion operators, and JSON converterJsonRpcRequestandJsonRpcResponseto useJsonRpcIdinstead ofstring?JsonRpcRequestConverterto preserve original ID types during deserializationJsonRpcIdA2AExceptionExtensionsTesting
All 240 existing tests pass, plus new tests specifically verify:
123) remain numeric in responses"test-id") remain strings in responsesThis change maintains full backward compatibility while ensuring compliance with the JSON-RPC 2.0 specification.
Fixes #113.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.