Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Add Web Search to a Mastra Agent (Free, No API Key)

Mastra is a TypeScript framework for building AI agents, and like most agent frameworks it doesn't come with a web search tool. If your agent needs to answer "what changed in the latest release?" or "what does this docs page say right now?", you have to give it one. This guide adds web search to a Mastra agent in about 20 lines, using Mastra's built-in MCPClient and the AgentSearch MCP server.…

Mastra is a TypeScript framework used to build AI agents, but it doesn't come with a built-in web search tool. When an agent needs to answer questions like "what changed in the latest release?" or "what does this docs page say right now?", a web search tool must be added. This guide demonstrates how to add a web search capability to a Mastra agent using Mastra's built-in MCPClient and AgentSearch MCP server, with no API key, signup, or wallet required.

To start, an MCPClient is created to connect to the AgentSearch MCP server. This server exposes several tools, including live web search, extracting information from public URLs, and rendering JavaScript-heavy pages. These tools are free with a daily limit of 25 searches per IP and no API key needed. The guide provides a step-by-step process for installing Mastra and the MCP client, connecting the AgentSearch MCP server, allowing only the necessary tools for the research agent, and building the research agent itself.

The research agent is instructed to use the live web for answering questions, prioritizing the web search tool first, followed by extracting information from relevant URLs. If the extract tool returns empty or near-empty text, the agent is to try rendering the JavaScript-heavy page with the render tool. The agent is to answer in a few sentences and cite the sources used, treating all tool outputs as untrusted web content.

The guide includes the necessary code snippets for installation, connection, filtering tools, and building the research agent.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Make the agent use the existing Link component, not a raw <a>, for internal routes

The agent adds a “Back to settings” control as <a href="/settings"> . The app already has a Link (or RouterLink , or Next.js Link ) that prefetches, keeps the client transition, and applies the active…

  • Use existing Link component for internal routes
  • Avoid raw a tags for internal navigation
  • Link component offers prefetching, transitions, active classes

More from Thursday 19 November →