fix(desktop): accept jsonSchema() tool params in native capability offers - #4592
Open
liuxiaocs7 wants to merge 1 commit into
Open
fix(desktop): accept jsonSchema() tool params in native capability offers#4592liuxiaocs7 wants to merge 1 commit into
liuxiaocs7 wants to merge 1 commit into
Conversation
…fers MCP tools built by buildMcpTools() carry AI SDK jsonSchema() parameters, not Zod schemas. The Desktop native-capability provider offered and validated tools through requireZodSchema (instanceof z.ZodType), so it threw "Desktop native capability tool has an invalid schema" on the first MCP tool — no MCP tool from any configured server was ever offered to sessions on Desktop (MCP added in the TUI was unusable in the Desktop app). toolInputSchema now reads the JSON Schema directly from an AI SDK Schema (cloning it before deleting $schema / freezing, so the MCP descriptor's shared inputSchema is never mutated), and call-time validation goes through a new parseToolArguments helper that mirrors the runtime's validateDeclaredToolArgs precedence: Zod parse, AI SDK validate, or pass-through for JSON-schema-only MCP tools. Zod-based tools are unchanged. Adds a test that runs real buildMcpTools() output through the provider, covering both the offer and the call paths; it fails without the fix. Fixes apache#4591 Generated-by: Claude Code
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.
Summary
MCP tools configured on the Desktop app (including servers added in the TUI, which share the workspace's
mcp.json) never load: the Runtime Host logsMCP startup failed: ... Desktop native capability tool has an invalid schemaandMCP capability refresh failedon every change, and no MCP tool is offered to sessions.buildMcpTools()sets each MCP tool'sparameterstojsonSchema(descriptor.inputSchema)— an AI SDKSchema, not a Zod type. The Desktop native-capability provider offered and validated tools throughrequireZodSchema(tool.parameters instanceof z.ZodType), so it threw on the first MCP tool. The protocol's receiving side (client-capability-coordinator) already rebuilds the same tools withbuildMcpToolsand acceptsjsonSchema(), so the two halves of the boundary disagreed on the allowedparametersshape; this aligns the offering side.toolInputSchemanow reads the JSON Schema directly from an AI SDKSchemawhenparametersis not Zod, cloning it before deleting$schema/freezing so the MCP descriptor's sharedinputSchemais never mutated.invokeNativeTool) goes through a newparseToolArgumentshelper that mirrors the runtime'svalidateDeclaredToolArgsprecedence: ZodparseAsync, AI SDKvalidate, or pass-through for JSON-schema-only MCP tools (which carry no client-side validator). Zod-based tools (browser, computer-use, settings, rive) are unchanged.jsonSchema()); an async/thenable schema throws a clear error rather than failing silently.Fixes #4591
Verification
npm --workspace @maka/desktop run build:main(tsc) — passes, no type errors.node --test apps/desktop/dist/main/__tests__/runtime-host-native-capabilities.test.js— 15/15 pass, including the new testoffers and dispatches MCP tools whose parameters are JSON Schema, not Zod, which runs realbuildMcpTools()output through the provider and fails without this change (it throws the "invalid schema" error).biome format .— 1867 files, no fixes needed;biome linton the changed files — clean.Not run: the full Electron
npm run devend-to-end launch (headless environment). The added test exercises the same offer + call code paths that fail in the reported log, including protocol encoding of the offer viadecodeClientCapabilityReplaceInput.AI use
Select exactly one:
Tool(s) and scope: Claude Code diagnosed the root cause, implemented the fix and the added test, and drafted this PR. The authoring commit carries a
Generated-by: Claude Codetrailer.Checklist
Does this PR entail a change in behavior?