Skip to main content
The Model Context Protocol (MCP) enables Agents to interact with external systems through a standardized interface. You can connect your Agents to any MCP server, using Agno’s MCP integration. This simple example shows how to connect an Agent to the Agno MCP server:
agno_agent.py
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.mcp import MCPTools

# Create the Agent
agno_agent = Agent(
    name="Agno Agent",
    model=Claude(id="claude-sonnet-4-0"),
    # Add the Agno MCP server to the Agent
    tools=[MCPTools(transport="streamable-http", url="https://docs.agno.com/mcp")],
)

Usage

1

Find the MCP server you want to use

You can use any working MCP server. To see some examples, you can check this GitHub repository, by the maintainers of the MCP themselves.
2

Initialize the MCP integration

Initialize the MCPTools class and connect to the MCP server. The recommended way to define the MCP server is to use the command or url parameters. With command, you can pass the command used to run the MCP server you want. With url, you can pass the URL of the running MCP server you want to use.For example, to connect to the Agno documentation MCP server, you can do the following:
from agno.tools.mcp import MCPTools

# Initialize and connect to the MCP server
mcp_tools = MCPTools(transport="streamable-http", url="https://docs.agno.com/mcp"))
await mcp_tools.connect()
3

Provide the MCPTools to the Agent

When initializing the Agent, pass the MCPTools instance in the tools parameter. Remember to close the connection when you’re done.The agent will now be ready to use the MCP server:
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools

# Initialize and connect to the MCP server
mcp_tools = MCPTools(url="https://docs.agno.com/mcp")
await mcp_tools.connect()

try:
    # Setup and run the agent
    agent = Agent(model=OpenAIChat(id="gpt-5-mini"), tools=[mcp_tools])
    await agent.aprint_response("Tell me more about MCP support in Agno", stream=True)
finally:
    # Always close the connection when done
    await mcp_tools.close()

Example: Filesystem Agent

Here’s a filesystem agent that uses the Filesystem MCP server to explore and analyze files:
filesystem_agent.py
import asyncio
from pathlib import Path
from textwrap import dedent

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools


async def run_agent(message: str) -> None:
    """Run the filesystem agent with the given message."""

    file_path = "<path to the directory you want to explore>"

    # Initialize and connect to the MCP server to access the filesystem
    mcp_tools = MCPTools(command=f"npx -y @modelcontextprotocol/server-filesystem {file_path}")
    await mcp_tools.connect()

    try:
        agent = Agent(
            model=OpenAIChat(id="gpt-5-mini"),
            tools=[mcp_tools],
            instructions=dedent("""\
                You are a filesystem assistant. Help users explore files and directories.

                - Navigate the filesystem to answer questions
                - Use the list_allowed_directories tool to find directories that you can access
                - Provide clear context about files you examine
                - Use headings to organize your responses
                - Be concise and focus on relevant information\
            """),
            markdown=True,
        )

        # Run the agent
        await agent.aprint_response(message, stream=True)
    finally:
        # Always close the connection when done
        await mcp_tools.close()


# Example usage
if __name__ == "__main__":
    # Basic example - exploring project license
    asyncio.run(run_agent("What is the license for this project?"))

Connecting your MCP server

Using connect() and close()

You should use the connect() and close() methods to connect and disconnect from the MCP server. This is the recommended way to setup your MCP server.
mcp_tools = MCPTools(command="uvx mcp-server-git")
await mcp_tools.connect()
After you’re done, you should close the connection to the MCP server.
await mcp_tools.close()

Using Async Context Manager

If you prefer, you can also use MCPTools or MultiMCPTools as async context managers for automatic resource cleanup:
async with MCPTools(command="uvx mcp-server-git") as mcp_tools:
    agent = Agent(model=OpenAIChat(id="gpt-5-mini"), tools=[mcp_tools])
    await agent.aprint_response("What is the license for this project?", stream=True)
This pattern automatically handles connection and cleanup, but the explicit .connect() and .close() methods provide more control over connection lifecycle.

Transports

Transports in the Model Context Protocol (MCP) define how messages are sent and received. The Agno integration supports the three existing types:
The stdio (standard input/output) transport is the default one in Agno’s MCPTools and MultiMCPTools.

Best Practices

  1. Resource Cleanup: Always close MCP connections when done to prevent resource leaks:
mcp_tools = MCPTools(command="uvx mcp-server-git")
await mcp_tools.connect()

try:
    # Your agent code here
    pass
finally:
    await mcp_tools.close()
  1. Error Handling: Always include proper error handling for MCP server connections and operations.
  2. Clear Instructions: Provide clear and specific instructions to your agent:
instructions = """
You are a filesystem assistant. Help users explore files and directories.
- Navigate the filesystem to answer questions
- Use the list_allowed_directories tool to find accessible directories
- Provide clear context about files you examine
- Be concise and focus on relevant information
"""

Developer Resources

  • See how to use MCP with AgentOS here.
  • Find examples of Agents that use MCP here.
  • Find a collection of MCP servers here.
I