createTool helper to define tools with automatic input/output validation.
Basic Tool Creation
Create a tool using thecreateTool helper with an ID, description, and execute function:
Tool with Input and Output Schemas
Define input and output schemas for type safety and validation:Tool with Context Access
Access Mastra instance and other context in the execute function:Tool Requiring Approval
Create tools that require explicit user approval before execution:Tool Execution Context
The execution context provides access to:mastra- Mastra instance for accessing storage, agents, workflowsrequestContext- Request-scoped values (auth, feature flags, etc.)agent- Agent-specific context (toolCallId, messages, suspend/resume)workflow- Workflow-specific context (runId, state, suspend/resume)workspace- Workspace for file operations and command executionwriter- Stream writer for real-time output
Provider Options
Specify provider-specific options for model behavior:Transforming Output for Models
Transform tool output before sending to the model:Next Steps
Tool Calling
Learn how to call tools from agents and workflows
MCP Overview
Connect tools via Model Context Protocol