Repository navigation
Merge same-named fields across fragments in MCP tool output schemas - #10326
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes OperationToolFactory output-schema generation to tolerate duplicate response names (e.g., same-named fields selected across fragments) by merging colliding JSON Schema properties instead of throwing during tool warmup, and adds snapshot coverage for the previously failing selection shapes.
Changes:
- Replace
Dictionary.Addwith collision-awareTryAdd+ schema merge for same response-name fields in output schema generation. - Introduce
MergePropertiesto union object properties / array item schemas and intersectrequiredsets across branches. - Add new snapshot tests covering inline fragments, fragment spreads, and duplicate field selections.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Adapters/src/Adapters.Mcp.Core/OperationToolFactory.cs | Merges colliding response-name properties and adds recursive schema-merge helper. |
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/OperationToolFactoryTests.cs | Adds new snapshot tests and a small schema to reproduce same-named-field scenarios. |
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/snapshots/OperationToolFactoryTests.CreateTool_InlineFragmentsOnDifferentTypesSelectSameField_MergesIntoSingleProperty.json | New snapshot for identical sub-selections across inline fragments. |
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/snapshots/OperationToolFactoryTests.CreateTool_InlineFragmentsWithDivergingSubSelections_UnionsSubSelections.json | New snapshot for diverging sub-selections merged into a unified schema. |
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/snapshots/OperationToolFactoryTests.CreateTool_FragmentSpreadsSelectSameField_MergesIntoSingleProperty.json | New snapshot for same field selected via multiple fragment spreads. |
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/snapshots/OperationToolFactoryTests.CreateTool_DuplicateFieldSelection_MergesIntoSingleProperty.json | New snapshot for duplicate field selections in the same selection set. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage100.0% of changed lines covered (43/43)
Project coverage: 57.7% (286110/495834 lines) |
glen-84
added a commit
that referenced
this pull request
Sep 23, 2026
This was referenced Sep 26, 2026
Merged
This was referenced Oct 3, 2026
This was referenced Oct 5, 2026
Open
Open
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.
Summary
OperationToolFactorythrewArgumentExceptionwhile building a tool's output schema whenever two selections shared a response name — inline fragments on different types selecting the same field (the shape any interface/union with implementation-declared fields forces), fragment spreads doing the same, or a plain duplicate field selection. Because the throw happened during warmup, one such operation took down the whole tool catalogue.Test plan
OperationToolFactorysnapshot tests cover same-named fields via inline fragments (identical and diverging sub-selections), via fragment spreads, and via duplicate field selections; each previously failed with the reportedArgumentException.Adapters.Mcp.Testssuite passes (241 tests).Closes #10321