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.
Type Parameters
Section titled “Type Parameters”TId extends string = string
TInputSchema
Section titled “TInputSchema”TInputSchema extends SchemaLike = undefined
TOutputSchema
Section titled “TOutputSchema”TOutputSchema extends SchemaLike = undefined
TSuspendSchema
Section titled “TSuspendSchema”TSuspendSchema extends SchemaLike = undefined
TResumeSchema
Section titled “TResumeSchema”TResumeSchema extends SchemaLike = undefined
TRequestContext
Section titled “TRequestContext”TRequestContext extends unknown = unknown
TContext
Section titled “TContext”TContext extends ToolExecutionContext<InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TRequestContext> = ToolExecutionContext<InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TRequestContext>
Parameters
Section titled “Parameters”CreateToolOpts<TId, TInputSchema, TOutputSchema, TSuspendSchema, TResumeSchema, TRequestContext, TContext>
Returns
Section titled “Returns”Tool<InferSchema<TInputSchema>, InferSchema<TOutputSchema>, InferSchema<TSuspendSchema>, InferSchema<TResumeSchema>, TContext, TId, TRequestContext>
Example
Section titled “Example”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.jsonwith your project’s resolver or package-manager tooling, then readdist/docs/SKILL.mdfrom that package root and follow its reference links. Use package-manager tools for virtual or archived packages. - Tool documentation if packaged docs are unavailable.