> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skybridge.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# useRegisterViewTool

> Expose a tool the host and model can call against the running view

A [tool](https://docs.skybridge.tech/build/tools.md) the model calls normally runs on your server. `useRegisterViewTool` registers a tool that runs in the [view](https://docs.skybridge.tech/build/view.md) instead: the model invokes it and the handler executes in your component, so the model can mutate view [state](https://docs.skybridge.tech/build/state.md) or do any work that does not need the backend.

## Example

The model adds an on-screen product to the cart by calling a tool the view handles itself: the handler updates the live cart and reports back what it added.

```tsx highlight={2,7-23} theme={null}
import * as z from "zod";
import { useRegisterViewTool, useViewState } from "skybridge/web";

function Carousel({ products }: { products: Product[] }) {
  const [{ cart }, setState] = useViewState({ cart: [] }); // synced with the model, survives remount

  useRegisterViewTool(
    {
      name: "carousel_add_to_cart",
      title: "Add to cart",
      description: "Add a product from the carousel to the cart by its id.",
      inputSchema: { productId: z.string() },
      annotations: { readOnlyHint: false },
    },
    ({ productId }) => {
      const product = products.find((p) => p.id === productId);
      setState((s) => ({ cart: [...s.cart, productId] }));
      return {
        content: [{ type: "text", text: `Added ${product?.name ?? productId} to the cart.` }],
        structuredContent: { cart: [...cart, productId] },
      };
    },
  );

  return <ProductGrid products={products} />;
}
```

## Parameters

### `config`

```tsx theme={null}
config: ViewToolConfig<TInput>;
```

**Required.** Declares the tool the view exposes, mirroring the server-side [`registerTool`](https://docs.skybridge.tech/api-reference/register-tool) config. Namespace `name` (for example `carousel_add_to_cart`) so it does not clash with a server tool.

```tsx theme={null}
type ViewToolConfig<TInput> = {
  name: string; // tool name the model calls
  title?: string;
  description?: string; // model-facing: decides when the model calls this tool
  inputSchema?: TInput; // Zod raw shape; types the handler args
  annotations?: ToolAnnotations; // standard MCP hints, e.g. readOnlyHint
};
```

### `handler`

```tsx theme={null}
handler: (args: InferViewToolArgs<TInput>) => ViewToolResult | Promise<ViewToolResult>;
```

**Required.** Runs when the model calls the tool, receiving the arguments typed from `config.inputSchema` (each field's optionality preserved). It returns the MCP `CallToolResult`; the model sees `content` and `structuredContent` as the tool result in the conversation.

```tsx theme={null}
type ViewToolResult = {
  content?: ContentBlock[]; // returned to the model; defaults to []
  structuredContent?: Record<string, unknown>; // typed result the model reads
  isError?: boolean; // true marks the call as failed
  _meta?: Record<string, unknown>;
};
```

## Lifecycle

The hook registers the tool on mount, removes it on unmount, and re-registers only when `name` changes. The `handler` always runs its latest version, so it sees current state; changes to the other config fields reach the host only on re-registration.

> [card] [Create Views](https://docs.skybridge.tech/build/view.md)
>
> Wire a view tool into a running view

> [card] [useCallTool](https://docs.skybridge.tech/api-reference/use-call-tool.md)
>
> The inverse: call a server tool from the view

> [card] [useToolInfo](https://docs.skybridge.tech/api-reference/use-tool-info.md)
>
> Read the tool result the view mounted with


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.