模型上下文协议 (MCP) 中的传输定义了消息的发送和接收方式。Agno 集成支持已有的三种类型:
stdio,
SSE 和
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 with MCPTools(command=f"uvx mcp-server-git") as mcp_tools:
agent = Agent(model=OpenAIChat(id="gpt-4o"), tools=[mcp_tools])
await agent.aprint_response("What is the license for this project?", stream=True)
您也可以一次使用多个 MCP 服务器,使用 MultiMCPTools
类。例如:
import asyncio
import os
from agno.agent import Agent
from agno.tools.mcp import MultiMCPTools
async def run_agent(message: str) -> None:
"""使用给定的消息运行 Airbnb 和 Google Maps 代理。"""
env = {
**os.environ,
"GOOGLE_MAPS_API_KEY": os.getenv("GOOGLE_MAPS_API_KEY"),
}
async with MultiMCPTools(
[
"npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
"npx -y @modelcontextprotocol/server-google-maps",
],
env=env,
) as mcp_tools:
agent = Agent(
tools=[mcp_tools],
markdown=True,
show_tool_calls=True,
)
await agent.aprint_response(message, stream=True)
# 示例用法
if __name__ == "__main__":
# Pull request 示例
asyncio.run(
run_agent(
"What listings are available in Cape Town for 2 people for 3 nights from 1 to 4 August 2025?"
)
)
Responses are generated using AI and may contain mistakes.