Skip to content

fix: handle outputSchema compilation errors in MCP tool discovery#24015

Closed
k-i-k-s wants to merge 1 commit intoanomalyco:devfrom
k-i-k-s:fix/mcp-outputschema-compat
Closed

fix: handle outputSchema compilation errors in MCP tool discovery#24015
k-i-k-s wants to merge 1 commit intoanomalyco:devfrom
k-i-k-s:fix/mcp-outputschema-compat

Conversation

@k-i-k-s
Copy link
Copy Markdown

@k-i-k-s k-i-k-s commented Apr 23, 2026

Issue for this PR

Closes #21373

Type of change

  • Bug fix

What does this PR do?

Recreated PR from @claygeo following PR template

When an MCP server returns outputSchema in its tools/list response, the SDK's default AjvJsonSchemaValidator can throw during schema compilation via ajv.compile(). This error propagates through listTools()cacheToolMetadata(), causing opencode's defs() function to catch the error and return undefined, which results in the server being marked as "Failed to get tools".

opencode doesn't use output schemas at all — only inputSchema is read in convertMcpTool(). So validation failures on outputSchema should never prevent tool discovery.

Fix: Create a TolerantJsonSchemaValidator that wraps AjvJsonSchemaValidator with try/catch in getValidator(). On compilation failure, returns a permissive fallback validator. Pass it to both new Client() calls via the SDK's jsonSchemaValidator option.

How did you verify your code works?

  • TypeScript type check passes (tsc --noEmit)
  • Config tests pass (144/144, 0 failures)
  • Static code path trace confirms the fix intercepts the exact throw site
  • SDK Client constructor correctly receives custom validator (verified via SDK source)

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When an MCP server returns outputSchema in its tools/list response,
the SDK's default AjvJsonSchemaValidator can throw during schema
compilation, causing listTools() to fail entirely. This makes the
server show "Failed to get tools" even though the tools themselves
are valid.

opencode doesn't use output schemas (only inputSchema is read in
convertMcpTool), so validation failures should be non-fatal.

Wrap AjvJsonSchemaValidator with a TolerantJsonSchemaValidator that
catches compilation errors and returns a permissive fallback. Pass
it to both Client constructors via the SDK's jsonSchemaValidator
option.

Closes anomalyco#21373
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #21592 - "fix: tolerate outputSchema compilation failures in MCP tool discovery"

Why it's related: This PR addresses the same issue - handling outputSchema compilation errors during MCP tool discovery. Both PRs aim to prevent validation failures on outputSchema from blocking tool discovery, which aligns with the current PR #24015's approach of creating a tolerant validator wrapper.

@k-i-k-s k-i-k-s closed this Apr 23, 2026
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.

"Failed to get tools" when MCP server returns outputSchema in tools/list response

2 participants