项目简介
WiseVision ROS2 MCP Server 是一个基于 Model Context Protocol (MCP) 构建的服务器,旨在为大型语言模型 (LLM) 提供与 ROS2 (Robot Operating System 2) 系统交互的能力。通过将 ROS2 的功能封装成 MCP 工具,该服务器允许 LLM 客户端以标准化的方式访问和控制 ROS2 系统,从而实现机器人应用的智能化。
主要功能点
- 主题列表 (Topic List): 列出当前可用的 ROS2 主题及其消息类型,帮助 LLM 理解 ROS2 系统的可用数据通道。
- 服务列表 (Service List): 列出当前可用的 ROS2 服务及其请求字段,允许 LLM 发现并调用 ROS2 服务以执行特定功能。
- 服务调用 (Service Call): 允许 LLM 调用指定的 ROS2 服务,并传递必要的参数,从而控制 ROS2 系统的行为。
- 主题订阅 (Topic Subscribe): 使 LLM 能够订阅 ROS2 主题,实时接收主题消息,从而获取 ROS2 系统的传感器数据或其他状态信息。
- 消息获取 (Message Get): 从 WiseVision Data Black Box (InfluxDB 替代方案) 获取指定主题的历史消息数据,为 LLM 提供更丰富的上下文信息。
- 消息字段获取 (Message Field Get): 获取 ROS2 消息类型的字段信息,帮助 LLM 理解消息结构,正确构造消息内容。
- 主题发布 (Topic Publish): 允许 LLM 向 ROS2 主题发布消息,从而向 ROS2 系统发送指令或数据。
- 主题消息回显等待 (Topic Echo Wait): 使 LLM 能够等待并接收来自特定 ROS2 主题的单条消息,用于验证发布结果或实时获取数据。
安装步骤
- 克隆仓库
git clone https://github.com/wise-vision/mcp_server_ros_2.git cd mcp_server_ros_2 - 构建 Docker 镜像
docker build -t wisevision/mcp_server_ros_2 .
服务器配置
MCP 客户端需要配置以下 JSON 以连接到 WiseVision ROS2 MCP Server:
{ "mcp_server_ros_2": { "command": "docker", "args": [ "run", "-i", "--rm", "wisevision/mcp_server_ros_2" ] } }
配置参数说明:
- server name: 'mcp_server_ros_2' (服务器名称,用于在 MCP 客户端中标识和调用)
- command: 'docker' (启动服务器的命令,这里使用 Docker 运行)
- args:
- 'run': Docker 运行命令
- '-i': 保持 STDIN 打开,即使未连接
- '--rm': 容器退出后自动删除
- 'wisevision/mcp_server_ros_2': Docker 镜像名称,与构建时指定的名称一致
基本使用方法
-
启动 MCP 服务器: MCP 客户端根据上述配置启动 WiseVision ROS2 MCP Server。
-
在 LLM Prompt 中指示使用工具: 在 LLM 的 Prompt 中添加类似以下指令,引导 LLM 使用 MCP 工具与 ROS2 系统交互:
You are an AI assistant that uses external tools via an MCP server. Before calling any tool, always check your memory to see if the list of available tools is known. • If you don’t have the current tool list in memory, your first action should be to call the list-tools tool. • Never guess tool names or parameters. • If a user requests something that may require a tool and you don’t have the right tool info, ask them or call list-tools first. Once the tool list is loaded, you may call tools directly using their documented names and schemas. -
LLM 调用工具: LLM 根据用户请求和工具描述,调用相应的 MCP 工具来完成与 ROS2 系统的交互任务。例如,LLM 可以调用 'ros2_topic_list' 工具获取主题列表,然后调用 'ros2_topic_subscribe' 工具订阅感兴趣的主题以获取数据。
信息
分类
桌面与硬件