
AI Development
AdsCrawl for Mastra
Expose AdsCrawl as a Mastra tool with explicit input and output schemas. Agents can request a URL and receive rendered Markdown with its source, while your application keeps browser access in server-side code.
What you can do
Schema-defined inputs
Accept a validated URL through Mastra’s createTool interface.
Structured tool results
Return source and markdown fields with an outputSchema for downstream consumers.
Reusable agent tools
Register the same tool in a Mastra agent, or call it from application code.
Before you start
- An AdsCrawl account with an API key and available credits.
- Node.js 22.22 or newer, running on your server or local development machine.
SETUP METHOD 01
Define a Mastra tool
Combine createTool, Zod schemas and the AdsCrawl JavaScript SDK. Test the tool before attaching a model.
Install dependencies
Run this in your application directory.
npm install adscrawl @mastra/core zodConfigure your API key
Set the variables in your server environment or local shell. Replace the placeholders with your own keys; keep them out of browser bundles and source control.
export ADSCRAWL_API_KEY="your_adscrawl_api_key"Save mastra-web.mjs
The execute handler receives the validated input directly. This standalone example invokes the tool and prints its structured result.
import AdsCrawl from "adscrawl"; import { createTool } from "@mastra/core/tools"; import { z } from "zod"; const browser = new AdsCrawl({ apiKey: process.env.ADSCRAWL_API_KEY }); export const readWebPage = createTool({ id: "read-web-page", description: "Read a public web page as browser-rendered Markdown.", inputSchema: z.object({ url: z.string().url() }), outputSchema: z.object({ source: z.string().url(), markdown: z.string() }), execute: async ({ url }) => { const markdown = await browser.markdown({ url, waitUntil: "domcontentloaded", }); if (!markdown.trim()) throw new Error("The page returned no text"); return { source: url, markdown }; }, }); const result = await readWebPage.execute({ url: "https://example.com" }, {}); console.log(result);Run and connect the next step
Expect an object with source and Markdown headed Example Domain. Add readWebPage to your Mastra agent’s tools object, for example tools: { readWebPage }, and configure the agent’s model separately.
node mastra-web.mjs
Usage & limits
- The example runs a tool directly; it does not create a Mastra agent, model provider or durable workflow. Those remain part of your application configuration.
- Each page request uses AdsCrawl credits. These examples fetch one public URL; JavaScript-rendered pages may need a different waitUntil setting or additional browser interactions.
- Keep the source URL with the content. For longer pages, choose a chunking or context-budget strategy before passing text to a model.