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 14:35:47 +08:00
committed by Xubin Ren
parent b6cf7020ac
commit e87bb0a82d
4 changed files with 135 additions and 94 deletions
+3 -1
View File
@@ -146,7 +146,9 @@ class Tool(ABC):
def _validate(self, val: Any, schema: dict[str, Any], path: str) -> list[str]:
raw_type = schema.get("type")
nullable = isinstance(raw_type, list) and "null" in raw_type
nullable = (isinstance(raw_type, list) and "null" in raw_type) or schema.get(
"nullable", False
)
t, label = self._resolve_type(raw_type), path or "parameter"
if nullable and val is None:
return []