Skip to main content
All integrations

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

01

Schema-defined inputs

Accept a validated URL through Mastra’s createTool interface.

02

Structured tool results

Return source and markdown fields with an outputSchema for downstream consumers.

03

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.

  1. Install dependencies

    Run this in your application directory.

    Shell
    npm install adscrawl @mastra/core zod
  2. Configure 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.

    Shell
    export ADSCRAWL_API_KEY="your_adscrawl_api_key"
  3. Save mastra-web.mjs

    The execute handler receives the validated input directly. This standalone example invokes the tool and prints its structured result.

    JavaScript
    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);
  4. 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.

    Shell
    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.
See pricing and credit conversion

Further reading

Mastra documentationAdsCrawl JavaScript / TypeScript SDK