Skip to content
AgentSearch

How to Add Web Search to a Haystack Agent (MCP, Free Tier, No API Key)

Haystack is deepset's open-source Python framework for building LLM pipelines, RAG systems and agents. Its Agent component takes a chat generator and a set of tools and loops until the model has an answer. What it doesn't give you out of the box is a cheap, keyless way to reach the live web. This guide adds Haystack agent web search with the official mcp-haystack integration (MCPToolset and MCPTool) and the AgentSearch MCP server.

Search works right away with no API key, no signup and no wallet. You get 25 free searches per IP in total, then pay per call. The 25 is a lifetime allowance and it never resets. When the agent needs a whole page, it gets clean markdown back, with a small free daily trial of extract (5 a day per IP) and pay-per-call pricing after that.

You'll build:

  1. An MCPToolset that starts npx -y @agentsearchhq/agentsearch-mcp over stdio.
  2. A tool filter, so the model only sees search, extract and search-and-read.
  3. A full Haystack Agent that searches and reads pages.
  4. A search-then-read script with no model in the loop.
  5. An optional paid setup with a hard budget.

What we actually ran (November 27, 2026): haystack-ai 3.5.0 and mcp-haystack 2.2.0 (with mcp 2.3.0) and @agentsearchhq/agentsearch-mcp 1.8.7 on Python 3.13 and Node 24. We connected MCPToolset, listed and filtered the tools, built the Agent with the filtered toolset, called the search tool directly once, and ran the search-then-read script below exactly as printed (two real free searches and one free-trial extract in total). We did not run a live model call. That step sends your prompt to the model provider, so it needs your own model key (for example OPENAI_API_KEY).

What the agent gets (and what it costs)

The AgentSearch MCP server exposes eight tools. For a research agent, three matter:

Tool What it does Cost
agentsearch_web_search Live web search, up to 5 results with title, URL and snippet 25 free searches per IP in total (never resets), then $0.003 per call over x402
agentsearch_extract Any public URL as clean markdown Free trial: 5 a day per IP, then $0.002 per call
agentsearch_search_and_read Search plus the page text of the top hits, in one call 10 free calls per IP in total (never resets), then $0.005 per call

There's no account and no API key at any tier, and no minimum spend. Paid calls use x402: the API answers with a 402 and a price, the MCP server signs a small USDC payment on Base, and you're only charged when a usable answer comes back. More on the Search and Extract pages.

Step 1: Install Haystack and the MCP integration

python -m venv .venv && source .venv/bin/activate
pip install "haystack-ai==3.5.0" "mcp-haystack==2.2.0"

Both packages need Python 3.11 or newer. mcp-haystack is deepset's official MCP integration from haystack-core-integrations. It pulls in the mcp SDK, and you import it from haystack_integrations.tools.mcp. haystack-ai already includes OpenAIChatGenerator; other model providers come as their own integration packages.

You also need Node.js 20 or newer, because the MCP server runs with npx.

Step 2: Connect the AgentSearch MCP server

StdioServerInfo describes how to start the server: a command plus a separate args list. MCPToolset wraps every tool the server offers as a Haystack Tool:

from haystack_integrations.tools.mcp import MCPToolset, StdioServerInfo

server = StdioServerInfo(command="npx", args=["-y", "@agentsearchhq/agentsearch-mcp"])
toolset = MCPToolset(server_info=server, connection_timeout=60)

toolset.warm_up()  # connect and load the tools
print(sorted(t.name for t in toolset))
toolset.close()

When we ran this, it printed all eight tools:

['agentsearch_extract', 'agentsearch_news_search', 'agentsearch_render',
 'agentsearch_review_lookup', 'agentsearch_review_submit', 'agentsearch_screenshot',
 'agentsearch_search_and_read', 'agentsearch_web_search']

Don't skip warm_up() if you want to inspect the tools yourself. MCPToolset connects lazily by default. Before warm-up, iterating it gives a single placeholder tool named mcp_not_connected_placeholder_..., not the real list. An Agent warms its tools up for you before a run, and eager_connect=True connects in the constructor instead. connection_timeout is in seconds (default 30); a generous value gives npx room on the first run, when it downloads the package.

Step 3: Give the agent only the right tools

Eight tools is more than a research agent needs, and every tool description goes into the model's context. tool_names keeps only the ones you name:

