Normalize in your agent loop
If you build an MCP client or AI agent, arbitrary third-party MCP servers will send JSON Schemas that trigger 400 errors or silent constraint drops. mcp-schema-bridge sits cleanly in your tool loop.
Working examples (verified live with OpenAI): examples/client-builder/agent.py (Python) and examples/client-builder-ts/agent.ts (TypeScript). Raw MCP schemas failed with 400 … 'additionalProperties' is required to be supplied and to be false; with the bridge, the calls succeeded.
The tool loop
Section titled “The tool loop”
sequenceDiagram
participant MCP as MCP Server
participant Bridge as mcp-schema-bridge
participant Model as Model API (Gemini / OpenAI / Claude)
MCP->>Bridge: tools/list
Bridge->>Bridge: normalize_tools(tools, target)
Bridge->>Model: to_sdk_payload(bridged, api)
Model-->>Bridge: function_call(name, model_args)
Bridge->>Bridge: denormalize_args(tool, model_args)
Bridge->>MCP: tools/call(name, server_args)
Python
Section titled “Python”import jsonfrom mcp_schema_bridge import NormalizeOptions, denormalize_args, normalize_tools, to_sdk_payload
bridged = normalize_tools( (await mcp.list_tools()).tools, "openai-strict", NormalizeOptions(strict_fallback=True),)log.info(bridged.summary()) # human-readable diff per tool
response = openai.responses.create( model=..., input=..., tools=to_sdk_payload(bridged, "openai-responses"),)
for call in (o for o in response.output if o.type == "function_call"): tool = bridged.get(call.name) args = denormalize_args(tool, json.loads(call.arguments)).args # strips injected nulls, unwraps, etc. result = await mcp.call_tool(call.name, args)TypeScript
Section titled “TypeScript”import { denormalizeArgs, normalizeTools, toSdkPayload } from "mcp-schema-bridge";
const bridged = normalizeTools((await mcp.listTools()).tools, "openai-strict", { strictFallback: true,});
const response = await openai.responses.create({ model, input, tools: toSdkPayload(bridged, "openai-responses"),});
for (const item of response.output) { if (item.type !== "function_call") continue; const tool = bridged.get(item.name)!; const args = denormalizeArgs(tool, JSON.parse(item.arguments)).args; await mcp.callTool({ name: item.name, arguments: args as Record<string, unknown> });}Best practices
Section titled “Best practices”- Always call
denormalize_args/denormalizeArgs: Strict mode makes optional fields required and nullable, so the model sendsnullfor “not provided”. Many MCP servers treatnulldifferently from a missing key. - Enable
strict_fallback(strictFallback): A tool that cannot be made strict (for example, one with a free-form map) is demoted to the non-strict sibling (openaioranthropic) instead of disappearing. - Use
to_sdk_payloadfor other providers: Pass"genai"for Gemini (@google/genai/google-genai) or"anthropic-messages"for Claude. - Cache per server and target: Results serialize via
to_dict()/toJSON()andNormalizedTool.from_dict(). Re-normalize only onnotifications/tools/list_changedor after upgrading.
For caching, ReverseMismatchError, reserved_budget, and opt-in repairs, see For framework authors and the API & CLI reference.