const myTool = defineTool({
description: "My tool description",
input: z.object({ name: z.string() }),
output: z.object({ result: z.string() }),
handler: async (input, context) => {
// input is fully typed as { name: string }
return { result: `Hello ${input.name}` };
}
});
const myTool = defineTool({
description: "My tool description",
input: { name: z.string() },
output: { result: z.string() },
handler: async (input, context) => {
// input is fully typed as { name: string }
return { result: `Hello ${input.name}` };
}
});
Helper function to define a tool with proper type inference.
This helper solves TypeScript's generic type inference limitations by capturing the specific schema types at the call site.
Supports both explicit Zod schemas and inline object syntax: