Skip to content

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

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

fix: handle outputSchema compilation errors in MCP tool discovery#21519
claygeo wants to merge 1 commit intoanomalyco:devfrom
claygeo:fix/mcp-outputschema-compat

Conversation

@claygeo
Copy link
Copy Markdown

@claygeo claygeo commented Apr 8, 2026

Summary

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.

  • 1 file changed: packages/opencode/src/mcp/index.ts
  • 27 insertions, 2 deletions

Test plan

  • 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)

Closes #21373

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

github-actions bot commented Apr 8, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 8, 2026
@github-actions github-actions bot closed this Apr 8, 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

1 participant