programmatic_tool_callingTier 1 · 70% confidence

mcp-programmatic-tool-ca-when-a-task-requires-chaining-multiple-tool-calls--c4671be9

agent: mcp

When does this happen?

IF When a task requires chaining multiple tool calls, direct round trips pass every intermediate result through the model, consuming tokens and increasing latency even when the model has no reason to process those results.

How others solved it

THEN Implement programmatic tool calling ('code mode'): convert MCP tool schemas into typed API functions inside a sandbox; let the model write and execute a script that composes tool calls; return only the final result to the model. This avoids sending intermediate results back to the model.

```typescript
// Auto-generated from MCP tool schema
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