Skip to content

fix(desktop): accept jsonSchema() tool params in native capability offers - #4592

Open
liuxiaocs7 wants to merge 1 commit into
apache:mainfrom
liuxiaocs7:fix/desktop-mcp-native-capability-jsonschema
Open

fix(desktop): accept jsonSchema() tool params in native capability offers#4592
liuxiaocs7 wants to merge 1 commit into
apache:mainfrom
liuxiaocs7:fix/desktop-mcp-native-capability-jsonschema

Conversation

@liuxiaocs7

Copy link
Copy Markdown
Member

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 logs MCP startup failed: ... Desktop native capability tool has an invalid schema and MCP capability refresh failed on every change, and no MCP tool is offered to sessions.

buildMcpTools() sets each MCP tool's parameters to jsonSchema(descriptor.inputSchema) — an AI SDK Schema, not a Zod type. The Desktop native-capability provider offered and validated tools through requireZodSchema (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 with buildMcpTools and accepts jsonSchema(), so the two halves of the boundary disagreed on the allowed parameters shape; this aligns the offering side.

  • toolInputSchema now reads the JSON Schema directly from an AI SDK Schema when parameters is not Zod, cloning it before deleting $schema/freezing so the MCP descriptor's shared inputSchema is never mutated.
  • Call-time validation (invokeNativeTool) goes through a new parseToolArguments helper that mirrors the runtime's validateDeclaredToolArgs precedence: Zod parseAsync, AI SDK validate, 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.
  • Offers are built synchronously and frozen, so only synchronously-available schemas are supported at offer time (all current tools qualify: Zod, or MCP's plain-object 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.js15/15 pass, including the new test offers and dispatches MCP tools whose parameters are JSON Schema, not Zod, which runs real buildMcpTools() output through the provider and fails without this change (it throws the "invalid schema" error).
  • biome format . — 1867 files, no fixes needed; biome lint on the changed files — clean.

Not run: the full Electron npm run dev end-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 via decodeClientCapabilityReplaceInput.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

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 Code trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…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
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: MCP tools fail to load — native-capability offer rejects jsonSchema() parameters

1 participant