WEB_TOOLS = ["agentsearch_web_search", "agentsearch_extract", "agentsearch_search_and_read"]

web = MCPToolset(server_info=server, tool_names=WEB_TOOLS, connection_timeout=60)
web.warm_up()
print(sorted(t.name for t in web))
# ['agentsearch_extract', 'agentsearch_search_and_read', 'agentsearch_web_search']

Names must match the server's exactly, and they all start with agentsearch_. Unlike some frameworks, a typo isn't silently dropped: warm-up raises MCPToolNotFoundError and lists the tools that do exist. Leave tool_names out to load everything.

If you only want one tool, MCPTool wraps a single tool by name: MCPTool(name="agentsearch_web_search", server_info=server).

Pass the filtered toolset straight into Agent(tools=...):

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.tools.mcp import MCPToolset, StdioServerInfo

WEB_TOOLS = ["agentsearch_web_search", "agentsearch_extract", "agentsearch_search_and_read"]

web = MCPToolset(
    server_info=StdioServerInfo(command="npx", args=["-y", "@agentsearchhq/agentsearch-mcp"]),
    tool_names=WEB_TOOLS,
    connection_timeout=60,
    invocation_timeout=60,
)

agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-5.4-mini"),  # reads OPENAI_API_KEY
    tools=web,
    system_prompt=(
        "Use agentsearch_web_search for anything recent or factual. "
        "If a snippet isn't enough, read the page with agentsearch_extract. "
        "Use agentsearch_search_and_read when you need several pages at once. "
        "Cite the URLs you used."
    ),
    exit_conditions=["text"],
)

result = agent.run(
    messages=[ChatMessage.from_user("What's new in the latest Haystack release? Cite sources.")]
)
print(result["last_message"].text)
web.close()

Each MCP tool becomes a Haystack Tool with the server's own name, description and JSON schema, so the model sees the same arguments the server documents (query, max_results, freshness, include_domains and more for search; url and max_chars for extract). exit_conditions=["text"] ends the loop when the model replies with plain text instead of another tool call.

We built this exact agent and confirmed it holds the three filtered tools. The agent.run call is the part we didn't run. It needs your model key: OpenAIChatGenerator can be created without one, but warm-up fails with None of the following authentication environment variables are set: ('OPENAI_API_KEY',). Any Haystack chat generator that supports tools (Anthropic, Ollama, Amazon Bedrock, Google and others) works in its place.

Search, then read: no model in the loop

Sometimes you don't want a model deciding anything. You just want the top hit for a query, as markdown. Every tool in the toolset has an invoke() method you can call directly:

import json
from haystack_integrations.tools.mcp import MCPToolset, StdioServerInfo

def tool_json(result: str) -> dict:
    # invoke() returns the whole MCP result as a JSON string;
    # the tool's own JSON is the text of the first content block.
    return json.loads(json.loads(result)["content"][0]["text"])

def search_then_read(query: str) -> str:
    web = MCPToolset(
        server_info=StdioServerInfo(command="npx", args=["-y", "@agentsearchhq/agentsearch-mcp"]),
        tool_names=["agentsearch_web_search", "agentsearch_extract"],
        connection_timeout=60,
        invocation_timeout=60,
    )
    web.warm_up()
    tools = {t.name: t for t in web}
    try:
        hits = tool_json(tools["agentsearch_web_search"].invoke(query=query, max_results=3))
        top_url = hits["results"][0]["url"]
        page = tool_json(tools["agentsearch_extract"].invoke(url=top_url, max_chars=4000))
        return page["markdown"]
    finally:
        web.close()

print(search_then_read("haystack mcp-haystack MCPToolset")[:500])

This is the part we ran end to end. The search for "haystack mcp-haystack MCPToolset" came back with three results. The top one was the MCPTool page in the Haystack 3.5 documentation, and the extract call returned that page as markdown (starting with the docs site's navigation, so you may want to trim it). Each result also has title, content, domain and published_date, so you can pick a URL by domain instead of the first.

One gotcha we hit: invoke() doesn't return the tool's JSON. It returns the whole MCP CallToolResult serialized as a string, like {"_meta":null,"content":[{"type":"text","text":"{\n \"query\": ..."}]...}. The tool's JSON is a string inside that, so you parse twice, which is what tool_json does. (Inside an Agent this doesn't matter; the model just reads the text.)

