Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Follow-up to #1138: adds tests validating behavior for less-common JSON-RPC payload shapes that may come from various implementations.

New test coverage (26 tests)

  • Null property handling: "error": null with result, both result and error null
  • Error precedence: when both error and result are present (non-compliant but possible), error takes precedence regardless of property order
  • ID edge cases: empty string, zero, negative numbers, long.MaxValue
  • Params variations: explicit null, empty object, array (positional arguments)
  • Property ordering: unusual orders like params before method, result before id
  • String handling: Unicode (CJK, Greek, emoji), escaped characters
  • Result types: primitive string, number, boolean, array
  • Error data types: null, numeric, array, complex object
  • Unknown properties: multiple unknowns interspersed with known properties
  • Minimal messages: notification with method only

Example

// Response with explicit null error (lenient handling)
string json = """{"jsonrpc":"2.0","id":1,"result":{"data":"value"},"error":null}""";
var message = JsonSerializer.Deserialize<JsonRpcMessage>(json, McpJsonUtilities.DefaultOptions);
Assert.IsType<JsonRpcResponse>(message); // Treated as success response
Original prompt

As a follow-up to @modelcontextprotocol/csharp-sdk/pull/1138, please add some tests validating behavior for various less-common shapes of JSON-RPC payloads, e.g. a valid message that has an "error": null property. Please try to be thorough in validating various combinations of properties and values while not being overly duplicative. Add the tests to an existing test file if possible.


💡 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.

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@stephentoub stephentoub marked this pull request as ready for review January 14, 2026 02:05
@stephentoub stephentoub enabled auto-merge (squash) January 14, 2026 02:05
@stephentoub stephentoub disabled auto-merge January 14, 2026 02:05
@stephentoub stephentoub enabled auto-merge (squash) January 14, 2026 02:05
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
auto-merge was automatically disabled January 14, 2026 02:06

Head branch was pushed to by a user without write access

Copilot AI changed the title [WIP] Add tests for various JSON-RPC payload shapes Add comprehensive edge case tests for JSON-RPC payload shapes Jan 14, 2026
Copilot AI requested a review from stephentoub January 14, 2026 02:06
@stephentoub stephentoub enabled auto-merge (squash) January 14, 2026 02:23
@stephentoub stephentoub merged commit dada237 into main Jan 14, 2026
10 checks passed
@stephentoub stephentoub deleted the copilot/add-json-rpc-payload-tests branch January 14, 2026 12:26
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.

3 participants