[ clawifi for mastra ]
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.
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_freesearches many engines as one and returns ranked results with their sources. - Read:
fetch_urlandscrape_urlread pages and PDFs as Markdown; with aquery,scrape_urlreturns only the passages that answer it. - Parse and discover:
extract_urlpulls structured fields from a page;map_sitelists a site’s URLs;start_crawlandget_crawlread several pages. - Jobs, history and monitors:
create_job,get_job,list_historyandlist_monitorsfor longer runs and scheduled checks. - Cost first:
estimateprices 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. 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/mcppackage (Mastra MCP docs).npm install @mastra/mcp @mastra/core3. Connect Clawifi and give its tools to an agent
MCPClientconnects to the hosted server over Streamable HTTP; the key goes inrequestInit.headers, and only whenCLAWIFI_API_KEYis set. Replace the model with one you use.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_freeandclawifi_fetch_url.
Sources for this setup: Remote MCP · Mastra MCP docs. 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.
Other agents and frameworks#
Next: Integrations · Docs · Pricing