You only pay to read the page you picked. If you'd rather get hits and page text in a single call, use agentsearch_search_and_read (10 free calls per IP in total, then $0.005 per paid call).

Going past the free tier: pay per call with x402

When the 25 free searches are used up, add a wallet. Use a new, dedicated wallet holding a few dollars of USDC on Base, never your main one. The MCP server reads these environment variables:

Variable What it does
AGENTSEARCH_WALLET_PRIVATE_KEY Key of the dedicated wallet. Turns on paid extract and the other paid tools.
AGENTSEARCH_MODE=paid Also makes search paid ($0.003 per call). A wallet key alone keeps search on the free tier.
AGENTSEARCH_MAX_TOTAL_ATOMIC Spend cap per server session in USDC atomic units (default 1000000, which is $1.00).
AGENTSEARCH_MAX_PER_CALL_ATOMIC Optional lower cap per call.

One detail: StdioServerInfo starts the server through the MCP SDK's stdio client, which does not forward your whole shell environment. It starts from a minimal safe set (HOME, PATH, USER and a few others) and merges in whatever you pass as env. So pass the wallet variables explicitly. Haystack's Secret keeps the key out of serialized pipelines:

from haystack.utils import Secret
from haystack_integrations.tools.mcp import MCPToolset, StdioServerInfo

server = StdioServerInfo(
    command="npx",
    args=["-y", "@agentsearchhq/agentsearch-mcp"],
    env={
        "AGENTSEARCH_WALLET_PRIVATE_KEY": Secret.from_env_var("AGENTSEARCH_WALLET_PRIVATE_KEY"),
        "AGENTSEARCH_MODE": "paid",
        "AGENTSEARCH_MAX_TOTAL_ATOMIC": "200000",  # $0.20 hard cap per session
    },
)
web = MCPToolset(
    server_info=server,
    tool_names=["agentsearch_web_search", "agentsearch_extract", "agentsearch_search_and_read"],
    connection_timeout=60,
)

Live prices on November 27, 2026: search $0.003, news $0.003, extract $0.002, search-and-read $0.005, all paid in USDC over x402 on Base. No signup, no API key, no minimums. Calls are only charged when a usable answer comes back. We checked the variable names against the package README. We didn't run a paid call for this post.

Troubleshooting

json.loads(result)["results"] raises KeyError. invoke() returns the full MCP result, not the tool's JSON. Parse json.loads(result)["content"][0]["text"] a second time, as tool_json does above.

Only an mcp_not_connected_placeholder_... tool. The toolset hasn't connected yet. Call warm_up() first, or pass eager_connect=True. An Agent does this for you.

MCPToolNotFoundError on warm-up. A name in tool_names doesn't exist on the server. The error lists the available tools; compare with Step 2's output.

npx: not found. Install Node.js 20+ and make sure it's on the PATH your Python process sees.

Timeouts on the first run. npx downloads the package the first time. Raise connection_timeout, or install it globally (npm i -g @agentsearchhq/agentsearch-mcp) and use command="agentsearch-mcp" with no args.

HTTP 429 from search or extract. You've used the free allowance: the 25 lifetime searches for your IP, the 10 lifetime search-and-read calls, or the daily extract trial (5). Add a wallet as shown above to keep going.

Wallet set but search still free. That's expected. Search only switches to paid with AGENTSEARCH_MODE=paid. Also check you passed the variables through env=, because they aren't forwarded automatically.

FAQ

Does Haystack agent web search need an API key?

Not with this setup. The AgentSearch MCP server gives you 25 free searches per IP in total with no key, account or wallet, then you pay per call over x402. You still need a key for whichever model drives the agent.

Can I use the tools in a Haystack Pipeline instead of an Agent?

Yes. MCPToolset is a regular Haystack Toolset, so you can add an Agent component to a Pipeline with tools=web, or pass the toolset to a chat generator and a ToolInvoker. With a bare chat generator, call warm_up() on the toolset first.

Get started

pip install "haystack-ai==3.5.0" "mcp-haystack==2.2.0"

Then point StdioServerInfo at npx -y @agentsearchhq/agentsearch-mcp, filter MCPToolset to the three web tools, and hand it to your Agent. You get 25 free searches per IP in total with no key, then $0.003 per paid search.

More from the blog

Service pages: Web Search API · Web Extract API · Search + Read API