Skip to main content
Exa provides a hosted MCP server for high-quality web search and content retrieval. It is the first tutorial in this section that needs a key of its own — Exa’s is free to obtain and has a free usage tier. It is also the first of the three authentication shapes you will meet across these examples: Exa takes its key as a query parameter, Semgrep takes a Bearer header, and Firecrawl takes a path segment. Same Agent, three different URL constructions.

Prerequisites

Build it

1

Install and set both keys

2

Build the URL from the environment

The key ends up inside the URL string. Read it from the environment and never print the constructed value — a logged URL is a leaked key.
3

Write a prompt that makes it cite

A search tool does not by itself produce sourced answers. This is the prompt that does:
The last sentence matters most. Fabricated URLs are the characteristic failure of search agents, and they are far more convincing than a fabricated fact.
4

Create the agent

max_loops=2 gives the model room to search, read what came back, and then answer.
5

Run a query that requires recency

The complete script

Keeping the key out of the URL

If embedding a secret in a URL makes you uncomfortable — and it should, given how often URLs end up in logs — the same key can be sent as a Bearer token on servers that accept one:
The env: prefix tells swarms to read the value from the environment at connection time, so the secret never appears in your source. See authentication patterns for every shape, including custom headers and OAuth.

Cost control

Search calls are billed per request, and an agent left to its own devices will happily run six searches where two would do.

Next