CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
fix(mcp): match real tool.execute signature; propagate isError; exclude_none
xf gong7aef69adf878
diff --git a/cubepi/agent/types.py b/cubepi/agent/types.pyindex ed1dc5e..37e0321 100644--- a/cubepi/agent/types.py+++ b/cubepi/agent/types.py@@ -23,6 +23,7 @@ TMessage = TypeVar("TMessage")class AgentToolResult(BaseModel):content: list[Content]details: Any = None+ is_error: bool | None = Noneterminate: bool | None = Nonediff --git a/cubepi/mcp/_adapter.py b/cubepi/mcp/_adapter.pyindex 922ad46..fc11ee7 100644--- a/cubepi/mcp/_adapter.py+++ b/cubepi/mcp/_adapter.py@@ -72,8 +72,18 @@ def make_mcp_agent_tool(input_schema=input_schema,)- async def _execute(args) -> AgentToolResult:- args_dict = args.model_dump() if hasattr(args, "model_dump") else dict(args)+ async def _execute(+ tool_call_id: str,+ args,+ *,+ signal=None,+ on_update=None,+ ) -> AgentToolResult:+ # tool_call_id and on_update are unused by MCP semantics (MCP RPC is+ # not incremental), but we accept them for signature compatibility+ # with cubepi's agent loop.+ del tool_call_id, on_update+ args_dict = args.model_dump(exclude_none=True) if hasattr(args, "model_dump") else dict(args)result = await call_remote(name, args_dict)content_blocks: list[Content] = []for c in result.get("content", []):@@ -82,6 +92,7 @@ def make_mcp_agent_tool(return AgentToolResult(content=content_blocks,details={"raw_mcp_response": result},+ is_error=True if result.get("isError") else None,)return AgentTool(diff --git a/tests/mcp/test_adapter.py b/tests/mcp/test_adapter.pyindex 959cc52..4833d31 100644--- a/tests/mcp/test_adapter.py+++ b/tests/mcp/test_adapter.py@@ -90,7 +90,8 @@ async def test_make_mcp_agent_tool_routes_to_call_remote() -> None:assert tool.description == "Search the web"args = tool.parameters(query="cats")- result = await tool.execute(args)+ # Use the production signature: tool_call_id positional, then args, then keyword-only+ result = await tool.execute("test-call-id-1", args, signal=None, on_update=None)assert called == {"name": "search", "args": {"query": "cats"}}assert len(result.content) == 1from cubepi.providers.base import TextContent@@ -111,7 +112,40 @@ async def test_make_mcp_agent_tool_carries_raw_response_in_details() -> None:call_remote=_fake_call,)args = tool.parameters()- result = await tool.execute(args)+ result = await tool.execute("test-call-id-2", args, signal=None, on_update=None)assert result.details == {"raw_mcp_response": {"content": [], "isError": True, "errorMessage": "boom"}}+ # isError from MCP response must be reflected on AgentToolResult+ assert result.is_error is True+++async def test_make_mcp_agent_tool_omits_none_optional_args() -> None:+ """Optional schema field absent from args → omitted from call (not sent as null)."""+ captured: dict = {}++ async def _fake_call(name, args):+ captured["args"] = args+ return {"content": [], "isError": False}++ tool = make_mcp_agent_tool(+ name="search",+ description="",+ input_schema={+ "type": "object",+ "properties": {+ "query": {"type": "string"},+ "limit": {"type": "integer"},+ },+ "required": ["query"],+ },+ call_remote=_fake_call,+ )+ args = tool.parameters(query="cats") # limit not passed+ await tool.execute("tc-3", args, signal=None, on_update=None)+ # Critical: 'limit' must NOT appear in args (not even as null)+ assert "limit" not in captured["args"], (+ f"Optional field not provided should be omitted, got: {captured['args']!r}"+ )+ assert captured["args"] == {"query": "cats"}diff --git a/tests/mcp/test_stdio_loader.py b/tests/mcp/test_stdio_loader.pyindex acb4e81..569ab87 100644--- a/tests/mcp/test_stdio_loader.py+++ b/tests/mcp/test_stdio_loader.py@@ -25,7 +25,7 @@ async def test_stdio_loader_against_fake_server() -> None:assert echo.name == "echo"args = echo.parameters(text="hello")- result = await echo.execute(args)+ result = await echo.execute("tc-stdio-1", args, signal=None, on_update=None)assert len(result.content) == 1from cubepi.providers.base import TextContent