@@ -185,6 +185,52 @@ def test_optional_non_string_field_is_nullable(self):
185185 assert int in field .annotation .__args__
186186 assert type (None ) in field .annotation .__args__
187187
188+ def test_array_type_integer_null_maps_to_int (self ):
189+ lc_tool = mcp_tool_to_langchain (
190+ self ._tool_with_types ({"limit" : {"type" : ["integer" , "null" ]}}, required = ["limit" ]),
191+ AsyncMock (),
192+ lambda : "token" ,
193+ )
194+ field = _schema_fields (lc_tool )["limit" ]
195+ import types as _types
196+ assert isinstance (field .annotation , _types .UnionType )
197+ assert int in field .annotation .__args__
198+ assert type (None ) in field .annotation .__args__
199+
200+ def test_array_type_number_null_maps_to_float (self ):
201+ lc_tool = mcp_tool_to_langchain (
202+ self ._tool_with_types ({"ratio" : {"type" : ["number" , "null" ]}}, required = ["ratio" ]),
203+ AsyncMock (),
204+ lambda : "token" ,
205+ )
206+ field = _schema_fields (lc_tool )["ratio" ]
207+ import types as _types
208+ assert isinstance (field .annotation , _types .UnionType )
209+ assert float in field .annotation .__args__
210+ assert type (None ) in field .annotation .__args__
211+
212+ def test_array_type_multiple_scalars_uses_first_non_null (self ):
213+ # e.g. {"type": ["number", "string", "null"]} — pick "number"
214+ lc_tool = mcp_tool_to_langchain (
215+ self ._tool_with_types ({"val" : {"type" : ["number" , "string" , "null" ]}}, required = ["val" ]),
216+ AsyncMock (),
217+ lambda : "token" ,
218+ )
219+ field = _schema_fields (lc_tool )["val" ]
220+ import types as _types
221+ assert isinstance (field .annotation , _types .UnionType )
222+ assert float in field .annotation .__args__
223+ assert type (None ) in field .annotation .__args__
224+
225+ def test_array_type_without_null_is_not_nullable (self ):
226+ lc_tool = mcp_tool_to_langchain (
227+ self ._tool_with_types ({"count" : {"type" : ["integer" ]}}, required = ["count" ]),
228+ AsyncMock (),
229+ lambda : "token" ,
230+ )
231+ field = _schema_fields (lc_tool )["count" ]
232+ assert field .annotation is int
233+
188234
189235class TestMcpToolToLangchainInvocation :
190236 """End-to-end invocation tests: verify what actually reaches call_tool."""
0 commit comments