@@ -78,6 +78,34 @@ def test_handles_empty_input_schema(self):
7878 assert result .name == "simple_tool"
7979 assert result .args_schema is not None
8080
81+ def test_optional_fields_not_required_in_args_schema (self ):
82+ """Fields absent from 'required' must be optional in the generated Pydantic model."""
83+ tool = MCPTool (
84+ name = "get_supplier_bid" ,
85+ server_name = "ariba" ,
86+ description = "Gets all supplier bids for the specified event" ,
87+ input_schema = {
88+ "type" : "object" ,
89+ "required" : ["eventid" ],
90+ "properties" : {
91+ "eventid" : {"description" : "Unique identifier of the event" },
92+ "showdeclinedreason" : {"description" : "Show supplier decline reason" },
93+ "datafetchmode" : {"description" : "Level of detail for the response" },
94+ },
95+ },
96+ url = "https://example.com/mcp" ,
97+ )
98+
99+ result = mcp_tool_to_langchain (tool , AsyncMock (return_value = "result" ), lambda : "token" )
100+
101+ from pydantic import BaseModel
102+
103+ assert result .args_schema is not None and isinstance (result .args_schema , type ) and issubclass (result .args_schema , BaseModel )
104+ fields = result .args_schema .model_fields
105+ assert fields ["eventid" ].is_required (), "eventid should be required"
106+ assert not fields ["showdeclinedreason" ].is_required (), "showdeclinedreason should be optional"
107+ assert not fields ["datafetchmode" ].is_required (), "datafetchmode should be optional"
108+
81109 def test_handles_input_schema_without_properties (self ):
82110 """Handle MCPTool with input schema but no properties."""
83111 tool = MCPTool (
0 commit comments