Skip to Content
ExamplesWorkflows (Legacy)Using a Tool as a Step

Tool as a Workflow step (Legacy)

This example demonstrates how to create and integrate a custom tool as a workflow step, showing how to define input/output schemas and implement the tool’s execution logic.

import { createTool } from "@mastra/core/tools"; import { LegacyWorkflow } from "@mastra/core/workflows/legacy"; import { z } from "zod"; const crawlWebpage = createTool({ id: "Crawl Webpage", description: "Crawls a webpage and extracts the text content", inputSchema: z.object({ url: z.string().url(), }), outputSchema: z.object({ rawText: z.string(), }), execute: async ({ context }) => { const response = await fetch(context.triggerData.url); const text = await response.text(); return { rawText: "This is the text content of the webpage: " + text }; }, }); const contentWorkflow = new LegacyWorkflow({ name: "content-review" }); contentWorkflow.step(crawlWebpage).commit(); const { start } = contentWorkflow.createRun(); const res = await start({ triggerData: { url: "https://example.com" } }); console.log(res.results);





View Example on GitHub