"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(tools): MCP tool schemas with a malformed properties field no longer lose the properties key entirely
Lanre Shittu19d2920a1d91
diff --git a/agent/src/tools/mcp.py b/agent/src/tools/mcp.pyindex 39f9881ca..e39bc3f28 100644--- a/agent/src/tools/mcp.py+++ b/agent/src/tools/mcp.py@@ -479,7 +479,8 @@ def normalize_mcp_tool_schema(schema: dict[str, Any] | None) -> dict[str, Any]:properties = normalized.get("properties")if properties is not None and not isinstance(properties, dict):normalized.pop("properties", None)- elif not isinstance(properties, dict) and not _schema_uses_composed_top_level_rules(normalized):+ properties = None+ if not isinstance(properties, dict) and not _schema_uses_composed_top_level_rules(normalized):normalized["properties"] = {}required = normalized.get("required")diff --git a/agent/tests/test_mcp_client_adapter.py b/agent/tests/test_mcp_client_adapter.pyindex 575abcd58..fd6bf7a18 100644--- a/agent/tests/test_mcp_client_adapter.py+++ b/agent/tests/test_mcp_client_adapter.py@@ -148,6 +148,18 @@ def test_normalize_mcp_tool_schema_collapses_nullable_object() -> None:assert schema["required"] == ["symbol"]+def test_normalize_mcp_tool_schema_recovers_from_malformed_properties() -> None:+ """A non-dict top-level ``properties`` (malformed remote schema) must still+ end up with the documented ``properties: {}`` fallback, not no key at all.+ """+ schema = normalize_mcp_tool_schema(+ {"type": "object", "properties": "oops", "required": ["symbol"]}+ )++ assert schema["properties"] == {}+ assert schema["required"] == ["symbol"]++def test_normalize_mcp_tool_schema_preserves_top_level_one_of_branches() -> None:schema = normalize_mcp_tool_schema({@@ -287,6 +299,35 @@ def test_remote_tool_execute_forwards_arguments_for_composed_schema() -> None:assert state["call_records"][0]["arguments"] == {"symbol": "AAPL"}+def test_remote_tool_malformed_properties_still_yields_valid_schema() -> None:+ """A remote tool whose schema has a non-dict top-level ``properties`` used+ to end up with no ``properties`` key at all on ``tool.parameters`` — the+ exact object forwarded verbatim as the OpenAI-style function-calling+ schema (``to_openai_schema`` only falls back to a default when+ ``self.parameters`` is falsy, and a dict missing just one key is still+ truthy), so a malformed remote schema reached the LLM provider API as an+ invalid tool definition instead of the documented ``properties: {}``+ fallback."""+ state = {+ "list_calls": 0,+ "call_calls": 0,+ "call_records": [],+ "list_outcomes": [[+ mcp_types.Tool(+ name="lookup",+ description="Lookup by symbol",+ inputSchema={"type": "object", "properties": "oops", "required": ["symbol"]},+ )+ ]],+ "call_outcomes": [],+ }++ tool = build_mcp_tool_wrappers("demo", _make_config(), client_factory=_make_factory(state))[0]++ assert isinstance(tool.parameters.get("properties"), dict)+ assert tool.to_openai_schema()["function"]["parameters"]["properties"] == {}++@dataclassclass _RobinhoodPosition:"""FastMCP-style generated dataclass nested in a Robinhood response."""