---
title: "Mastra · Scrape.ly Docs"
description: "Give Mastra agents tools that run Actors and read their results."
url: https://scrape.ly/docs/mastra
markdown: https://scrape.ly/docs/mastra.md
---

# Mastra

> Give Mastra agents tools that run Actors and read their results.

Give Mastra agents Scrape.ly tools: search the Store, run Actors, wait for their runs, and read the results. Agents connect to the hosted [MCP server](https://scrape.ly/docs/mcp.md) through `@mastra/mcp`, so there is no Scrape.ly package to install.

```bash
npm install @mastra/core @mastra/mcp
```

Create an API token in the [dashboard](https://my.scrape.ly) under **Settings → API & Integrations** and set it as `SCRAPELY_TOKEN`. The agent can do anything the token can, including starting paid runs, so give it a scoped key: `actors:run`, `runs:read`, and `datasets:read`, with a **Max charge per day**. See [API keys & permissions](https://scrape.ly/docs/api-keys.md).

## Give an agent Scrape.ly tools

Create an `MCPClient` for the server and pass its tools to the agent. A `url` server uses the streamable HTTP transport, and `requestInit` sends the token with every request.

```ts
import { Agent } from '@mastra/core/agent';
import { MCPClient } from '@mastra/mcp';

const mcp = new MCPClient({
  servers: {
    scrapely: {
      url: new URL('https://mcp.scrape.ly'),
      requestInit: { headers: { Authorization: `Bearer ${process.env.SCRAPELY_TOKEN}` } },
    },
  },
});

const agent = new Agent({
  id: 'web-researcher',
  name: 'Web researcher',
  instructions: 'Find the right Actor in the Scrape.ly Store, run it, and report what its results show.',
  model: 'anthropic/claude-sonnet-5-5',
  tools: await mcp.listTools(),
});

try {
  const result = await agent.generate(
    "Find an Actor that scrapes Google Maps, run it for 'coffee shops in Berlin' with at most 20 results, " +
      'and list the name, rating, and address of each place.',
  );
  console.log(result.text);
} finally {
  await mcp.disconnect();
}
```

Any model Mastra supports works. See the [MCPClient reference](https://mastra.ai/reference/tools/mcp-client) for more options.

## What the agent can do

The agent gets the MCP server's default tools. The ones used most:

| Tool | What it does |
| --- | --- |
| `search-actors` | Find Actors in the Store by keywords. |
| `fetch-actor-details` | Read an Actor's input schema, README, and pricing before running it. |
| `call-actor` | Run an Actor with a JSON input, optionally with `maxItems` and `maxTotalChargeUsd`. |
| `get-actor-run` | Wait for a run and check its status. |
| `get-actor-output` | Read a run's results, paged and kept compact. |

The full list, including saved inputs and automations, is on the [MCP server](https://scrape.ly/docs/mcp.md#tools) page. To run one Actor you already know, name it in the prompt, for example `Run username/actor-name`, so the agent skips the search.

**Costs**: runs started by the agent are billed like any run. Put the limits in the prompt (such as "at most 20 results"), and keep a **Max charge per day** on the key.

---

- Previous: [Vercel AI SDK](https://scrape.ly/docs/vercel-ai-sdk.md)
- Next: [OpenAI Agents SDK](https://scrape.ly/docs/openai-agents-sdk.md)
- All docs: [Docs index](https://scrape.ly/docs.md), [llms.txt](https://scrape.ly/llms.txt)
