Skip to content

fix(mcp): fall back on circular tool schemas#16910

Open
MaheshBhushan wants to merge 2 commits intoanomalyco:devfrom
MaheshBhushan:fix/16899-mcp-circular-schema-fallback
Open

fix(mcp): fall back on circular tool schemas#16910
MaheshBhushan wants to merge 2 commits intoanomalyco:devfrom
MaheshBhushan:fix/16899-mcp-circular-schema-fallback

Conversation

@MaheshBhushan
Copy link

Issue for this PR

Closes #16899

Type of change

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

What does this PR do?

This prevents session crashes when an MCP tool exposes input JSON Schema with circular $defs references (for example nested _And references).

Before this change, we passed those schemas directly into jsonSchema(...), and downstream schema resolution could recurse until failure (RecursionError: maximum recursion depth exceeded).

Now we detect circular $defs reference graphs and, for those tools only, fall back to a permissive object input schema:

  • { type: "object", additionalProperties: true }

This keeps the tool available and avoids hard crashing the session processor.

How did you verify your code works?

  • Added circular-ref detection over $defs reference graph (#/$defs/...).
  • Verified normal non-circular schemas still use the original transformed schema path.
  • Verified circular schemas use fallback path and emit a warning log.

Screenshots / recordings

Not included (core logic fix; no UI changes).

Checklist

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

@github-actions
Copy link
Contributor

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

The searches found PR #16910 (the current PR) and a couple of related schema-handling PRs, but those are from 2024 and address different issues (Gemini schema compatibility and $ref expansion). They don't appear to be addressing the same circular reference detection issue for MCP tools.

No duplicate PRs found

@MaheshBhushan
Copy link
Author

quick note on the failing ypecheck check: the reported errors are in packages/desktop/src/index.tsx and packages/desktop/src/updater.ts, while this PR only changes packages/opencode/src/session/prompt.ts.

so this appears unrelated to the scoped MCP schema change in this PR (likely baseline/dev-branch issue). happy to rebase/re-run once upstream desktop typecheck is green again.

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 tool schema resolution: RecursionError on circular schema references

1 participant