> ## 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.

# Enable AgentOS MCP

> AgentOS with the MCP server enabled, plus an agent client that authenticates and operates it.

## Code

Secure the instance with `OS_SECURITY_KEY`. Every request to the API and to `/mcp` must then carry `Authorization: Bearer <key>`.

```python mcp_server_example.py theme={null}
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.websearch import WebSearchTools

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

# Setup basic research agent
web_research_agent = Agent(
    id="web-research-agent",
    name="Web Research Agent",
    model=Claude(id="claude-sonnet-4-5"),
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
    enable_session_summaries=True,
    markdown=True,
)

# Setup AgentOS with MCP enabled
agent_os = AgentOS(
    description="Example app with MCP enabled",
    agents=[web_research_agent],
    mcp_server=True,  # This enables an LLM-friendly MCP server at /mcp
)

app = agent_os.get_app()

if __name__ == "__main__":
    # MCP server available at http://localhost:7777/mcp
    agent_os.serve(app="mcp_server_example:app")
```

## Define a Local Test Client

The client connects to `/mcp` with the security key in the `Authorization` header and drives the [built-in tools](/agent-os/mcp/mcp#built-in-tools).

```python test_client.py theme={null}
import asyncio
from os import getenv
from uuid import uuid4

from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.models.openai import OpenAIResponses
from agno.tools.mcp import MCPTools, StreamableHTTPClientParams

# Authenticate against the secured AgentOS with the security key
server_params = StreamableHTTPClientParams(
    url="http://localhost:7777/mcp",
    headers={"Authorization": f"Bearer {getenv('OS_SECURITY_KEY')}"},
)

session_id = f"session_{uuid4()}"


async def run_agent() -> None:
    async with MCPTools(
        transport="streamable-http", server_params=server_params, timeout_seconds=60
    ) as mcp_tools:
        agent = Agent(
            model=OpenAIResponses(id="gpt-5.5"),
            tools=[mcp_tools],
            instructions=[
                "You operate an AgentOS through its MCP tools.",
                "Call get_agentos_config first to discover the agents, teams, and workflows you can run.",
                "Use the run tools to delegate work, and the session tools to review past conversations.",
            ],
            user_id="john@example.com",
            session_id=session_id,
            db=InMemoryDb(),
            add_history_to_context=True,
            markdown=True,
        )

        await agent.aprint_response(
            input="Which agents do I have in my AgentOS?", stream=True, markdown=True
        )


if __name__ == "__main__":
    asyncio.run(run_agent())
```

## Usage

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

  <Step title="Set Environment Variables">
    ```bash theme={null}
    export ANTHROPIC_API_KEY=your_anthropic_api_key
    export OPENAI_API_KEY=your_openai_api_key
    export OS_SECURITY_KEY=your_security_key
    ```
  </Step>

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

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

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

  <Step title="Run Test Client">
    ```bash theme={null}
    python test_client.py
    ```
  </Step>
</Steps>
