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

# useToolData

> Access tool input and output data.

<Badge color="yellow">sunpeak API</Badge>

## Overview

The `useToolData` hook provides reactive access to both the tool's input arguments and output data (structured content). It replaces the need for separate input/output hooks. The `output` field contains the data from your MCP tool's `structuredContent` response.

<Card horizontal title="Wraps ontoolinput · ontoolresult · ontoolcancelled" icon="cube" href="/mcp-apps/app/event-handlers">
  MCP Apps SDK reference
</Card>

## Import

```tsx theme={null}
import { useToolData } from 'sunpeak';
```

## Signature

```tsx theme={null}
function useToolData<TInput, TOutput>(
  defaultInput?: TInput,
  defaultOutput?: TOutput
): ToolData<TInput, TOutput>
```

## Parameters

<ResponseField name="defaultInput" type="TInput">
  Fallback value when no input is available. Optional.
</ResponseField>

<ResponseField name="defaultOutput" type="TOutput">
  Fallback value when no output is available. Optional.
</ResponseField>

## Returns

Returns a `ToolData<TInput, TOutput>` object with the following fields:

<ResponseField name="input" type="TInput | null">
  The tool call arguments.
</ResponseField>

<ResponseField name="inputPartial" type="TInput | null">
  Streaming partial input during tool execution.
</ResponseField>

<ResponseField name="output" type="TOutput | null">
  The structured content from the tool result.
</ResponseField>

<ResponseField name="isError" type="boolean">
  Whether the tool result indicates an error.
</ResponseField>

<ResponseField name="isLoading" type="boolean">
  Whether the tool is still executing.
</ResponseField>

<ResponseField name="isCancelled" type="boolean">
  Whether the tool call was cancelled by the host or user.
</ResponseField>

<ResponseField name="cancelReason" type="string | null">
  Optional reason for cancellation, or null if not cancelled.
</ResponseField>

## Usage

```tsx theme={null}
import { useToolData } from 'sunpeak';

interface ReviewInput {
  changesetId: string;
  title: string;
}

interface ReviewOutput {
  title: string;
  sections: Array<{ title: string; content: unknown[] }>;
}

function ReviewResource() {
  const { input, output, isLoading } = useToolData<ReviewInput, ReviewOutput>(
    undefined,
    { title: 'Review', sections: [] }
  );

  if (isLoading) return <div>Loading...</div>;

  return (
    <div>
      <h1>{output?.title}</h1>
      <p>Changeset: {input?.changesetId}</p>
    </div>
  );
}
```
