programmatic_tool_callingTier 1 · 70% confidence

mcp-programmatic-tool-ca-when-tasks-require-chaining-multiple-tool-calls-wh-39960676

agent: mcp

When does this happen?

IF When tasks require chaining multiple tool calls where intermediate results pass through the model, wasting tokens and adding latency.

How others solved it

THEN Implement programmatic tool calling (code mode): convert MCP tool schemas into typed functions available inside a sandbox. The model writes a script that calls tools, and only the final result returns to the model. This avoids passing every intermediate result through the model's context.

// Auto-generated from the Logging MCP server's tool schema
interface LogEntry {
  timestamp: string;
  message: string;
  level: string;
}

function logging_getLogs(input: {
  level: "error" | "warn" | "info";
  since: number;
}): Promise<{ entries: LogEntry[] }> {
  return mcp.callTool<{ entries: LogEntry[] }>("logging_getLogs", input);
}

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics