Integrations
ros2-mcp-server
ros2-mcp-server
is a Python-based server that integrates the Model Context Protocol (MCP) with ROS 2, enabling AI assistants to control robots via ROS 2 topics. It processes commands through FastMCP and runs as a ROS 2 node, publishing geometry_msgs/Twist
messages to the /cmd_vel
topic to control robot movement.
This implementation supports commands like "move forward at 0.2 m/s for 5 seconds and stop," with the /cmd_vel
publisher named pub_cmd_vel
.
Features
- MCP Integration: Uses FastMCP to handle commands from MCP clients (e.g., Claude).
- ROS 2 Native: Operates as a ROS 2 node, directly publishing to
/cmd_vel
. - Time-Based Control: Supports duration-based movement commands (e.g., move for a specified time and stop).
- Asynchronous Processing: Combines FastMCP's
asyncio
with ROS 2's event loop for efficient operation.
Prerequisites
- ROS 2: Humble distribution installed and sourced.
- Python: Version 3.10 (required for compatibility with ROS 2 Humble).
- uv: Python package manager for dependency management.
- Dependencies:
rclpy
: ROS 2 Python client library (installed with ROS 2).fastmcp
: FastMCP framework for MCP server implementation.numpy
: Required by ROS 2 message types.
Installation
- Clone the Repository:Copy
- Python Version Configuration:
This project uses Python 3.10 as required by ROS 2 Humble. The
.python-version
file is already configured:Copy - Project Dependencies:
The
pyproject.toml
file is configured with the necessary dependencies:Copy - Create uv Environment:Copy
- Activate the Virtual Environment:You'll seeCopy
(.venv)
appear at the beginning of your command prompt, indicating that the virtual environment is active. - Install Dependencies:Copy
MCP Server Configuration
To use this server with Claude or other MCP clients, you need to configure it as an MCP server. Here's how to set it up:
For Claude Desktop
- Open Claude Desktop settings and navigate to the MCP servers section.
- Add a new MCP server with the following configuration:Important: ReplaceCopy
/path/to/ros2-mcp-server
with the actual path to your repository. For example, if you cloned the repository to/home/user/projects/ros2-mcp-server
, you would use that path instead. - Save the configuration and restart Claude.
For Cline (VSCode Extension)
- In VSCode, open the Cline extension settings by clicking on the Cline icon in the sidebar.
- Navigate to the MCP servers configuration section.
- Add a new MCP server with the following configuration:Important: ReplaceCopy
/path/to/ros2-mcp-server
with the actual path to your repository, as in the Claude Desktop example. - You can immediately toggle the server on/off and verify the connection directly from the Cline MCP settings interface without needing to restart VSCode or reload the extension.
Usage
Once the MCP server is configured, you can use Claude to send commands to the robot:
- Example Command:
Ask Claude to move the robot forward at 0.2 m/s for 5 seconds:Copy
- Direct Tool Usage:
You can also use the
move_robot
tool directly:Copy - Monitor ROS 2 Topics:
Verify the
/cmd_vel
topic output:Copy
Testing
- With a Simulator:
- Launch a ROS 2-compatible simulator (e.g., Gazebo with TurtleBot3):Copy
- Use Claude to send movement commands.
- Observe the robot moving in Gazebo.
- Launch a ROS 2-compatible simulator (e.g., Gazebo with TurtleBot3):
- With a Real Robot:
- Ensure your robot is properly set up to subscribe to the
/cmd_vel
topic. - Use Claude to send movement commands.
- The robot should move according to the commands.
- Ensure your robot is properly set up to subscribe to the
- Expected Output:
- The server logs movement commands and stop commands.
- Claude receives a response like:
"Successfully moved for 5.0 seconds and stopped"
.
Troubleshooting
- ROS 2 Logging Errors: If you encounter logging directory errors, ensure the
ROS_LOG_DIR
environment variable is set to a writable directory (e.g.,/tmp
). - Python Version Mismatch: Ensure you're using Python 3.10, as ROS 2 Humble is built for this version.
- Connection Errors: If Claude reports "Connection closed" errors, check that the MCP server configuration is correct and that all dependencies are installed.
Directory Structure
Limitations
- Single Topic: Currently supports
/cmd_vel
withTwist
messages. Extendros2-mcp-server.py
for other topics or services. - Basic Commands: Currently supports simple movement commands. More complex behaviors would require additional implementation.
License
Note that this project uses FastMCP, which is licensed under the Apache License 2.0. The terms of that license also apply to the use of FastMCP components.
Acknowledgments
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
A Python-based server that enables AI assistants to control robots by integrating the Model Context Protocol (MCP) with ROS 2, allowing for natural language commands that translate into robot movement via the /cmd_vel topic.
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol (MCP) integration that allows AI assistants to control Home Assistant devices by searching for entities and controlling devices through natural language commands.Last updated -10PythonMIT License
- AsecurityAlicenseAqualityAn MCP (Model Context Protocol) server that integrates with the ArgoCD API, enabling AI assistants and large language models to manage ArgoCD applications and resources through natural language interactions.Last updated -106PythonMIT License
- AsecurityAlicenseAqualityA server that enables AI assistants to execute terminal commands and retrieve outputs via the Model Context Protocol (MCP).Last updated -36PythonMIT License
- -securityFlicense-qualityA Model Context Protocol server that allows AI assistants to interact with Prefect's workflow automation platform through natural language, enabling users to manage flows, deployments, tasks, and other Prefect resources via conversational commands.Last updated -4Python