> ## 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 complete and streaming MCP tool input, structured tool output, loading state, errors, and cancellation in a React View.

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

## Overview

The `useToolData` hook provides reactive access to both the tool's input arguments and output data. It replaces the need for separate input/output hooks. The `output` field contains `structuredContent` when the result includes that property, including an explicit `null`. When the property is absent, it falls back to the result's `content` blocks.

<Card horizontal title="Wraps ontoolinput · ontoolresult · ontoolcancelled" icon="cube" href="/docs/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 complete tool call arguments. Partial notifications do not overwrite this field.
</ResponseField>

<ResponseField name="inputPartial" type="TInput | null">
  The latest streaming partial input. sunpeak clears it when complete input arrives.
</ResponseField>

<ResponseField name="output" type="TOutput | null">
  The tool result's `structuredContent` value when present, including explicit null. Falls back to `content` when `structuredContent` is absent.
</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>
  );
}
```

## Stream a Preview Before Complete Input Arrives

MCP hosts may send zero or more partial input notifications before the complete tool arguments. Read `inputPartial` for preview UI and `input` for the finalized value:

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

interface DocumentInput {
  title?: string;
  body?: string;
}

function DocumentPreview() {
  const { inputPartial, input, isCancelled } = useToolData<DocumentInput>();
  const currentInput = inputPartial ?? input;

  if (isCancelled) return <p>Generation cancelled.</p>;

  return (
    <article aria-busy={inputPartial !== null}>
      <h1>{currentInput?.title ?? 'Untitled'}</h1>
      <pre>{currentInput?.body ?? 'Waiting for content...'}</pre>
    </article>
  );
}
```

`inputPartial` can contain missing, truncated, or changing fields. Use it only for rendering a preview. Wait for `input` before saving data or starting an action. See [`ontoolinputpartial`](/docs/mcp-apps/app/event-handlers/ontoolinputpartial) for the protocol event order and local testing steps.


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