fix(mcp): preserve schema semantics during normalization

Only normalize nullable MCP tool schemas for OpenAI-compatible providers so optional params still work without collapsing unrelated unions. Also teach local validation to honor nullable flags and add regression coverage for nullable and non-nullable schemas.

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-03-21 06:21:26 +00:00
committed by Xubin Ren
parent b6cf7020ac
commit e87bb0a82d
4 changed files with 135 additions and 94 deletions

View File

@@ -455,6 +455,18 @@ def test_validate_nullable_param_accepts_none() -> None:
assert errors == []
def test_validate_nullable_flag_accepts_none() -> None:
"""OpenAI-normalized nullable params should still accept None locally."""
tool = CastTestTool(
{
"type": "object",
"properties": {"name": {"type": "string", "nullable": True}},
}
)
errors = tool.validate_params({"name": None})
assert errors == []
def test_cast_nullable_param_no_crash() -> None:
"""cast_params should not crash on nullable type (the original bug)."""
tool = CastTestTool(