Stdio Transport

Connect MCPTools to a local MCP server over stdio using the command parameter.

The stdio (standard input/output) transport is the default one in Agno's integration. It works best for local integrations.

To use it, simply initialize the MCPTools class with the command argument. The command you want to pass is the one used to run the MCP server the agent will have access to.

Prerequisites

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install the Python dependencies and Node.js, then verify the runtimes used by the examples:

uv pip install -U "agno[mcp]" openai
uvx --version
node --version
npx --version
export OPENAI_API_KEY="your_openai_api_key_here"
export GOOGLE_MAPS_API_KEY="your_google_maps_api_key_here"

The @modelcontextprotocol/server-google-maps npm package is deprecated and no longer supported. The multi-server snippet below documents the legacy server. Use a maintained Maps MCP server for new projects.

For example, uvx mcp-server-git runs a Git MCP server:

import asyncio

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

async def main():
    async with MCPTools(command="uvx mcp-server-git") as mcp_tools:
        agent = Agent(model=OpenAIResponses(id="gpt-5.2"), tools=[mcp_tools])
        await agent.aprint_response(
            "What is the license for this project?",
            stream=True,
        )

asyncio.run(main())

Use one MCPTools instance per server when an agent needs tools from several servers:

import asyncio
import os
from datetime import date, timedelta

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


async def run_agent(message: str) -> None:
    """Run the Airbnb and Google Maps agent with the given message."""

    maps_env = {
        **os.environ,
        "GOOGLE_MAPS_API_KEY": os.environ["GOOGLE_MAPS_API_KEY"],
    }

    async with (
        MCPTools(
            command="npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt"
        ) as airbnb_tools,
        MCPTools(
            command="npx -y @modelcontextprotocol/server-google-maps",
            env=maps_env,
        ) as maps_tools,
    ):
        agent = Agent(
            model=OpenAIResponses(id="gpt-5.2"),
            tools=[airbnb_tools, maps_tools],
            markdown=True,
        )
        await agent.aprint_response(message, stream=True)


# Example usage
if __name__ == "__main__":
    check_in = date.today() + timedelta(days=30)
    check_out = check_in + timedelta(days=3)
    asyncio.run(
        run_agent(
            f"What listings are available in Cape Town for 2 people "
            f"from {check_in.isoformat()} to {check_out.isoformat()}?"
        )
    )