Skip to content

Merge same-named fields across fragments in MCP tool output schemas - #10326

Merged
glen-84 merged 2 commits into
mainfrom
gai/mcp-tool-fragment-field-merge
Aug 31, 2026
Merged

glen-84 merged 2 commits into
mainfrom
gai/mcp-tool-fragment-field-merge

Conversation

@glen-84

@glen-84 glen-84 commented Aug 31, 2026

Copy link
Copy Markdown
Member

Summary

  • OperationToolFactory threw ArgumentException while 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.
  • Colliding response names now merge into a single property: object schemas union their properties, only sub-fields selected in every branch stay required, and array schemas merge their item schemas the same way. A field reached only through a type condition was already optional and stays that way.

Test plan

  • New OperationToolFactory snapshot 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 reported ArgumentException.
  • Full Adapters.Mcp.Tests suite passes (241 tests).

Closes #10321

Copilot AI lite review requested due to automatic review settings August 31, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Add with collision-aware TryAdd + schema merge for same response-name fields in output schema generation.
  • Introduce MergeProperties to union object properties / array item schemas and intersect required sets 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.

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (43/43)

File Covered Changed Patch %
…/Adapters/src/Adapters.Mcp.Core/OperationToolFactory.cs 43 43 100.0% 🟢

Project coverage: 57.7% (286110/495834 lines)

@glen-84
glen-84 merged commit 9320b2a into main Aug 31, 2026
151 checks passed
@glen-84
glen-84 deleted the gai/mcp-tool-fragment-field-merge branch August 31, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adapters.Mcp: OperationToolFactory throws when inline fragments on different types select the same field

2 participants