> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Tools Advanced Example

> Run an AgentOS support agent wired to both a remote Agno docs MCP server and a stdio Brave Search MCP server.

AgentOS handles the lifespan of the MCPTools internally.

<Warning>
  This example uses the deprecated `@modelcontextprotocol/server-brave-search` package in its active and commented MCP configurations. Replace both occurrences with Brave's maintained MCP server before running. See [Brave Search MCP Server](https://github.com/brave/brave-search-mcp-server).
</Warning>

```python mcp_tools_advanced_example.py theme={null}
"""
Example AgentOS app where the agent has MCPTools.

AgentOS handles the lifespan of the MCPTools internally.
"""

from os import getenv

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.anthropic import Claude
from agno.os import AgentOS
from agno.tools.mcp import MCPTools  # noqa: F401

# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------

# Setup the database
db = SqliteDb(db_file="tmp/agentos.db")

agno_mcp_tools = MCPTools(transport="streamable-http", url="https://docs.agno.com/mcp")

# Example: Brave Search MCP server
brave_mcp_tools = MCPTools(
    command="npx -y @modelcontextprotocol/server-brave-search",
    env={
        "BRAVE_API_KEY": getenv("BRAVE_API_KEY"),
    },
    timeout_seconds=60,
)

# You can also use MultiMCPTools to connect to multiple MCP servers at once:
#
# from agno.tools.mcp import MultiMCPTools
# mcp_tools = MultiMCPTools(
#     commands=["npx -y @modelcontextprotocol/server-brave-search"],
#     urls=["https://docs.agno.com/mcp"],
#     env={"BRAVE_API_KEY": getenv("BRAVE_API_KEY")},
# )

# Setup ai framework agent
ai_framework_agent = Agent(
    id="agno-support-agent",
    name="Agno Support Agent",
    model=Claude(id="claude-sonnet-4-5"),
    db=db,
    tools=[brave_mcp_tools, agno_mcp_tools],
    add_history_to_context=True,
    num_history_runs=3,
    markdown=True,
)

agent_os = AgentOS(
    description="Example app with MCP Tools",
    agents=[ai_framework_agent],
)


app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    """Run your AgentOS.

    You can see test your AgentOS at:
    http://localhost:7777/docs

    """
    # Don't use reload=True here, this can cause issues with the lifespan
    agent_os.serve(app="mcp_tools_advanced_example:app")
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[mcp,os]" anthropic
    ```
  </Step>

  <Step title="Prepare 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:

    ```bash theme={null}
    node --version
    npx --version
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
      export BRAVE_API_KEY="your_brave_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
      $Env:BRAVE_API_KEY="your_brave_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Update both Brave MCP commands">
    Replace both occurrences of `npx -y @modelcontextprotocol/server-brave-search` with `npx -y @brave/brave-search-mcp-server --transport stdio` in the saved file.
  </Step>

  <Step title="Run the example">
    Save the code above as `mcp_tools_advanced_example.py`, then run:

    ```bash theme={null}
    python mcp_tools_advanced_example.py
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/mcp\_demo/mcp\_tools\_advanced\_example.py](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/mcp_demo/mcp_tools_advanced_example.py)
