From c92b56fbf44a731c9b88b2aa8bab364503f7382d Mon Sep 17 00:00:00 2001 From: pedro-inf-custodio Date: Sat, 18 Oct 2025 13:33:22 +0100 Subject: [PATCH 1/3] fix: ensure inputSchema has properties for object type tools --- langchain_mcp_adapters/tools.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/langchain_mcp_adapters/tools.py b/langchain_mcp_adapters/tools.py index a8bf0eb..fb90a9e 100644 --- a/langchain_mcp_adapters/tools.py +++ b/langchain_mcp_adapters/tools.py @@ -251,6 +251,8 @@ async def call_tool( base = tool.annotations.model_dump() if tool.annotations is not None else {} meta = {"_meta": meta} if meta is not None else {} metadata = {**base, **meta} or None + if tool.inputSchema.get("type") == "object": + tool.inputSchema.setdefault("properties", {}) return StructuredTool( name=tool.name, From 74a0ba6c6141f3c1e3857bedc04da98a1b3c50f5 Mon Sep 17 00:00:00 2001 From: pedro-inf-custodio Date: Sat, 18 Oct 2025 18:36:48 +0100 Subject: [PATCH 2/3] test: add conversion test for MCP tool with empty input schema --- tests/test_tools.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_tools.py b/tests/test_tools.py index 279da86..562f0d2 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -150,6 +150,44 @@ async def test_convert_mcp_tool_to_langchain_tool(): ) +async def test_convert_mcp_tool_with_empty_input_schema(): + tool_input_schema = { + "title": "ToolSchema", + "type": "object", + } + # Mock session and MCP tool + session = AsyncMock() + session.call_tool.return_value = CallToolResult( + content=[TextContent(type="text", text="tool result")], + isError=False, + ) + + mcp_tool = MCPTool( + name="test_tool", + description="Test tool description", + inputSchema=tool_input_schema, + ) + + # Convert MCP tool to LangChain tool + lc_tool = convert_mcp_tool_to_langchain_tool(session, mcp_tool) + + # Verify the converted tool + assert lc_tool.name == "test_tool" + assert lc_tool.description == "Test tool description" + assert lc_tool.args_schema == {**tool_input_schema, "properties": {}} + + # Test calling the tool + result = await lc_tool.ainvoke({"args": {}, "id": "1", "type": "tool_call"}) + + # Verify session.call_tool was called with correct arguments + session.call_tool.assert_called_once_with("test_tool", {}, progress_callback=None) + + # Verify result + assert result == ToolMessage( + content="tool result", name="test_tool", tool_call_id="1" + ) + + async def test_load_mcp_tools(): tool_input_schema = { "properties": { From e6c670d9e4bb1cf775af3d95a514d37598307a2e Mon Sep 17 00:00:00 2001 From: pedro-inf-custodio Date: Sat, 18 Oct 2025 18:38:08 +0100 Subject: [PATCH 3/3] fix: rename test for MCP tool input schema to reflect missing properties --- tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 562f0d2..ab2e3dc 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -150,7 +150,7 @@ async def test_convert_mcp_tool_to_langchain_tool(): ) -async def test_convert_mcp_tool_with_empty_input_schema(): +async def test_convert_mcp_tool_with_input_schema_missing_properties(): tool_input_schema = { "title": "ToolSchema", "type": "object",