From c45500604471142a47b87b016ae29119e4fc8211 Mon Sep 17 00:00:00 2001 From: syf2211 Date: Sun, 28 Jun 2026 10:05:55 +0000 Subject: [PATCH] fix(smolagents): support MCP tools with no input parameters Parameter-less tools may expose a valid JSON Schema of {"type": "object"} without a properties field. SmolAgentsAdapter previously assumed properties was always present and raised KeyError during adaptation. Fixes #78 --- src/mcpadapt/smolagents_adapter.py | 11 +++++++---- tests/test_smolagents_adapter.py | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/mcpadapt/smolagents_adapter.py b/src/mcpadapt/smolagents_adapter.py index d48b542..e2d6935 100644 --- a/src/mcpadapt/smolagents_adapter.py +++ b/src/mcpadapt/smolagents_adapter.py @@ -99,12 +99,15 @@ def adapt( if k != "$defs" } + # Parameter-less tools may omit `properties`; treat that as an empty object schema. + properties = input_schema.setdefault("properties", {}) + # make sure mandatory `description` and `type` is provided for each arguments: - for k, v in input_schema["properties"].items(): + for k, v in properties.items(): if "description" not in v: - input_schema["properties"][k]["description"] = "see tool description" + properties[k]["description"] = "see tool description" if "type" not in v: - input_schema["properties"][k]["type"] = "string" + properties[k]["type"] = "string" # Extract and resolve outputSchema if present (only if structured_output=True) output_schema = None @@ -235,7 +238,7 @@ def forward( tool = MCPAdaptTool( name=mcp_tool.name, description=mcp_tool.description or "", - inputs=input_schema["properties"], + inputs=properties, output_type=output_type, output_schema=output_schema, structured_output=self.structured_output, diff --git a/tests/test_smolagents_adapter.py b/tests/test_smolagents_adapter.py index a1ccb2b..3824af7 100644 --- a/tests/test_smolagents_adapter.py +++ b/tests/test_smolagents_adapter.py @@ -135,6 +135,33 @@ def test_optional_sync(echo_server_optional_script): assert tools[2](text="hello") == "Echo: hello" +def test_tool_with_no_input_parameters(): + mcp_server_script = dedent( + ''' + from mcp.server.fastmcp import FastMCP + + mcp = FastMCP("Version Server") + + @mcp.tool() + def server_version() -> str: + """Return the server version.""" + return "1.0.0" + + mcp.run() + ''' + ) + with MCPAdapt( + StdioServerParameters( + command="uv", args=["run", "python", "-c", mcp_server_script] + ), + SmolAgentsAdapter(), + ) as tools: + assert len(tools) == 1 + assert tools[0].name == "server_version" + assert tools[0].inputs == {} + assert tools[0]() == "1.0.0" + + def test_tool_name_with_dashes(): mcp_server_script = dedent( '''