Skip to content

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, adds additionalProperties: 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.


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" becomes enum: ["x"] on Gemini; integer exclusiveMinimum: 0 becomes minimum: 1.
  • Description hints where it doesn’t: Dropped or unenforced constraints are appended to the field’s description so the model still sees them, and every drop is recorded as lossy in 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 null on return (breaking tools where null meant “clear”), or
  • Flags every optional nullable field as a false-positive warning.

mcp-schema-bridge distinguishes the two:

  • If default: null is declared, omitting and sending null mean the same thing → marked reversible, denormalize_args safely removes null.
  • If the field is optional and nullable without default: null, the distinction is genuinely lost → marked lossy (optional-nullable-ambiguous) so you know to add = None or handle null.

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) causes 400s on Gemini (schema at properties.point.items must be a boolean or an object) and items: false bugs if naively dropped.
  • $ref with siblings & percent-encoding: Gemini fails to percent-decode $ref fragments, so mcp-schema-bridge renames definitions to [A-Za-z0-9_.-] and inlines $ref siblings where required.
  • allOf conflicts: Merging allOf branches where one branch sets additionalProperties: false and another adds properties, or where two branches have conflicting patterns or minimums.
  • Recursive schemas: Targets like anthropic-strict forbid unbounded recursion. mcp-schema-bridge unrolls recursion up to max_ref_depth and 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.


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.