Files
agentUniverse/docs/guidebook/zh/How-to/使用与发布MCP服务/如何使用MCP服务.md
2025-05-22 12:02:22 +08:00

2.9 KiB
Raw Blame History

如何在agentUniverse中使用MCP服务

在agentUniverse中您只需通过以下2个步骤即可将任意MCP服务接入并将其作为工具供智能体使用。

step1. 通过MCPToolkit将您指定MCP服务作为工具包接入

MCPServer当前版本可分为三类通信模式,1)通过标准输入输出流(stdio)连接2)通过SSE方式连接3通过Streamable HTTP连接下列是各类不同MCP模式的配置yaml样例。

1)标准输入输出流(stdio)模式连接示例如下:

name: 'docx_toolkit'
description: |
  这是一个docx相关的工具集
transport: 'stdio'
command: 'uvx'
args:
  - 'mcp-server-office'

metadata:
  type: 'TOOLKIT'
  module: 'agentuniverse.agent.action.toolkit.mcp_toolkit'
  class: 'MCPToolkit'

2SSE模式连接示例如下

name: 'search_toolkit'
description: |
  这是一个搜索相关的工具包
transport: 'sse'
url: 'http://localhost:8000/sse'

metadata:
  type: 'TOOLKIT'
  module: 'agentuniverse.agent.action.toolkit.mcp_toolkit'
  class: 'MCPToolkit'

3Streamable HTTP连接示例如下

name: 'weather'
transport: 'streamable_http'
url: 'http://localhost:8000/mcp'
metadata:
  type: 'TOOLKIT'
  module: 'agentuniverse.agent.action.toolkit.mcp_toolkit'
  class: 'MCPToolkit'
  • transporturlcommandargsenv等参数均与mcp官方定义一致。

step2. 将MCPToolkit配置给agent供agent使用MCP服务

通过步骤一我们已经将mcp服务接入了进一步您可以MCPToolkit配置给agent供agent使用MCP服务。

配置方式将您想使用的MCPToolkit列表挂载在agent配置文件的 [action->toolkit] 属性中。

下面是一个完整的示例配置在该agent中使用了步骤一中配置的stdio模式下的docx mcp服务。

info:
  name: 'demo_agent_with_mcp_toolkit'
  description: 'A simple demonstration react agent designed to showcase 
  the integration and usage of mcp toolkits.'
profile:
  prompt_version: qwen_react_agent.cn
  llm_model:
    name: 'qwen3-32b'
    stop: 'Observation'
    temperature: 0.1
action:
  toolkit:
    - 'docx_toolkit'
memory:
  name: 'demo_memory'
metadata:
  type: 'AGENT'
  module: 'agentuniverse.agent.template.react_agent_template'
  class: 'ReActAgentTemplate'

详细的案例app代码地址可以参考MCP使用样例appMCPToolkit接入您可参考配置文件, Agent配置MCPToolkit可参考配置文件,测试启动入口见文件

更多详细内容您可阅读文档MCP工具包MCP工具