# defineChannelTool

> Define a Standard Schema-validated tool with inferred arguments and Channels thread context.

`defineChannelTool` preserves a tool definition while inferring the handler
argument type from its Standard Schema.

## Signature [#signature]

```ts
function defineChannelTool<Schema extends ObjectSchema>(
  tool: ChannelTool<Schema>,
): ChannelTool<Schema>;
```

```ts
interface ChannelTool<Schema extends ObjectSchema> {
  name: string;
  description: string;
  parameters: Schema;
  handler(
    args: InferSchemaOutput<Schema>,
    context: ChannelToolContext,
  ): unknown | Promise<unknown>;
}
```

## Example [#example]

```ts title="tools.ts"
import { defineChannelTool } from "@copilotkit/channels";
import { z } from "zod";

export const getIncident = defineChannelTool({
  name: "get_incident",
  description: "Read an incident by id.",
  parameters: z.object({
    incidentId: z.string(),
  }),
  async handler({ incidentId }) {
    const incident = await incidents.get(incidentId);
    return incident;
  },
});
```

Register tools in `createChannel({ tools })`, add one with `channel.tool(tool)`
before startup, or pass turn-scoped tools to `thread.runAgent({ tools })`.

## Handler context [#handler-context]

| Field      | Type                           | Managed behavior                                                          |
| ---------- | ------------------------------ | ------------------------------------------------------------------------- |
| `thread`   | `Thread`                       | Current conversation handle.                                              |
| `message`  | `IncomingMessage \| undefined` | Current inbound message when the run began from a message trigger.        |
| `user`     | `ApplicationUser \| null`      | Application user selected for this event.                                 |
| `actor`    | `ProviderActor`                | Provider account that caused this event.                                  |
| `signal`   | `AbortSignal \| undefined`     | Reserved optional field; the current SDK tool runner leaves it undefined. |
| `platform` | `string`                       | Normalized source provider, such as `"slack"` or `"teams"`.               |

Return raw objects or arrays for data. The SDK JSON-serializes non-string
results for the model. A tool that already posted UI should return a short
natural-language confirmation so the model does not repeat the card.

See [Tools and context](/slack/tools) for a complete managed example.
