Skip to content

fix(mcp): tolerate invalid tool output schemas#26530

Open
nicolascancino wants to merge 1 commit intoanomalyco:devfrom
nicolascancino:fix/mcp-output-schema-ref
Open

fix(mcp): tolerate invalid tool output schemas#26530
nicolascancino wants to merge 1 commit intoanomalyco:devfrom
nicolascancino:fix/mcp-output-schema-ref

Conversation

@nicolascancino
Copy link
Copy Markdown

Issue for this PR

Closes #26529

Type of change

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

What does this PR do?

Makes MCP tool loading resilient when a server returns a valid tools/list response whose outputSchema contains refs the SDK cannot resolve.

The normal client.listTools() path still runs first. If it fails with a schema reference error, OpenCode retries tools/list with a tolerant result schema that keeps inputSchema validation and treats outputSchema as opaque.

This fixes Google Stitch-style failures where the MCP transport connects but OpenCode marks the server as failed while validating tool output schemas.

How did you verify your code works?

cd packages/opencode
bun test test/mcp/lifecycle.test.ts --timeout 30000

Result:

20 pass
0 fail
51 expect() calls
Ran 20 tests across 1 file. [2.13s]

Screenshots / recordings

N/A — non-UI change.

Checklist

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

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 tools fail to load when outputSchema contains unresolved refs

1 participant