Skip to content

Commit 256698f

Browse files
committed
add support for union types in mcp client
Signed-off-by: Patrick Riel <[email protected]>
1 parent c5524a5 commit 256698f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/aiq/tool/mcp/mcp_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def _generate_field(field_name: str, field_properties: dict[str, Any]) -> tuple:
6868
else:
6969
item_type = _type_map.get(item_properties.get("type", "string"), Any)
7070
field_type = list[item_type]
71+
elif isinstance(json_type, list):
72+
nullable = "null" in json_type
73+
main_type = next((t for t in json_type if t != "null"), "string")
74+
field_type = _type_map.get(main_type, Any)
75+
if nullable:
76+
field_type = field_type | None
77+
return field_type, Field(
78+
default=field_properties.get("default", None if nullable else ...),
79+
description=field_properties.get("description", "")
80+
)
7181
else:
7282
field_type = _type_map.get(json_type, Any)
7383

0 commit comments

Comments
 (0)