mirror of
https://github.com/agentuniverse-ai/agentUniverse.git
synced 2026-02-09 01:59:19 +08:00
2.6 KiB
2.6 KiB
MCP工具
MCP工具是一类特殊的工具Tool,它通过调用MCPServer的Tool完成相应的任务。 MCPServer当前版本可分为三类通信模式,1)通过标准输入输出流(stdio)连接,2)通过SSE方式连接,3)通过Streamable HTTP连接,下列是各类不同MCP模式的配置yaml样例。
通过标准输入输出流连接的MCPTool定义示例如下:
name: 'calculator'
description: |
使用该工具可以执行搜索操作。工具的输入是你想搜索的内容。
server_name: 'demo_stdio_mcp_tool'
transport: 'stdio'
command: 'python'
args:
- 'stdio_server.py'
env:
TIMEOUT: 100
metadata:
type: 'TOOL'
module: 'agentuniverse.agent.action.tool.mcp_tool'
class: 'MCPTool'
通过SSE连接的MCPTool定义示例如下:
name: 'weather'
origin_tool_name: 'get_weather'
server_name: 'demo_http_mcp_tool'
transport: 'sse'
url: 'http://localhost:8000/sse'
metadata:
type: 'TOOL'
module: 'agentuniverse.agent.action.tool.mcp_tool'
class: 'MCPTool'
通过Streamable HTTP连接的MCPTool定义示例如下:
name: 'weather'
origin_tool_name: 'get_weather'
server_name: 'demo_http_mcp_tool'
transport: 'streamable_http'
url: 'http://localhost:8000/mcp'
metadata:
type: 'TOOL'
module: 'agentuniverse.agent.action.tool.mcp_tool'
class: 'MCPTool'
- 在MCPTool中,name除了表示agentUniverse中工具的名称,也表示MCPServer中工具的名称。如果您希望使用一个不一样的名字,您可以使用
origin_tool_name参数指定MCPServer中的真实工具名称 - description和普通Tool不同,允许为空。如果不主动填写,会使用MCPServer中对于该工具的描述作为默认description
- server_name用于标识一个唯一的MCPServer,统一server_name的MCPServer在请求过程中共享session
- transport取值分为
stdio、sse以及streamable_http,分别表示通过标准输入输出流、sse和streamable_http连接MCPServer。当transport取值为stdio时,需要配置command和args参数用于通过命令启动一个本地的MCPServer。env为可选参数,类型是dict,表示运行时的环境变量。当transport取值为sse和streamable_http时,您需要配置url参数用于连接一个远程的MCPServer
工具定义示例可参考:duckduckgo_search_mcp_tool
工具调用可参考示例:demo_agent_with_mcp_tool