MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / dispatch_tool_call

Function dispatch_tool_call

src/harness/agentic_loop/tools.py:431–451  ·  view source on GitHub ↗

Route a tool call to orchestrator handler or MCP. Checks orchestrator tools first (local, fast). Falls back to MCP for sandbox tools.

(
    tool_name: str,
    tool_args: dict[str, Any],
    orchestrator_tools: list[OrchestratorTool],
    mcp_client: Any,
)

Source from the content-addressed store, hash-verified

429
430
431def dispatch_tool_call(
432 tool_name: str,
433 tool_args: dict[str, Any],
434 orchestrator_tools: list[OrchestratorTool],
435 mcp_client: Any,
436) -> str:
437 """Route a tool call to orchestrator handler or MCP.
438
439 Checks orchestrator tools first (local, fast). Falls back to MCP
440 for sandbox tools.
441 """
442 for tool in orchestrator_tools:
443 if tool.name == tool_name:
444 return tool.handler(tool_args)
445 # Not an orchestrator tool -> dispatch to MCP
446 result = mcp_client.invoke(tool_name, tool_args)
447 return (
448 json.dumps(result, default=str)
449 if isinstance(result, (dict, list))
450 else str(result)
451 )

Callers

nothing calls this directly

Calls 1

invokeMethod · 0.45

Tested by

no test coverage detected