Surface tool creation failures as unavailable MCP tools - #10328
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves resilience in the MCP tool catalog building pipeline by containing OperationToolFactory.CreateTool failures and surfacing affected tool definitions as “unavailable” instead of crashing tool initialization (including warmup paths). It also introduces a new diagnostic event to report tool-creation failures.
Changes:
- Wrap tool creation in
McpStorageObserver.RebuildToolsAsyncwith exception handling to degrade failing definitions into “invalid/unavailable” tools. - Add
ToolCreationFailed(toolName, exception)toIMcpDiagnosticEventsand wire it through the diagnostic listener infrastructure. - Add an integration test to ensure listing includes both healthy and failing tools and the failure is logged.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/IntegrationTestBase.cs | Adds an integration test for tool-creation failure containment and extends the test diagnostic listener to capture failures. |
| src/HotChocolate/Adapters/src/Adapters.Mcp.Core/McpStorageObserver.cs | Catches tool factory exceptions during rebuild and records failing definitions as invalid fallbacks while emitting a diagnostic event. |
| src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Diagnostics/McpDiagnosticEventListener.cs | Adds a virtual no-op ToolCreationFailed hook for consumers. |
| src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Diagnostics/IMcpDiagnosticEvents.cs | Introduces the new ToolCreationFailed diagnostic event to the contract. |
| src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Diagnostics/AggregateMcpDiagnosticEventListener.cs | Forwards ToolCreationFailed to all registered listeners. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage50.0% of changed lines covered (8/16)
Uncovered changed lines (JSON){
"sha": "78dc33cd387e408fe60dff7c4d41b2a9e27959b4",
"files": [
{ "path": "src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Diagnostics/AggregateMcpDiagnosticEventListener.cs", "ranges": [[55, 60]] },
{ "path": "src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Diagnostics/McpDiagnosticEventListener.cs", "ranges": [[26, 27]] }
]
}Project coverage: 57.7% (286077/495849 lines) |
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
OperationToolFactory.CreateToolthrow no longer takes down the whole tool catalogue — or, on the warmup path, the host process (the containment gap noted in Adapters.Mcp: OperationToolFactory throws when inline fragments on different types select the same field #10321). The failed definition now degrades the same way a schema-invalid one does: it is surfaced as an unavailable tool unless a valid same-named duplicate exists, and calls to it return the "currently unavailable" error.ToolCreationFailed(toolName, exception)diagnostic event reports the failure throughIMcpDiagnosticEvents, alongside the existingValidationErrorsevent.Test plan
Adapters.Mcp.Testssuite passes (244 tests).