Skip to content

fix(mcp): tolerate invalid output schema patterns - #35679

Closed
fengjikui wants to merge 1 commit into
anomalyco:devfrom
fengjikui:mcp-schema-pattern
Closed

fengjikui wants to merge 1 commit into
anomalyco:devfrom
fengjikui:mcp-schema-pattern

Conversation

@fengjikui

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #35624

Type of change

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

What does this PR do?

Some MCP servers can return a tool outputSchema whose pattern is not valid in ECMAScript regex syntax. The MCP SDK validates tools/list, then precompiles output schema validators in Client.listTools(). When that precompile throws, OpenCode currently treats the whole tool discovery as failed.

OpenCode already has a tolerant tools/list retry path for output schema validation problems. This PR extends that same fallback to SDK errors caused by invalid output schema regex patterns, so the server can still connect and list tools while output-schema validation is skipped for that fallback response.

How did you verify your code works?

  • Added a regression test that reproduces the current failure with (?P<workflow_id>...) in a tool output schema pattern. Before the fix, McpCatalog.defs() returned undefined for the whole tool list.
  • bun test --timeout 30000 test/mcp/catalog.test.ts
  • bun test --timeout 30000 test/mcp
  • bunx prettier --check packages/opencode/src/mcp/catalog.ts packages/opencode/test/mcp/catalog.test.ts
  • bun run typecheck from packages/opencode
  • bun run lint from the repo root
  • pre-push bun turbo typecheck

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

I found a potential duplicate PR:

PR #35662: fix(mcp): tolerate invalid output schema patterns
#35662

This PR has the exact same title and appears to address the same issue as the current PR #35679. Both are fixing the handling of invalid MCP output schema patterns.

@fengjikui

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of my existing PR #35662, which already targets #35624 with the same fix path. Keeping #35662 as the canonical PR for review.

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: a tool with a non-ECMAScript JSON-Schema pattern fails the whole server connection (shown as "Authentication failed" for OAuth servers)

1 participant