Skip to content

Function: createTool()

createTool<TId, TInputSchema, TOutputSchema, TSuspendSchema, TResumeSchema, TRequestContext, TContext>(opts): Tool<InferSchema<TInputSchema>, InferSchema<TOutputSchema>, InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TContext, TId, TRequestContext>

Defines a tool with a description, input/output schemas, and an execution function.

TId extends string = string

TInputSchema extends SchemaLike = undefined

TOutputSchema extends SchemaLike = undefined

TSuspendSchema extends SchemaLike = undefined

TResumeSchema extends SchemaLike = undefined

TRequestContext extends unknown = unknown

TContext extends ToolExecutionContext<InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TRequestContext> = ToolExecutionContext<InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TRequestContext>

CreateToolOpts<TId, TInputSchema, TOutputSchema, TSuspendSchema, TResumeSchema, TRequestContext, TContext>

Tool<InferSchema<TInputSchema>, InferSchema<TOutputSchema>, InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TContext, TId, TRequestContext>

import { createTool } from '@mastra/core/tools';
import { z } from 'zod';
const greet = createTool({
id: 'greet',
description: 'Greet someone by name.',
inputSchema: z.object({ name: z.string() }),
outputSchema: z.string(),
execute: async ({ name }) => `Hello, ${name}!`,
});
  • For documentation bundled with your installed package, locate @mastra/core/package.json with your project’s resolver or package-manager tooling, then read dist/docs/SKILL.md from that package root and follow its reference links. Use package-manager tools for virtual or archived packages.
  • Tool documentation if packaged docs are unavailable.