Skip to content

fix(tools): strip non-standard schema formats from tool schemas - #159

Closed
hogan-yuan wants to merge 3 commits into
mainfrom
fix/schema-uint-format
Closed

hogan-yuan wants to merge 3 commits into
mainfrom
fix/schema-uint-format

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

Problem

schemars derives JSON Schema format values from Rust numeric types — usize → uint, u64 → uint64, i64 → int64, f64 → double, etc. None of these are in the JSON Schema 2020-12 format-annotation vocabulary, so strict MCP clients log unknown format "uint" ignored on every tool call.

Fix

Recursively drop every format annotation whose value is not a standard JSON Schema format (STANDARD_JSON_SCHEMA_FORMATS), applied to both the input schemas and the output schemas served over the resource path. Standard string formats (date-time, uri, …) are preserved.

Tests

Added an assertion that the output schemas served via the resource path are format-clean (no non-standard format survives).

cargo test, clippy, and +nightly fmt clean. Only touches src/tools/mod.rs.

schemars derives non-standard numeric `format` values from Rust integer/
float types (`usize` -> "uint", `u64` -> "uint64", `i64` -> "int64",
`f64` -> "double", ...). JSON Schema defines no numeric formats, so strict
MCP clients log `unknown format "uint" ignored` on every tool call for
fields like `page`, `count`, `total`.

Recursively drop these numeric `format` annotations from every tool's
input and output schema in the shared list_tools() post-processing pass
(alongside the existing null-type stripping). `type` is preserved, so the
value is still constrained to an integer/number; only the advisory,
unrecognized keyword is removed. String formats (date-time, uri, ...) are
left untouched. Add a regression test asserting no tool schema exposes a
non-standard numeric format.

Resolves longbridge/developers#1264
Generalize the format sanitizer to a whitelist: keep only the JSON Schema
2020-12 standard formats (date-time, uri, uuid, …) and drop every other
`format` value, rather than blacklisting the known schemars numeric ones.
This future-proofs against any other non-standard format schemars might
emit (e.g. `char`). Verified the current tool set: after stripping, zero
`format` values remain and all schema keywords are standard.
…path

list_tools() nulls output_schema (a jq projection can return any shape),
so the previous regression test's output-schema branch never ran. The
output-schema contract is actually served as MCP resources from
all_tools_full_cached(); assert that path is free of non-standard formats
too, split from the input-schema check for a precise failure message.
@hogan-yuan

Copy link
Copy Markdown
Member Author

Superseded — the schema-format fix already landed via #156 (on main, unreleased). This branch is also stale (based on pre-#156 main), so its diff reverts unrelated changes. Nothing to merge.

@hogan-yuan hogan-yuan closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant