How single-call server lookup works under the hood, why you must resend tools every turn, and the exact HTTP 400 traps to avoid.
Under server-side retrieval, setting {"type": "tool_search"} alongside defer_loading: true splits your tool list cleanly. In turn one, Gemini receives only the tool name and description (or optional short_description when the full description is parameter-heavy). When the task requires issue_refund or a deferred remote mcp_server, Gemini emits a tool_search_call step (tsc_*), the API immediately resolves and appends the matching schema in a tool_search_result step carrying an opaque encrypted signature, and Gemini emits the real function_call or mcp_server_tool_call within that exact same API response.
That ordering delivers a critical economic bonus: prefix caching compatibility. Because deferred parameter schemas stay out of the prompt prefix and retrieved schemas are appended later inside conversation steps, your cached prompt prefix remains byte-identical across turns and across disparate user intents—unlike dynamic prompt assembly that busts prefix caches whenever a user triggers a different tool subset.
There are three strict protocol invariants documented in <a href="https://ai.google.dev/gemini-api/docs/tool-retrieval" target="_blank" rel="noopener">Google’s Tool Retrieval reference</a>. First, even when chaining with previous_interaction_id, the API does not carry tool declarations forward—you must resend the complete tools array on every turn. Second, never combine defer_loading: true with execution: "client" or omit defer_loading: true when setting short_description; both trigger immediate 400 rejections. Third, in stateless mode (store: false), you must circulate both tool_search_call and tool_search_result steps verbatim—encrypted signature fields intact—or the follow-up function_result request fails with Server side tool call context must be circulated or Tool call part is missing thought_signature.
01 · Leave Your Top 3–5 Hot Tools Undeferred
Keep core high-frequency tools loaded upfront (defer_loading omitted) and defer the long tail plus broad remote mcp_server endpoints so routine turns avoid unnecessary search steps.
02 · Always Resend the Complete tools Array Every Turn
Even when passing previous_interaction_id, omitting tool_search or deferred tools causes follow-up turns to forget unloaded capabilities or throw 400 validation errors.
03 · Circulate tool_search_call + tool_search_result Verbatim When store: false
Use @google/genai v3.6.0+ so unknown step types are never stripped, and push every step object—including its encrypted signature—directly back into history before function_result.
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
const tools = [
{ type: "tool_search" },
{
type: "function",
name: "get_order_status",
description: "Look up live fulfillment status for an order ID.",
parameters: {
type: "object",
properties: { order_id: { type: "string" } },
required: ["order_id"],
},
},
{
type: "function",
name: "issue_refund",
description: "Refund a damaged or missing order to the original payment method with audit logging.",
short_description: "Refund an order to the original payment method.",
defer_loading: true,
parameters: {
type: "object",
properties: {
order_id: { type: "string" },
amount: { type: "number" },
},
required: ["order_id", "amount"],
},
},
{
type: "mcp_server",
name: "warehouse_inventory",
url: "https://gemini-api-demos.uc.r.appspot.com/mcp",
defer_loading: true,
},
];
// Turn 1: stateless store: false requires full history circulation
const history = [
{ type: "user_input", content: [{ type: "text", text: "Order A-1042 arrived damaged. Refund 40 dollars." }] },
];
const turn1 = await ai.interactions.create({
model: "gemini-4-hydrogen",
store: false,
input: history,
tools,
});
// Preserve tool_search_call, tool_search_result, and opaque signatures verbatim
for (const step of turn1.steps) {
history.push(step);
}
const fcStep = turn1.steps.find((step) => step.type === "function_call");
if (fcStep) {
history.push({
type: "function_result",
name: fcStep.name,
call_id: fcStep.id,
result: [{ type: "text", text: JSON.stringify({ refunded: true, order_id: "A-1042", amount: 40 }) }],
});
// Always resend the complete tools array on every follow-up turn
const turn2 = await ai.interactions.create({
model: "gemini-4-hydrogen",
store: false,
input: history,
tools,
});
console.log(turn2.output_text);
}