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

# Serve agents as MCP tools

> Turn the default MCP surface off and serve agents directly as tools.

Turn the default MCP surface off and serve agents directly as tools. A bare agent in MCPConfig(tools=\[...]) becomes a tool named after its id with the agent's own description; agent.as\_tool(name=..., description=...) publishes it under a model-facing name and pitch of your choosing instead. An MCP client sees chief and deep\_research -- not run\_agent(agent\_id=...) -- and each call runs through the same machinery as the default run tools (fresh session minting, scope checks, progress). continue\_run and cancel\_run ride along automatically so paused (human-in-the-loop) runs stay resumable; set lifecycle\_tools=False to serve exactly the configured tools.

```python agents_as_tools.py theme={null}
"""
Serve agents as MCP tools
=========================

Turn the default MCP surface off and serve agents directly as tools. A bare
agent in MCPConfig(tools=[...]) becomes a tool named after its id with the
agent's own description; agent.as_tool(name=..., description=...) publishes
it under a model-facing name and pitch of your choosing instead. An MCP
client sees chief and deep_research -- not run_agent(agent_id=...) -- and
each call runs through the same machinery as the default run tools (fresh
session minting, scope checks, progress). continue_run and cancel_run ride
along automatically so paused (human-in-the-loop) runs stay resumable; set
lifecycle_tools=False to serve exactly the configured tools.

as_tool also carries the presentation a client and a marketplace reviewer
read: title= is the display name, and annotations= are the behaviour hints
(readOnlyHint, destructiveHint, idempotentHint, openWorldHint) merged over
the defaults a published component asserts about itself.

Prerequisites: OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/14_mcp/agents_as_tools.py
Try: connect an MCP client to http://localhost:7777/mcp and call chief or deep_research
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS, MCPConfig

# ---------------------------------------------------------------------------
# Create the agents to expose
# ---------------------------------------------------------------------------

db = SqliteDb(
    id="mcp-agents-as-tools-db",
    db_file="tmp/mcp_agents_as_tools.db",
)

chief = Agent(
    id="chief",
    name="Chief",
    model=OpenAIResponses(id="gpt-5.6-luna"),
    db=db,
    description="Answers executive questions and delegates follow-ups.",
    instructions="Answer briefly and decisively.",
    # Every exposed tool tells the client "pass session_id back to continue the
    # conversation" -- history in context is what makes that promise real.
    add_history_to_context=True,
)

researcher = Agent(
    id="researcher",
    name="Researcher",
    model=OpenAIResponses(id="gpt-5.6-luna"),
    db=db,
    description="Digs into a topic and returns sourced findings.",
    instructions="Be thorough and cite what you rely on.",
    add_history_to_context=True,
)

# ---------------------------------------------------------------------------
# Serve the agents as the only MCP tools
# ---------------------------------------------------------------------------

agent_os = AgentOS(
    id="mcp-agents-as-tools-os",
    description="AgentOS serving its agents directly as MCP tools.",
    db=db,
    agents=[chief, researcher],
    mcp=MCPConfig(
        default_tools=False,
        tools=[
            chief,
            researcher.as_tool(
                name="deep_research",
                title="Deep Research",
                description="Thorough, sourced research. Send one clear question.",
                # Hints are published to the client and read by assistant marketplaces
                # during a listing review, which test them against what the tool really
                # does -- so a wrong hint is worse than a missing one. The researcher
                # holds no tools and only appends to its own session, so it refines the
                # default rather than contradicting it: still not read-only (every run
                # writes a session and a run row), but nothing it writes destroys
                # anything, and running it twice is not the same as running it once.
                annotations={"destructiveHint": False, "idempotentHint": False},
            ),
        ],
    ),
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Agents-as-Tools AgentOS
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app=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]" openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

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

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

Full source: [cookbook/05\_agent\_os/14\_mcp/agents\_as\_tools.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/05_agent_os/14_mcp/agents_as_tools.py)
