options.server parameter. When omitted, they use the provider’s default server. Low-level hooks like useServer and useResolvedServer accept a server name directly as an argument instead.
useCallTool
Call an MCP tool with typed input/output.Parameters
| Parameter | Type | Description |
|---|---|---|
toolName | string | Name of the MCP tool |
options.server | string | Target a named server |
options.onSuccess | (data) => void | Success callback |
options.onError | (error) => void | Error callback |
options.resetOnToolChange | boolean | Reset state when toolName changes (default: true) |
Return Value
| Index | Type | Description |
|---|---|---|
[0] | (args: TInput) => Promise<TOutput | null> | Call function |
[1] | ToolState<TOutput> | { data, loading, error, called } |
[2] | () => void | Reset state |
Example
useReadResource
Dual-mode resource reading — lazy or auto-fetch.Lazy Mode
[read, state] tuple. Call read(uri) on demand.
Auto-Fetch Mode
refetch() to re-read.
useGetPrompt
Fetch an MCP prompt by name.Example
useListTools
Reactive tool list from the registry.useListResources
Reactive resource and resource template lists.useListPrompts
Reactive prompt list.useStoreResource
Subscribe to astate:// URI with live updates via MCP resource subscriptions.
notifications/resources/updated, the hook automatically re-fetches the resource. Content is JSON-parsed when possible.
Example
useServer
Low-level hook to access a rawServerEntry from the registry.
useSyncExternalStore for tear-free reads.
useResolvedServer
Internal hook that resolves a server entry with context fallback.useDynamicTool
Register an MCP tool on mount, unregister on unmount. See Dynamic Tools for full details. Supports both zod schemas (recommended) and raw JSON Schema (backward compat).With Zod Schema (Recommended)
schema, input is automatically validated via safeParse before reaching your execute callback. Invalid input returns an error CallToolResult with validation details.
With JSON Schema (Backward Compat)
Options
| Option | Type | Default | Description |
|---|---|---|---|
name | string | — | Required. Tool name |
description | string | — | Required. Description for agents |
schema | z.ZodObject | — | Zod schema (mutually exclusive with inputSchema) |
inputSchema | Record<string, unknown> | — | JSON Schema (mutually exclusive with schema) |
execute | (args) => Promise<CallToolResult> | — | Required. Handler |
enabled | boolean | true | Conditionally enable/disable |
server | string | — | Target a named server |
useDynamicResource
Register an MCP resource on mount, unregister on unmount. See Dynamic Tools for full details.Options
| Option | Type | Default | Description |
|---|---|---|---|
uri | string | — | Required. Resource URI |
name | string | — | Required. Human-readable name |
description | string | — | Description for agents |
mimeType | string | — | Content MIME type |
read | () => Promise<ReadResourceResult> | — | Required. Handler |
enabled | boolean | true | Conditionally enable/disable |
server | string | — | Target a named server |
useComponentTree
Expose the DOM subtree under a ref as a JSON MCP resource. See Dynamic Tools for full details.Options
| Option | Type | Default | Description |
|---|---|---|---|
rootRef | RefObject<HTMLElement | null> | — | Required. Root element ref |
uri | string | 'react://component-tree' | Resource URI |
maxDepth | number | 10 | Max traversal depth |
includeProps | boolean | false | Include data-* attributes |
server | string | — | Target a named server |
Multi-Server Pattern
All hooks accept{ server: 'name' } to target a specific server: