Repository navigation
fix(mcp): normalize schemars numeric formats in tool input schemas - #264
Conversation
Rust MCP servers built with schemars emit non-standard numeric formats (uint32, int8, uint, double, ...) that some providers reject in tool definitions. Drop those formats at every nested subschema position and keep exact integer-width ranges as minimum/maximum. Applied to the model-facing schema on desktop and in the CLI; raw schemas stay the drift and grant identity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
very-hermes-bot
left a comment
There was a problem hiding this comment.
Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.
Hermes Review BotConfidence: 5 Engine: SummaryNormalizes non-standard numeric schema formats generated by Rust's Confidence Score: 5/5Fully traced and verified end-to-end: verified iterative worklist traversal against deep and cyclic schemas, inspected keyword classification for draft-07 and draft 2020-12 structures, verified integer boundary math, confirmed raw inventory preservation at call sites in desktop and CLI, and reviewed Ajv boundary test coverage. 📁 Important Files Changed
FindingsNo findings. 📊 Sequence DiagramUnchanged or not applicable for this change. Machine-Readable Findings[]
|
There was a problem hiding this comment.
Important
Draft-07 schema-valued dependencies entries bypass normalization, leaving provider-hostile numeric formats in some valid tool schemas.
Reviewed changes This review covers the initial implementation of MCP numeric schema normalization across the desktop and CLI model-facing MCP tool paths.
- Schema normalization. Adds a pure walker that removes mapped non-standard numeric formats and preserves representable integer bounds.
- Desktop and CLI integration. Normalizes schemas only for model consumption while retaining raw schemas for drift and identity checks.
- Tests and documentation. Adds Ajv compatibility and boundary coverage plus CLI parity assertions, and records the change in the MCP test script, plan docs, and project memory.
GPT Luna | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes Incremental review of c8b3114b — the delta since the prior pullfrog review at 401beb75. It fixes the previously flagged gap where Draft-07 schema-valued dependencies bypassed normalization.
- Normalized Draft-07 schema-valued
dependenciesentries —"dependencies"now joinsSUBSCHEMA_MAP_KEYWORDS, so numeric formats inside dependency schemas are stripped with their width bounds, while property-name dependency lists pass through unchanged. This closes the prior review finding. - Added a regression test with a real oracle — strict Ajv rejects the un-normalized form (
unknown format "uint8"), and the normalized form enforces theretriesrange at both boundaries; the raw schema's immutability and the property-list form are pinned too. - Registered
mcp-tool-schema.test.tsin thecore-gitCI lane, fixing two pre-existing alphabetical order violations in the same file.
Verified locally: focused schema tests 7/7, npm run test:mcp 118/118, npm run test:ci-policy 46/46, and the core-git lane validates with the new file registered. Also re-checked the untouched model-facing paths: the four Type.Unsafe call sites are covered (desktop and CLI normalize; the subagent read/mutation sites receive schemas already projected through the format-stripping structural allowlist), so no other path leaks schemars formats to the model.
GLM Flash | 𝕏
|
Pullfrog stalled The agent stopped emitting events for 120s and was killed by the activity-timeout watchdog. The model produced no output at all before the stall — the request was sent but nothing came back. This is usually transient; re-running often succeeds. Recent agent stderr
|
|
Pullfrog stalled The agent stopped emitting events for 125s and was killed by the activity-timeout watchdog. The model produced no output at all before the stall — the request was sent but nothing came back. This is usually transient; re-running often succeeds. Recent agent stderr
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Important
A wide, valid-size remote schema can make the new worklist allocate millions of queue entries synchronously in Electron's main process.
Reviewed changes This incremental review covers changes since c8b3114b: the recursive 64-level cutoff was replaced with iterative normalization, and a deep-schema regression test was added.
- Removed the depth cutoff. Replaced recursive traversal with a
WeakMap-backed worklist and added coverage for 2,000 nested schema levels.
GPT Luna | 𝕏
| if (existing) return existing; | ||
| const target: Record<string, unknown> = {}; | ||
| copies.set(source, target); | ||
| pending.push({ source, target }); |
There was a problem hiding this comment.
MCP servers control these schemas, and the desktop's 8 MiB response limit still permits millions of tiny subschemas. This worklist retains a { source, target } record for each child before draining the queue, which can substantially amplify memory use and synchronously stall or crash the main process.
Technical details
# Bound work queued from remote schemas
## Affected sites
- `main/services/mcp-tool-schema.ts:102` — each discovered schema object adds a retained queue record.
- `main/services/mcp-tool-schema.ts:115-116` — array-valued keywords enqueue all children before the worklist drains.
- `main/services/mcp.ts:365-376` — the desktop applies this normalizer to server-provided tool schemas after transport-level byte limiting.
## Required outcome
- Enforce a schema-node/work-queue budget and reject oversized schemas before model registration; never forward a partially normalized schema.# Conflicts: # docs/plans/README.md

Summary
Rust MCP servers built with
schemarsput non-standard numeric formats (uint,uint8..uint128,int,int8..int128,float,double) on tool input schemas, and some providers reject tool definitions that carry them. This PR adds a pure normalizer that removes those formats at every nested position and keeps the integer width asminimum/maximumwhere the bound is an exact JSON number.Source: pi-mcp-adapter #651.
What changed
main/services/mcp-tool-schema.ts): newnormalizeMcpToolInputSchema. It recurses throughproperties,patternProperties,$defs,definitions,dependentSchemas,items(object or tuple),prefixItems,allOf/anyOf/oneOf,additionalProperties,not,if/then/else, and similar keywords.minimum: 0. Float formats are dropped without adding bounds.integer/number. Astringfield with a numeric format just loses the format.date-timeanduriare left alone, and the input is never mutated.main/services/mcp.ts):McpManager.agentContextFornormalizes the schema passed toType.Unsafe. That one path covers chats, Bots and scheduled tasks.packages/cli/src/mcp.ts):createCliMcpPool().agentToolsnormalizes the same way. The per-call drift fence still compares against the raw inventory.formatthrough their structural allowlist (projectStructuralSchema). Normalizing there would change schema hashes and invalidate existing grants.peer-response.tsvalidates the Aiden Remote protocol, not tool schemas.docs/plans/README.md, a.memory/note, and a papercut about the CLI type-check needing a build first.Tests
main/services/mcp-tool-schema.test.ts(registered intest:mcp) uses realistic schemars 0.8 (draft-07,definitions, tupleitems) and 1.x (2020-12,$defs,prefixItems) fixtures.uint32field. The test checks the model-facing schema and that the raw inventory still carries the format.npm run test:mcp: 117 passnpm run type-check(root): cleannpx eslinton touched files: cleanpackages/cli:npm run build && npm run type-check && npm test, all passFollow-ups
$defs/$ref, so subagents see a flattened shape for schemars schemas that use references. Widening that projection needs a grant/schema-hash migration.🤖 Generated with Claude Code