3.1 KiB
Step 2: Setting Up Rosbridge
Rosbridge runs on the robot's machine (wherever ROS is running). It provides a WebSocket interface that the MCP server on your machine connects to over the network.
Prerequisite: ROS must already be installed on the robot's machine. If you don't have ROS installed and want to try things out quickly, see the Turtlesim Docker example which runs ROS and rosbridge in a container.
Important — rosbridge and rosapi are both required. ros-mcp-server needs
rosbridge_server(the WebSocket interface) androsapi(the introspection services behindget_nodes,get_topics,get_services,detect_ros_version, parameter tools, etc.). The launch file used below starts both automatically. Do not start rosbridge withros2 run rosbridge_server .../rosrun rosbridge_server ...— those bring up the WebSocket withoutrosapi, and every introspection tool will fail with "Service does not exist". Theros-<distro>-rosbridge-serverpackage pullsrosapiin as a dependency; if in doubt, install the fullros-<distro>-rosbridge-suitemetapackage.
Install rosbridge_server
For ROS 2 Jazzy:
# Update package list
sudo apt update
# Install rosbridge for ROS2 Jazzy
sudo apt install ros-jazzy-rosbridge-server
For other ROS 2 distros:
# Install rosbridge for ROS2 Humble
sudo apt install ros-humble-rosbridge-server
# Install for other ROS distros
sudo apt install ros-<your-distro>-rosbridge-server
Using ROS 1? See ROS 1 instructions at the bottom of this page.
Launch rosbridge
source your ROS workspace first to ensure that the rosbridge has access to your ROS system.
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
Don't forget to
sourceyour ROS workspace before launching, especially if you're using custom messages or services.
Verify rosbridge is running
From the robot's machine:
curl -I http://localhost:9090
A successful response confirms rosbridge is listening on its default port (9090).
Also confirm rosapi is running — its services must be present for the MCP tools to work:
# ROS 2
ros2 service list | grep rosapi
# ROS 1
rosservice list | grep rosapi
If this prints nothing, you launched rosbridge without rosapi — use the ros2 launch / roslaunch command above rather than ros2 run / rosrun.
Next Step
Connect to your robot and test it out: Step 3: Connect
Advanced
ROS 1 (End of Life)
Install rosbridge_server
For ROS Noetic:
sudo apt install ros-noetic-rosbridge-server
For other ROS 1 distros:
sudo apt install ros-<your-distro>-rosbridge-server
Launch rosbridge
roslaunch rosbridge_server rosbridge_websocket.launch
Don't forget to
sourceyour ROS workspace before launching, especially if you're using custom messages or services.