# Web search and page reading for Mastra

> Connect a Mastra agent to Clawifi’s hosted MCP server with MCPClient, and it can search the web, read pages and PDFs, and get back the passages that answer each question, with sources.

Canonical page: https://clawifi.dev/for/mastra

## What Clawifi gives Mastra

A Mastra agent works with the tools you give it. Clawifi adds web search, page reading and passage selection as MCP tools, so the agent can check current sources and cite them.

- **Search:** `search_free` searches many engines as one and returns ranked results with their sources.
- **Read:** `fetch_url` and `scrape_url` read pages and PDFs as Markdown; with a `query`, `scrape_url` returns only the passages that answer it.
- **Parse and discover:** `extract_url` pulls structured fields from a page; `map_site` lists a site’s URLs; `start_crawl` and `get_crawl` read several pages.
- **Jobs, history and monitors:** `create_job`, `get_job`, `list_history` and `list_monitors` for longer runs and scheduled checks.
- **Cost first:** `estimate` prices a call before it runs, and the account tools show your credits.

## Set it up

### 1. Get an API key

Create an account at [clawifi.dev/signup](https://clawifi.dev/signup). The Free plan includes 1,000 credits a month. Copy the key the console shows you (it is shown once) and keep it in an environment variable, `CLAWIFI_API_KEY`.

### 2. Install the MCP client

Mastra’s MCP client is the `@mastra/mcp` package ([Mastra MCP docs](https://mastra.ai/docs/mcp/overview)).

**Terminal**

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

### 3. Connect Clawifi and give its tools to an agent

`MCPClient` connects to the hosted server over Streamable HTTP; the key goes in `requestInit.headers`, and only when `CLAWIFI_API_KEY` is set. Replace the model with one you use.

**agent.ts**

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

const key = process.env.CLAWIFI_API_KEY;

const mcp = new MCPClient({
  servers: {
    clawifi: {
      url: new URL("https://api.clawifi.dev/mcp"),
      // without a key, send no header: the four trial tools still run
      ...(key ? { requestInit: { headers: { Authorization: `Bearer ${key}` } } } : {}),
    },
  },
});

export const researchAgent = new Agent({
  id: "research-agent",
  name: "Research agent",
  instructions: "Answer with sources. Use Clawifi to search the web and read pages.",
  model: "your-provider/your-model",
  tools: await mcp.listTools(),
});
```

### 4. Ask it something

Call the agent with a question that needs the web. The tools arrive named by server, for example `clawifi_search_free` and `clawifi_fetch_url`.

Sources for this setup: [Remote MCP](https://clawifi.dev/docs/remote-mcp) · [Mastra MCP docs](https://mastra.ai/docs/mcp/overview). Clawifi works with Mastra; it is not affiliated with its makers.

## Example prompts

> Search the web for this week’s release notes of the framework we use and list the breaking changes, each with its source link.

> Read https://mastra.ai/docs/mcp/overview and return only the passages about authentication.

> Map https://docs.python.org/3/library/ and list the first 20 URLs, then read the asyncio page and summarise it.

## Questions

### How do I connect Clawifi to Mastra?

Create an `MCPClient` with a `clawifi` server whose `url` is `new URL("https://api.clawifi.dev/mcp")` and whose `requestInit.headers` carry `Authorization: Bearer <your key>`, then pass `await mcp.listTools()` to the agent’s `tools`.

### Each user has their own Clawifi key. What now?

Create the client per request with that user’s key and pass `await mcp.listToolsets()` as `toolsets` when you call the agent, instead of fixing `tools` in the constructor.

### Can I try it without a key?

Yes. When `CLAWIFI_API_KEY` is not set, the code above sends no Authorization header. Without a key, only `search_free`, `fetch_url`, `scrape_url` and `map_site` run, as a trial: 12 calls a minute and 50 a day per address. The other tools are still listed, but calling one without a key fails with an authorization error, so add your key before you rely on them.

### What does it cost?

Each tool call is billed like the API route it runs: most cost 1 credit and a browser render 3. Cache hits, failures on Clawifi’s side and answers with nothing to read (a blocked page, a JavaScript shell, a 404) cost 0. The Free plan includes 1,000 credits a month. See [Pricing](https://clawifi.dev/pricing).

## Other agents and frameworks

- [Clawifi for Continue](https://clawifi.dev/for/continue): Add Clawifi to Continue as an MCP server, and its agent can search the web, read docs pages and PDFs, and get back the passages that answer each question, with sources.
- [Clawifi for Gumloop](https://clawifi.dev/for/gumloop): Add Clawifi to Gumloop as a custom MCP connector, and your agents can search the web, read pages and PDFs, and get back the passages that answer each question, with sources.
- [Clawifi for Lindy](https://clawifi.dev/for/lindy): Connect Clawifi to Lindy as an MCP server, and your agents can search the web, read pages and PDFs, and get back the passages that answer each question, with sources.
- [All agent guides](https://clawifi.dev/for): Every client and framework.

Next: [Integrations](https://clawifi.dev/integrations) · [Docs](https://clawifi.dev/docs) · [Pricing](https://clawifi.dev/pricing)
