Skip to content

Surface tool creation failures as unavailable MCP tools - #10328

Merged
glen-84 merged 2 commits into
mainfrom
gai/mcp-tool-creation-containment
Aug 31, 2026
Merged

Surface tool creation failures as unavailable MCP tools#10328
glen-84 merged 2 commits into
mainfrom
gai/mcp-tool-creation-containment

Conversation

@glen-84

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

Copy link
Copy Markdown
Member

Summary

  • A tool definition that passes document validation but makes OperationToolFactory.CreateTool throw 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.
  • A new ToolCreationFailed(toolName, exception) diagnostic event reports the failure through IMcpDiagnosticEvents, alongside the existing ValidationErrors event.

Test plan

  • New integration test (runs in both the Core and Fusion flavors): storage holds a healthy tool plus a validated document the factory cannot build a tool for; both tools are listed, the broken one as unavailable, and the failure is logged once. Without the containment, the test reproduces the reported behavior: the unhandled exception fails application startup.
  • Full Adapters.Mcp.Tests suite passes (244 tests).

Copilot AI lite review requested due to automatic review settings August 31, 2026 14:59

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

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.RebuildToolsAsync with exception handling to degrade failing definitions into “invalid/unavailable” tools.
  • Add ToolCreationFailed(toolName, exception) to IMcpDiagnosticEvents and 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.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

50.0% of changed lines covered (8/16)

File Covered Changed Patch %
…/Diagnostics/AggregateMcpDiagnosticEventListener.cs 0 6 0.0% 🔴
…/Adapters.Mcp.Core/Diagnostics/McpDiagnosticEventListener.cs 0 2 0.0% 🔴
…/Adapters/src/Adapters.Mcp.Core/McpStorageObserver.cs 8 8 100.0% 🟢
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)

@glen-84
glen-84 merged commit 30c9056 into main Aug 31, 2026
151 checks passed
@glen-84
glen-84 deleted the gai/mcp-tool-creation-containment branch August 31, 2026 15:37
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.

2 participants