Why not write your own normalizer?
Every engineer who hits a 400 INVALID_ARGUMENT from Gemini or OpenAI strict mode has the same first thought:
“Can’t I just write a 50-line recursive function that strips
$schema, addsadditionalProperties: false, and moves on?”
For a single toy tool, yes. For arbitrary MCP servers (Pydantic, Zod, TypeScript, Go, Python) across Gemini, OpenAI, and Claude, a 50-line script breaks in seven predictable ways.
1. Silent failure is worse than a 400
Section titled “1. Silent failure is worse than a 400”Stripping keywords that cause a 400 is the easy part. The hard part is knowing which keywords a model API accepts without error and then silently ignores.
Our live probes against Gemini show that it accepts—and does not enforce—const, pattern, minLength, exclusiveMinimum, multipleOf, uniqueItems, and not. A naive normalizer leaves those keywords in place and assumes they work.
mcp-schema-bridge handles both:
- Semantic rewrites where the target enforces an equivalent:
const: "x"becomesenum: ["x"]on Gemini; integerexclusiveMinimum: 0becomesminimum: 1. - Description hints where it doesn’t: Dropped or unenforced constraints are appended to the field’s
descriptionso the model still sees them, and every drop is recorded aslossyin a machine-readable report.
2. Strict mode changes the shape of arguments
Section titled “2. Strict mode changes the shape of arguments”OpenAI strict: true (Structured Outputs) requires every property to be listed in required and sets additionalProperties: false. In our corpus of 164 real-world MCP tools, 157 fail raw OpenAI strict mode without normalization.
Making an optional field required means you have to allow null (e.g. type: ["integer", "null"]). When the model omits that optional parameter, it sends:
{ "query": "lamps", "limit": null }If you pass that straight to an MCP server expecting {"query": "lamps"}, Pydantic/Zod rejects null for limit?: number, or your server treats null as “clear this value”.
mcp-schema-bridge records every structural rewrite in a per-tool reverse map and provides denormalize_args() / denormalizeArgs() to strip injected nulls and unwrap wrapped roots before calling tools/call.
3. The T | None = None vs. ambiguous T | None trap
Section titled “3. The T | None = None vs. ambiguous T | None trap”Suppose a Pydantic tool declares email: str | None = None (optional and already nullable, with default: null). A naive strict-mode normalizer either:
- Blindly strips
nullon return (breaking tools wherenullmeant “clear”), or - Flags every optional nullable field as a false-positive warning.
mcp-schema-bridge distinguishes the two:
- If
default: nullis declared, omitting and sendingnullmean the same thing → markedreversible,denormalize_argssafely removesnull. - If the field is optional and nullable without
default: null, the distinction is genuinely lost → markedlossy(optional-nullable-ambiguous) so you know to add= Noneor handlenull.
4. JSON Schema composition and recursion edge cases
Section titled “4. JSON Schema composition and recursion edge cases”Real MCP servers emit schemas generated by Pydantic v2, Zod, zod-to-json-schema, and hand-written JSON Schema. A homegrown walker quickly hits:
- Draft-07 vs 2020-12: Draft-07 array
items: [A, B](tuples) causes400s on Gemini (schema at properties.point.items must be a boolean or an object) anditems: falsebugs if naively dropped. $refwith siblings & percent-encoding: Gemini fails to percent-decode$reffragments, somcp-schema-bridgerenames definitions to[A-Za-z0-9_.-]and inlines$refsiblings where required.allOfconflicts: MergingallOfbranches where one branch setsadditionalProperties: falseand another adds properties, or where two branches have conflictingpatterns orminimums.- Recursive schemas: Targets like
anthropic-strictforbid unbounded recursion.mcp-schema-bridgeunrolls recursion up tomax_ref_depthand detects unsatisfiable required-only cycles (fatal).
5. Per-request strict budgets & graceful fallback
Section titled “5. Per-request strict budgets & graceful fallback”OpenAI and Anthropic strict modes impose per-request limits across the entire toolset (maximum properties, nesting depth, enum string characters, optional/union parameter budgets).
If you normalize one tool at a time in isolation, your 12th tool can blow the request budget and fail the entire LLM call. normalize_tools() tracks budgets across the toolset and, with strict_fallback=True, demotes only the offending tool to its non-strict sibling (openai / anthropic) instead of crashing or dropping it.
6. Byte-identical determinism across Python & TypeScript
Section titled “6. Byte-identical determinism across Python & TypeScript”Both the Python and TypeScript packages implement the exact same specification and are differential-fuzzed in CI. They produce byte-identical normalized schemas, reports, key order, and SHA-256 fingerprints.
Because NormalizedTool is deterministic and serializable (to_dict() / from_dict()), you can normalize once in a Python backend, cache it, and denormalizeArgs in a TypeScript worker—with ReverseMismatchError protecting you if the schema or rules_version ever drifts.
7. Live-verified, versioned provider rules
Section titled “7. Live-verified, versioned provider rules”Provider APIs change their undocumented JSON Schema limits without notice. Instead of hardcoding if target == "gemini" branches inside application code, mcp-schema-bridge drives every transformation from declarative rule files (rules/*.json) backed by recorded API responses, live probes, and official documentation citations—stamped with rules_version.
How the pipeline works
Section titled “How the pipeline works”
flowchart TD
A["MCP tools/list"] --> B["1. Parse & canonicalize (draft-07 to 2020-12, $ref, keys)"]
B --> C["2. Structural rewrites (allOf merge, oneOf to anyOf, const to enum, optional to nullable)"]
C --> D["3. Target keyword filter & budget check (strip/hint, strict fallback)"]
D --> E["4. Emit NormalizedTool + Report + ReverseMap"]
E --> F["to_sdk_payload() -> Model API (Gemini / OpenAI / Claude)"]
F -->|"Tool call arguments"| G["denormalize_args(tool, args)"]
G --> H["MCP tools/call"]
Ready to try it? Head to the Quickstart or paste your own schema into the Playground.