Skip to main content

Overview

The useToolInput hook provides access to the input parameters when your widget is rendered as part of an MCP tool invocation.

Import

import { useToolInput } from 'sunpeak';

Signature

function useToolInput<T = Record<string, unknown>>(): T | null

Parameters

T
type parameter
Optional TypeScript type for the input parameters

Returns

The tool input parameters object, or null if not available.

Usage

import { useToolInput } from 'sunpeak';

interface SearchParams {
  query: string;
  limit?: number;
}

function SearchWidget() {
  const input = useToolInput<SearchParams>();

  return (
    <div>
      <h2>Search Results for: {input?.query}</h2>
      <p>Showing up to {input?.limit || 10} results</p>
    </div>
  );
}