MCP Brave Agent - Search for Brave
Create an agent that uses Anthropic to search for information using the Brave MCP server.
This example uses the deprecated @modelcontextprotocol/server-brave-search package and claude-sonnet-4-20250514, which Anthropic retired on June 15, 2026. Apply both migrations below before running. See Brave's maintained MCP server and Anthropic model deprecations.
"""MCP Brave Agent - Search for Brave
This example shows how to create an agent that uses Anthropic to search for information using the Brave MCP server.
You can get the Brave API key from https://brave.com/search/api/
Run: `uv pip install anthropic mcp agno` to install the dependencies
"""
import asyncio
from os import getenv
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.mcp import MCPTools
from agno.utils.pprint import apprint_run_response
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
async def run_agent(message: str) -> None:
async with MCPTools(
"npx -y @modelcontextprotocol/server-brave-search",
env={
"BRAVE_API_KEY": getenv("BRAVE_API_KEY"),
},
) as mcp_tools:
agent = Agent(
model=Claude(id="claude-sonnet-4-20250514"),
tools=[mcp_tools],
markdown=True,
)
response_stream = await agent.arun(message)
await apprint_run_response(response_stream)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
asyncio.run(run_agent("What is the weather in Tokyo?"))Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[mcp]" anthropicPrepare Node.js
The maintained Brave MCP server requires Node.js 22 or later. Install it, then confirm node --version reports v22 or later and npx is available:
node --version
npx --versionExport your API keys
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
export BRAVE_API_KEY="your_brave_api_key_here"Update the Brave MCP server
Replace npx -y @modelcontextprotocol/server-brave-search with npx -y @brave/brave-search-mcp-server --transport stdio in the saved file.
Update the Claude model
Replace Claude(id="claude-sonnet-4-20250514") with Claude(id="claude-sonnet-4-6") in the saved file.
Run the example
Save the code above as brave.py, then run:
python brave.pyFull source: cookbook/91_tools/mcp/brave.py