Conversation
The primitive JSON Schema -> zod mapping dropped enums, nested item shapes, nested required fields and property descriptions, so Claude saw e.g. todowrite as an array of anything. Convert the whole schema with z.fromJSONSchema instead. Each converted shape is dry-run through a throwaway SDK server first, since one shape the SDK cannot serialise fails tools/list for every tool; failures fall back to the old mapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
jsonSchemaToZodShapemaps only top-level primitive types, which loses most of each OpenCode tool's schema. Enums, nested object/array item shapes, nestedrequiredfields and property descriptions are all dropped. For example, Claude seestodowriteastodos: array of anything, and it has to guess thestatusvalues and item fields that native OpenCode models get from the schema. That leads to avoidable failed tool calls.Fix: convert each tool's full JSON Schema with
z.fromJSONSchema(zod ≥ 4.2). The SDK serialises tool shapes with its own zod, and a single shape it can't handle breakstools/listfor every tool (see #12). So each converted shape is first listed through a throwawaycreateSdkMcpServer, and it's used only if that succeeds. If conversion or the probe fails, the tool falls back to the existing primitive mapping. Results are cached per schema string, so the probe runs once per distinct tool schema per process.Caveats:
tools/listhandler through_requestHandlers, which is not public API. If it moves, the probe finds no handler and every tool falls back to today's behaviour, so nothing breaks.Test:
test/tool-schema-fidelity-regression.tssends atodowrite-shaped schema and a schema with an unresolvable$refthrough the proxy, then lists the bridge.todowritekeeps its enum, item shape and nestedrequired, which fails onmain. The broken schema falls back and both tools are still listed. It passes with the locked SDK 0.3.224 and with SDK 0.3.260 plus zod 4.5.4.bun test/smoke.tsandtsc --noEmitpass.This is independent of #20. With both merged, the fallback path also stops emitting
z.record.