Skip to content

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.

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)
import json
from 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)
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> });
}
  • Always call denormalize_args / denormalizeArgs: Strict mode makes optional fields required and nullable, so the model sends null for “not provided”. Many MCP servers treat null differently 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 (openai or anthropic) instead of disappearing.
  • Use to_sdk_payload for 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() and NormalizedTool.from_dict(). Re-normalize only on notifications/tools/list_changed or after upgrading.

For caching, ReverseMismatchError, reserved_budget, and opt-in repairs, see For framework authors and the API & CLI reference.