Skip to main content
Build a TypeScript research agent with Mastra that searches the web, reads the pages it cites, and answers with links. You start without an API key, add typed tools and filters, and then connect the same agent to Keenable’s remote MCP server instead of a package.

Before you start

You need Node 20 or later, a Mastra project, and a key for the model the agent runs on. The examples use openai/gpt-5 through Mastra’s model router, which reads OPENAI_API_KEY. Any tool-calling model works. Keenable needs no key. Without one, calls share the keyless limit for your IP address. See Keyless access.

Step 1: give the agent web search, keyless

Install the tools package:
createKeenableTools() returns keenableSearch and keenableFetch. Pass them to the agent:
src/mastra/agents/research-agent.ts
Ask it something that needs the web. Give it room for several tool calls with maxSteps: with Mastra’s default, an agent that searches and then reads a few pages can run out of steps before it answers, and result.text comes back empty.
The agent sets the filters itself. Its first search sent site: "blog.rust-lang.org" and publishedAfter: "2026-10-01"; it then fetched each release post and answered:
Output

Step 2: use the typed tools and filters

Each tool is a Mastra tool with Zod schemas, so you can also call it from your own code, and Mastra checks the input and the output against the schemas. Create one tool at a time when you want different settings per tool:
The search tool takes these filters. The agent sees the same names and descriptions, and picks them per call: Each result has title, url, description (page text, cut to 500 characters by default), publishedAt and acquiredAt. The fetch tool takes a url and returns the page as markdown in content, with title, description, author, publishedAt, image and favicon when the page has them. queryTime suits evaluations and backtests: an agent that answers “what was known on 1 June” gets only pages Keenable had indexed by then.

Step 3: connect Keenable’s remote MCP server

Instead of the package, an agent can take its tools from Keenable’s hosted MCP server through @mastra/mcp. Use this when you already manage tools through MCP, or want the MCP tool set, which adds a fetch prompt and max_chars:
src/mastra/agents/mcp-research-agent.ts
listTools() prefixes each tool with the server name: keenable_search_web_pages, keenable_fetch_page_content and keenable_get_billing. Asked for the latest stable Rust release, this agent searched with published_after, read five pages from the Rust blog in one fetch call, and answered with Rust 1.100.1, 27 November 2026, and the link.

Add an API key

A key lifts the keyless hourly cap. Create one under API keys in the console. For the package, set KEENABLE_API_KEY in the environment, or pass it to a factory:
For the MCP server, send it in the X-API-Key header:
See rate limits and pricing for what a key changes.

Next steps