Skip to content

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

Open
claygeo wants to merge 1 commit intoanomalyco:devfrom
claygeo:fix/mcp-outputschema-compat
Open

fix: tolerate outputSchema compilation failures in MCP tool discovery#21592
claygeo wants to merge 1 commit intoanomalyco:devfrom
claygeo:fix/mcp-outputschema-compat

Conversation

@claygeo
Copy link
Copy Markdown

@claygeo claygeo commented Apr 9, 2026

Issue for this PR

Closes #21591

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When an MCP server returns outputSchema in its tools/list response, the SDK's AjvJsonSchemaValidator.getValidator() calls ajv.compile(schema) with no try/catch. If the schema uses unsupported keywords, it throws and the entire listTools() call fails, making the server show "Failed to get tools."

opencode never uses outputSchema (only inputSchema in convertMcpTool()), so these compilation failures shouldn't block tool discovery.

The fix wraps AjvJsonSchemaValidator in a TolerantJsonSchemaValidator that catches getValidator() failures and returns a permissive fallback. Uses the SDK's jsonSchemaValidator extension point, no monkey-patching. One file changed, ~20 lines added.

How did you verify your code works?

  • Traced the code path: listTools()cacheToolMetadata()getValidator(outputSchema) — confirmed the wrapper intercepts the throw
  • typecheck passes
  • All existing tests pass
  • Working servers still use the real AJV validator (fallback only triggers on compilation errors)

Screenshots / recordings

Not a UI change.

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 github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

MCP servers with outputSchema in tools/list break tool discovery

1 participant