Agno : コンセプト : ツール – MCP : トランスポート (stdio)

Model Context Protocol (MCP) のトランスポートはメッセージが送受信される方法を定義します。Agno 統合は 3 つの既存のタイプ: stdio, SSE と HTTP ストリーミング (Streamable HTTP) をサポートしています。

Agno : ユーザガイド : コンセプト : ツール – MCP : トランスポート (stdio)

作成 : クラスキャット・セールスインフォメーション
作成日時 : 08/07/2025
バージョン : Agno 1.7.7

* 本記事は docs.agno.com の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています :

* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

 

 

Agno ユーザガイド : コンセプト : ツール – MCP : トランスポート (stdio)

Model Context Protocol (MCP) のトランスポートはメッセージが送受信される方法を定義します。Agno 統合は 3 つの既存のタイプ: stdio, SSE と HTTP ストリーミング (Streamable HTTP) をサポートしています。

stdio (標準入出力) トランスポートは Agno 統合のデフォルトです。ローカル統合に対して最適に動作します。

使用するには、command 引数で MCPTools クラスを初期化するだけです。渡したいコマンドは、エージェントがアクセスする MCP サーバを実行するために使用されるものです。

例えば “uvx mcp-server-git” です、これは git MCP サーバ を実行します :

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

async def run_mcp_agent():
    # Initialize the MCP tools
    mcp_tools = MCPTools(command=f"uvx mcp-server-git")

    # Connect to the MCP server
    await mcp_tools.connect()

    # Initialize the Agent
    agent = Agent(model=OpenAIChat(id="gpt-4o"), tools=[mcp_tools])

    # Run the agent
    await agent.aprint_response("What is the license for this project?", stream=True)

    # Close the MCP connection
    await mcp_tools.close()

MultiMCPTools クラスを使用して、複数の MCP サーバを同時に使用することもできます。例えば :

import asyncio
import os

from agno.agent import Agent
from agno.tools.mcp import MultiMCPTools


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

    env = {
        **os.environ,
        "GOOGLE_MAPS_API_KEY": os.getenv("GOOGLE_MAPS_API_KEY"),
    }

    # Initialize the MultiMCPTools instance
    multi_mcp_tools = MultiMCPTools(
        [
            "npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
            "npx -y @modelcontextprotocol/server-google-maps",
        ],
        env=env,
    )

    # Connect to the MCP servers
    await multi_mcp_tools.connect()

    # Initialize the Agent
    agent = Agent(
        tools=[mcp_tools],
        markdown=True,
        show_tool_calls=True,
    )

    # Run the agent
    await agent.aprint_response(message, stream=True)

    # Close the MCP connections
    await multi_mcp_tools.close()


# Example usage
if __name__ == "__main__":
    # Pull request example
    asyncio.run(
        run_agent(
            "What listings are available in Cape Town for 2 people for 3 nights from 1 to 4 August 2025?"
        )
    )

 

以上