# useDefaultTool

> The useDefaultTool hook enables rendering of a default UI which catches any tool that does not have a specific renderer.

## v1 SDK deprecated. Use v2 instead

> This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead.
> For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
> **AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape.**
> [Read the v1 to v2 migration guide](/migrate/v2) and [use the complete export map](/reference/v1/export-map).

<Callout type="warning">
  `useDefaultTool` is still supported, but we recommend migrating to [`useDefaultRenderTool`](/reference/v2/hooks/useDefaultRenderTool) from the v2 API.
</Callout>

`useDefaultTool` is a React hook that lets you render custom UI for any tool
call that doesn't have a specific renderer

## Usage [#usage]

```tsx
import { useDefaultTool } from "@copilotkit/react-core";

useDefaultTool({
  render: ({ name, args, status, result }) => {
    return (
      <div className="p-4 border rounded my-2">
        <div className="flex items-center justify-between mb-2">
          <h4 className="font-semibold">{name}</h4>
          <span className="text-sm text-gray-500">
            {status === "inProgress" && "Running..."}
            {status === "executing" && "Executing..."}
            {status === "complete" && "Complete"}
          </span>
        </div>

        {Object.keys(args).length > 0 && (
          <div className="mb-2">
            <p className="text-sm font-medium text-gray-600">Parameters:</p>
            <pre className="text-xs bg-gray-100 p-2 rounded mt-1">
              {JSON.stringify(args, null, 2)}
            </pre>
          </div>
        )}

        {status === "complete" && result && (
          <div>
            <p className="text-sm font-medium text-gray-600">Result:</p>
            <pre className="text-xs bg-gray-100 p-2 rounded mt-1">
              {JSON.stringify(result, null, 2)}
            </pre>
          </div>
        )}
      </div>
    );
  },
});
```

### Rendering Model Context Protocol (MCP) Tools [#rendering-model-context-protocol-mcp-tools]

```tsx
import { useDefaultTool } from "@copilotkit/react-core";

// Render any MCP tool call with a custom UI
useDefaultTool({
  render: ({ name, args, status, result }) => {
    // Custom rendering for MCP tools
    if (name.startsWith("mcp_")) {
      return <MCPToolRenderer name={name} args={args} status={status} result={result} />;
    }

    // Default rendering for other tools
    return <DefaultToolRenderer name={name} args={args} status={status} result={result} />;
  },
});
```

## Parameters [#parameters]

<PropertyReference name="tool" type='Omit<CatchAllFrontendAction, "name">' required>
  The tool rendering configuration object.
    <PropertyReference name="render" type="(props: CatchAllActionRenderProps<any>) => React.ReactElement">
      A function that returns the tool call UI. It receives props with:

      <div className="ml-8">
        <PropertyReference name="status" type="'inProgress' | 'executing' | 'complete'">
          - `"inProgress"`: Tool is being prepared or arguments are being streamed.
          - `"executing"`: Tool is actively running.
          - `"complete"`: Tool execution has finished.
        </PropertyReference>

        <PropertyReference name="args" type="Partial<T> | T | any">
          The arguments passed to the tool. Type-safe if parameters schema is provided.
          For catch-all renderers (`name: "*"`), this will be `any`.
        </PropertyReference>

        <PropertyReference name="result" type="any">
          The result returned by the tool. Only available when status is `"complete"`.
        </PropertyReference>

        <PropertyReference name="name" type="string">
          The actual name of the tool being executed. Particularly useful for
          catch-all renderers to know which tool is being rendered.
        </PropertyReference>
      </div>
    </PropertyReference>

    <PropertyReference name="renderAndWaitForResponse" type="(props: CatchAllActionRenderPropsWait<any>) => React.ReactElement">
      Use it in place of `render`. The tool call waits until you call `respond` with the result. Read `name` to tell the calls apart.
    </PropertyReference>
</PropertyReference>

<PropertyReference name="dependencies" type="any[]">
  An optional array of dependencies.
</PropertyReference>

## Common Use Cases [#common-use-cases]

1. **Backend Tool Visualization**: Display progress and results of long-running backend operations
2. **Generic Tool Rendering**: Provide a fallback UI for any tool without specific rendering
3. **MCP Tool Integration**: Render Model Context Protocol tools from various sources
4. **Debugging**: Display all tool calls during development
5. **Analytics**: Track and display tool usage

## Migration from useCopilotAction [#migration-from-usecopilotaction]

If you're migrating from `useCopilotAction` with only a `render` function:

```tsx
// Before with useCopilotAction (the catch-all name is "*")
useCopilotAction({
  name: "*",
  render: ({ name, args, status, result }) => (
    <GenericToolCall name={name} args={args} status={status} result={result} />
  ),
});

// After with useDefaultTool
useDefaultTool({
  render: ({ name, args, status, result }) => (
    <GenericToolCall name={name} args={args} status={status} result={result} />
  ),
});
```

Change the hook name to `useDefaultTool` and remove `name: "*"`. The render props remain the same.
