DEV Community

Why Your 50-Line MCP Schema Normalizer Breaks (and Introducing mcp-schema-bridge)

If you've built an MCP client or agent that talks to multiple LLM providers, you've probably seen an error like this:

400 INVALID_ARGUMENT: schema at properties.point.items must be a boolean or an object

Your first instinct is to write a 50-line recursive function that strips $schema, adds additionalProperties: false, and moves on. For a single toy tool, that works. For arbitrary MCP servers (Pydantic, Zod, Go, TypeScript) across Gemini, OpenAI, and Claude, a homegrown walker breaks in predictable ways - and the worst failures don't even throw a 400.

Today I'm sharing mcp-schema-bridge (v0.1.0, Apache-2.0): a schema normalizer, compatibility reporter, and argument round-tripper for Python and TypeScript.

Try it in your browser (no install, no API key): mcp-schema-bridge Playground

The Three Failure Modes of Multi-Provider MCP Tools

1. Silent failure is worse than a 400

Stripping keywords that cause a 400 is the easy part. The harder problem 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 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

OpenAI strict: true (Structured Outputs) requires every property in required and sets additionalProperties: false. In our corpus of 164 real-world MCP tools across 10 captured servers, 157 fail raw OpenAI strict mode without normalization.

Making an optional field required means allowing null (type: ["integer", "null"]). When the model omits that optional parameter, it sends:

{ "query": "lamps", "limit": null }

Passing that straight to an MCP server expecting {"query": "lamps"} can fail Pydantic/Zod validation or be interpreted as "clear this value".

mcp-schema-bridge records every structural rewrite in a per-tool reverse map and provides denormalize_args() (or denormalizeArgs() in TS) to strip injected nulls and unwrap wrapped roots before calling tools/call.

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).

  • If default: null is declared, omitting and sending null mean the same thing → marked reversible, and 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 about it.

Quickstart (Python & TypeScript)

Install:

pip install mcp-schema-bridge # Python, zero runtime dependencies
pip install "mcp-schema-bridge[sdks]" # + adapters for google-genai / openai / anthropic
npm install mcp-schema-bridge # TypeScript / JavaScript (Node >= 22)

Normalize tools, pass them to your SDK, and map arguments back:

from mcp_schema_bridge import denormalize_args, normalize_tools

tools = [  # as returned by an MCP server's tools/list
    {
        "name": "search",
        "description": "Search the catalogue",
        "inputSchema": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "minLength": 1},
                "limit": {"type": "integer", "minimum": 1, "maximum": 50},
            },
            "required": ["query"],
        },
    }
]

result = normalize_tools(tools, "openai-strict")
search = result.tools[0]
print(search.schema["required"]) # ['query', 'limit']
print(search.schema["properties"]["limit"]["type"]) # ['integer', 'null']

# Inspect every change: info | reversible | lossy | fatal
for entry in result.report.entries:
    print(entry.severity, entry.rule, entry.source_path, entry.keyword)

# Restore the original argument shape before calling the MCP server:
args = denormalize_args(search, {"query": "lamps", "limit": None}).args
assert args == {"query": "lamps"}

Need provider-ready payloads? Use to_sdk_payload() with the [sdks] extra:

from mcp_schema_bridge import normalize_tools, to_sdk_payload

gemini_tools = to_sdk_payload(normalize_tools(tools, "gemini-json"), "genai")
openai_tools = to_sdk_payload(normalize_tools(tools, "openai-strict"), "openai-responses")
claude_tools = to_sdk_payload(normalize_tools(tools, "anthropic-strict"), "anthropic-messages")

Also for MCP Server Builders and Users (CLI + Proxy)

You don't have to be building an agent framework to use it:

# Server builders: check compatibility in CI (exits 1 if anything is lossy)
mcp-schema-bridge check tools.json --fail-on lossy

# Check a live stdio MCP server across targets
mcp-schema-bridge check --target gemini-json --target openai-strict \
  --stdio -- npx -y @modelcontextprotocol/server-filesystem /tmp

# Users: put a proxy in front of any MCP server whose tools break your client
mcp-schema-bridge proxy --target gemini-json -- npx -y some-mcp-server

Under the Hood: Evidence-Backed Rules & Determinism

  • Versioned rules (rules/*.json): Every provider rule is backed by a live probe, recorded API response, or documentation citation with a verification date - not guesswork.
  • Per-request strict budgets: normalize_tools() tracks toolset-wide budgets for OpenAI and Anthropic strict modes and supports strict_fallback=True to demote only the offending tool instead of failing the whole call.
  • Byte-identical Python & TypeScript: Both packages are differential-fuzzed in CI and produce byte-identical schemas, reports, key ordering, and SHA-256 fingerprints (~20-25 ms per target for 100 tools on Apple Silicon).

Try It Out

If you run into a schema edge case or want another target supported, open an issue or PR - contributions are welcome!

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.