Skip to main content
useToolInfo reads the tool call that rendered the current view, so a view can display the data its own tool produced. Import it from your generated helpers.ts: the typed hook infers input, output, and responseMetadata from your server, so you pass only the tool name.

Example

The view reads the result of the tool that rendered it, branching on status.
import { useToolInfo } from "../helpers.js"; // generated, type-safe from server schema

function Carousel() {
  const { input, isPending, isSuccess, output, responseMetadata } =
    useToolInfo<"search-products">();

  if (isPending) {
    return <p>Searching {input?.query}...</p>;
  }
  if (isSuccess) {
    return (
      <div>
        <ProductGrid products={output.products} />
        <p>
          {output.products.length} results in {responseMetadata.ms}ms
        </p>
      </div>
    );
  }
  return null;
}

Type Parameters

ToolSignature

ToolSignature extends Partial<{
  input: Record<string, unknown>;
  output: Record<string, unknown>;
  responseMetadata: Record<string, unknown>;
}> = Record<string, never>;
Refines the shape of input, output, and responseMetadata. This is the direct-import form; the generated helper takes a tool name instead and infers all three. With neither, each typed field resolves to never.

Returns

status

status: "pending" | "success";
  • "pending": the tool’s output and metadata have not arrived yet.
  • "success": the tool delivered its output or its responseMetadata.

isPending, isSuccess

isPending: boolean;
isSuccess: boolean;
Each is true when status equals the matching value and false otherwise. isIdle is also returned but deprecated, always false.

input

input: ToolInput | undefined;
The arguments the view’s tool was called with. The model sees these: they are part of the tool call in the conversation. It can be undefined in either state, because the host may render the view before it delivers the arguments.

output

output: ToolOutput | undefined;
The tool’s structured output, set when status is "success". The model sees this: it is the tool result in the conversation. It is undefined while pending, and undefined in success if the tool returned no structured output.

responseMetadata

responseMetadata: ToolResponseMetadata | undefined;
The _meta the tool’s handler returned alongside its result, typed from your server. It is undefined while pending, and undefined in success if the tool returned no metadata.

Create Views

Render a view from a tool result in context

generateHelpers

The typed useToolInfo that infers from your server

useCallTool

Call another tool from the view