Robust ROS 2 MCP server enabling AI-driven robot control with FastMCP integration and time-based commands
ROS2-MCP-Server is a Python-based server that integrates the Model Context Protocol (MCP) with Robot Operating System (ROS) 2. This integration enables advanced AI applications to leverage ROS 2 for controlling robots, providing a flexible and powerful solution for robotics in various domains such as autonomous navigation, object detection, and more. By using MCP, this server acts as an intermediary between AI-driven commands from clients like Claude Desktop and the actual robot movement, making it a crucial component in AI-enabled robotic systems.
ROS2-MCP-Server offers several key features that enhance its utility for both developers and users:
MCP Integration: The server leverages the FastMCP framework to handle commands from various MCP clients. This ensures seamless communication between AI applications and ROS nodes, facilitating real-time data exchange and control.
ROS 2 Native: Operating as a ROS 2 node, it directly publishes geometry_msgs/Twist
messages to the /cmd_vel
topic for controlling robot movement. This native integration allows for precise control over the robot’s actions based on AI-generated commands.
Time-Based Control: Supports complex command structures like moving forward at 0.2 m/s for 5 seconds, enabling sophisticated behaviors that go beyond simple linear movements.
Asynchronous Processing: By combining FastMCP's asyncio
with ROS 2's event loop, the server ensures efficient and responsive handling of incoming commands from multiple clients simultaneously.
The architecture of ROS2-MCP-Server is built around several key components:
FastMCP Framework: This library forms the backbone for parsing and executing commands sent by MCP clients like Claude Desktop or Continue. It ensures that incoming commands are handled in a structured and efficient manner.
ROS 2 Node Integration: The server operates as a ROS 2 node, subscribing to relevant topics and publishing movements through the /cmd_vel
topic. This integration leverages ROS 2’s robust messaging system for real-time control.
Command Parsing & Execution: The core of ROS2-MCP-Server is its ability to parse MCP commands and execute them in a reliable manner. This process involves validating inputs, mapping them to appropriate control actions, and ensuring they are executed within the specified timeframe.
To get up and running with ROS2-MCP-Server, follow these steps:
Clone the Repository:
git clone https://github.com/kakimochi/ros2-mcp-server.git
cd ros2-mcp-server
Set Python Version: Ensure the project uses Python 3.10 as required by ROS 2 Humble.
# .python-version content
3.10
Install Dependencies: Use uv
to manage dependencies effectively.
uv venv --python /usr/bin/python3.10
source .venv/bin/activate
uv pip install -e .
Configuration and Startup:
Configure the server based on your specific MCP client (like Claude Desktop):
For Claude Desktop:
"ros2-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "uv",
"args": [
"--directory",
"/path/to/ros2-mcp-server",
"run",
"bash",
"-c",
"export ROS_LOG_DIR=/tmp && source /opt/ros/humble/setup.bash && python3 /path/to/ros2-mcp-server/ros2-mcp-server.py"
],
"transportType": "stdio"
}
For Cline (VSCode Extension):
"ros2-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "uv",
"args": [
"--directory",
"/path/to/ros2-mcp-server",
"run",
"bash",
"-c",
"export ROS_LOG_DIR=/tmp && source /opt/ros/humble/setup.bash && python3 /path/to/ros2-mcp-server/ros2-mcp-server.py"
],
"transportType": "stdio"
}
Imagine an autonomous warehouse robot tasked with picking and packing items. Using ROS2-MCP-Server, MCP commands from an AI application can instruct the robot to navigate autonomously, stop at specific areas for task execution, and resume movement when done.
{
"linear": [0.3, 0.0, 0.0],
"angular": [0.0, 0.0, 0.0],
"duration": 60.0
}
In a smart factory setting, real-time object detection using AI can trigger precise avoidance maneuvers for mobile robots to navigate safely through dynamic environments.
{
"linear": [0.2, 0.0, 0.0],
"angular": [-1.57, 0.0, 0.0], // rotating 90 degrees to the left
"duration": 30.0
}
ROS2-MCP-Server supports integration with multiple AI applications through its MCP protocol implementation:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[ROS 2 Node]
D --> E[Robot Movement / Tool Control]
The server ensures compatibility with various AI applications:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ❌ |
Cursor | ✅ | ✅ | ❌ |
For advanced users, configuring ROS2-MCP-Server involves setting up environment variables and optimizing command execution:
Environment Variables: Define API keys and other critical information securely.
"env": {
"API_KEY": "your-api-key"
}
Custom Command Handling: Customize the commands to cater to specific requirements.
def handle_command(command):
# Custom logic for executing MCP commands
pass
Can I integrate ROS2-MCP-Server with any AI application?
What happens if multiple commands come in at the same time?
How do I ensure data privacy during MCP communication?
Can I customize the behavior of ROS2-MCP-Server for my specific use case?
How does the server handle errors in MCP commands?
Contributing to ROS2-MCP-Server allows you to enhance its capabilities and integrate it more effectively into your AI workflows:
Setup Development Environment: Clone the repository, install dependencies, and set up Python 3.10.
git clone https://github.com/kakimochi/ros2-mcp-server.git
cd ros2-mcp-server
uv venv --python /usr/bin/python3.10
source .venv/bin/activate
uv pip install -e .
Contributing Code:
For further exploration, refer to these resources:
By integrating advanced AI applications with ROS 2 robots using ROS2-MCP-Server, developers can unlock a new era of robotics where intelligent decision-making is the norm. The MCP protocol ensures smooth and reliable communication between AI-driven commands and robotic actions, making this server a vital component in modern autonomous systems.
This comprehensive documentation positions ROS2-MCP-Server as an essential tool for AI application integration, ensuring clarity on its capabilities, installation process, and use cases.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Explore community contributions to MCP including clients, servers, and projects for seamless integration
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Integrate AI with GitHub using MCP Server for profiles repos and issue creation
Python MCP client for testing servers avoid message limits and customize with API key
Explore MCP servers for weather data and DigitalOcean management with easy setup and API tools