Skip to main content
ToolCall is the bridge between your UI and your server logic. When a user clicks a button or submits a form, ToolCall invokes a server tool with the arguments you specify — the same tools you define with @mcp.tool(). The renderer proxies the call through the Prefab SDK, so the tool executes server-side with full access to your backend.

Passing Arguments

Use {{ key }} interpolation in the arguments dict to pass client state to the tool. Form controls with a name automatically sync to state — Input(name="city") updates city on every keystroke, no SetState needed. Type a city name, click the button, and the current input value flows into the location argument.

Combined with Client Actions

Pass a list to execute multiple actions from a single interaction. A common pattern: update UI state before making the server call, so the user sees immediate feedback.
Combined Actions
from prefab_ui.components import Button
from prefab_ui import ToolCall, SetState

Button("Analyze", on_click=[
    SetState("status", "analyzing..."),
    ToolCall("run_analysis", arguments={"data": "{{ dataset }}"}),
])
The SetState executes first (instant), then ToolCall fires the server request.

API Reference

ToolCall Parameters

tool
str
required
Name of the server tool to call. Can be passed as a positional argument.
arguments
dict[str, Any]
default:"{}"
Arguments to pass to the tool. Values support {{ key }} interpolation to reference client-side state at call time.

Protocol Reference

ToolCall
{
  "action": "toolCall",
  "tool": "string (required)",
  "arguments?": "object",
  "resultKey?": "string"
}
For the complete protocol schema, see ToolCall.