fix(mcp): fall back on circular tool schemas#16910
fix(mcp): fall back on circular tool schemas#16910MaheshBhushan wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
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 |
|
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. |
Issue for this PR
Closes #16899
Type of change
What does this PR do?
This prevents session crashes when an MCP tool exposes input JSON Schema with circular
$defsreferences (for example nested_Andreferences).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
$defsreference 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?
$defsreference graph (#/$defs/...).Screenshots / recordings
Not included (core logic fix; no UI changes).
Checklist