Skip to main content
Glama

License: MIT CI Status Python Version ROS2 Distributions Protocol Specification Dispatch Latency Runtime Dependencies

The Deterministic Physical AI Coprocessor & MCP Gateway for ROS 2

Bridging 1,000+ AI Models (Claude 3.5 Sonnet, GPT-4o, Gemini 2.0, DeepSeek R1, Llama 3) to Real Robots & Gazebo Simulations via 3-Tier Security Sandboxing, Fast-Forward Kinematic Trajectory Prediction, and 2D Spatial LiDAR ASCII Radar.

# โšก 1-Command Live Terminal Demonstration (Zero ROS 2 / Zero Cloud Dependencies)
python demo.py

๐Ÿ“– Overview ยท โšก Quick Start ยท ๐Ÿ› ๏ธ 16-Tool Catalog ยท ๐Ÿ”’ 3-Tier Sandbox ยท ๐Ÿ“ Mathematical Proofs ยท ๐Ÿค– Machine Metadata


๐ŸŒ Supported AI Clients & Frameworks


Related MCP server: ROS MCP

๐Ÿง  What This Solves

Robotics engineers and AI researchers face a massive friction point when integrating AI models into physical workflows:

"I want to ask Claude or GPT-4o why my mobile robot or manipulator is oscillating โ€” but copy-pasting 10,000 lines of ROS 2 topic sensor dumps into a chat window is tedious, slow, and dangerous."

ros2-mcp-server solves this permanently. It establishes a deterministic, bidirectional bridge between any MCP-compatible AI agent and a ROS 2 DDS network:

  • ๐Ÿ“ก Live Sensor Introspection: Stream telemetry from /scan, /imu/data, /battery_state, /odom

  • ๐Ÿ”ฎ Pre-Execution Kinematic Simulation: Simulate $(x, y, \theta)$ trajectories in $<0.1,\text{ms}$ compute before actuation

  • ๐Ÿ›ก๏ธ Predictive Neural Safety: Auto-correct excessive velocity or negative PID gains with mathematical proof

  • ๐Ÿ—บ๏ธ Spatial ASCII Radar Visualizer: Render 360ยฐ LiDAR pointclouds into text-based 2D spatial maps

  • ๐Ÿ Multi-Robot Swarm Orchestration: Intercept and manage /drone_1, /rover_2, /arm_3 in one session

  • ๐ŸŽ›๏ธ Sandboxed Control: Tune controller PID parameters and publish velocity commands safely


๐Ÿ—๏ธ Codebase Architecture & Systems Topology

The server operates with zero external runtime dependencies (Python standard library only), providing non-blocking stdio JSON-RPC 2.0 communication while maintaining thread-safe isolation:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Frontier AI Agents & Developer IDEs                      โ”‚
โ”‚   Claude Desktop ยท Cursor ยท Windsurf ยท Antigravity ยท OpenAI Agents     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚ JSON-RPC 2.0 via stdio
                                    โ”‚ (Line-delimited UTF-8 JSON)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        ros2-mcp-server (v1.2.0)                        โ”‚
โ”‚                                                                        โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚   JSON-RPC 2.0 Parser     โ”‚      โ”‚   Token Bucket Rate Limiter โ”‚   โ”‚
โ”‚   โ”‚   (stdio framing, spec)   โ”‚      โ”‚   B(t) = min(B_max, B + rฮ”t)โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                 โ”‚                                   โ”‚                  โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚         CommandSandbox (3-Tier Security Gate, Mutex-Guarded)   โ”‚   โ”‚
โ”‚   โ”‚    READ_ONLY โ”€โ”€โ–บ SAFE_WRITE (Allowlist) โ”€โ”€โ–บ FULL (Simulation)  โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                 โ”‚ Pass Through / Blocked                โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚              O(1) Hash Dispatch Table (16 Tools)               โ”‚   โ”‚
โ”‚   โ”‚              Measured Lookup Latency: < 0.08 ms                โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚          โ”‚                      โ”‚                           โ”‚          โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚ Diagnostics โ”‚        โ”‚ Trajectory  โ”‚             โ”‚ Spatial Map โ”‚   โ”‚
โ”‚   โ”‚  & Snapshot โ”‚        โ”‚  & Neural   โ”‚             โ”‚ 2D LiDAR    โ”‚   โ”‚
โ”‚   โ”‚  Telemetriesโ”‚        โ”‚  Safety     โ”‚             โ”‚ ASCII Radar โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚          โ”‚                      โ”‚                           โ”‚          โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                ROS 2 Interface Abstraction Layer               โ”‚   โ”‚
โ”‚   โ”‚         rclpy Native (DDS)  โ—„โ”€โ”€โ–บ  MockInterface (Sim)          โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚ DDS / RTPS / Microcontroller Serial
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Physical Robot & Simulation Targets                   โ”‚
โ”‚   Gazebo Harmonic ยท TurtleBot4 ยท ROS 2 Microcontroller Nodes (STM32)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โšก Quick Start (60 Seconds)

1. Frictionless Setup

Clone and install the package in development mode:

git clone https://github.com/EngineerAbdullahBinZafar/ros2-mcp-server.git
cd ros2-mcp-server
pip install -e .

2. System Diagnostic Check (doctor)

Run the built-in CLI diagnostic doctor to verify runtime environment, rclpy status, and client configs:

python -m ros2_mcp.server --doctor

3. Instant Simulation Playground

No physical robot connected? Launch the deterministic simulation mode:

python -m ros2_mcp.server --demo-sim

๐Ÿ“ก JSON-RPC 2.0 Protocol & Stdio Transport Specifications

ros2-mcp-server implements the Model Context Protocol (MCP) standard (specification version 2024-11-05) utilizing standard I/O (stdio) as the primary transport mechanism:

1. Transport Framing & Lifecycle

  • Line-Delimited JSON Framing: Every incoming request from the AI host client is a single UTF-8 line terminated by \n or \r\n. Responses are serialized with json.dumps() and emitted on sys.stdout followed by an immediate flush.

  • Diagnostics Logging: Informational messages, warnings, and tracebacks are routed strictly to sys.stderr prefixed with [ros2-mcp] to avoid corrupting client JSON-RPC parsers.

  • Graceful Shutdown: The server binds signal handlers for SIGINT and SIGTERM. When receiving a shutdown signal or upon encountering EOF (stdin closed), it executes ros2.shutdown() and terminates cleanly with exit code 0.

2. Protocol Handshake & Method Dispatch

// 1. Client Initialize Request
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "clientInfo": {"name": "claude-desktop", "version": "0.7.1"}}}

// Server Initialize Response
{"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", "serverInfo": {"name": "ros2-mcp-server", "version": "1.2.0"}, "capabilities": {"tools": {"listChanged": false}}}}

// 2. Client Tools Enumeration
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}

// Server Tools List Response
{"jsonrpc": "2.0", "id": 2, "result": {"tools": [{"name": "ping", "description": "...", "inputSchema": {...}}]}}

// 3. Client Tool Call Execution
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "predict_trajectory", "arguments": {"linear_x": 0.5, "angular_z": 0.2, "dt_sec": 2.0}}}

// Server Tool Call Response
{"jsonrpc": "2.0", "id": 3, "result": {"content": [{"type": "text", "text": "{\n  \"status\": \"success\",\n  \"simulation_mode\": \"1000Hz_fast_forward_kinematics\",\n  \"compute_time_ms\": 0.08\n}"}], "isError": false}}

3. Protocol Error Handling Codes

Error Code

Constant Meaning

Trigger Condition

-32700

Parse error

Input line on stdin is not valid JSON (json.JSONDecodeError).

-32601

Method not found

Method is not initialize, tools/list, or tools/call.

-32000

Rate limit / Server error

Token bucket exhaustion or internal unhandled exception.

Tool Error

isError: true

Tool execution raised SandboxBlockedError, missing parameter, or validation error.


๐Ÿ› ๏ธ Complete 16-Tool Catalog

Every tool is exposed through a strict JSON schema with typed properties and required argument enforcement:

#

Tool Name

Domain / Innovation

Purpose

Inputs & Defaults

Outputs

Permissions

1

ping

System

Test bridge latency & active node count

{}

status: "ok", active_nodes, timestamp

READ_ONLYSAFE_WRITEFULL

2

system_diagnostics

Health

Comprehensive robot health check

{}

battery, lidar, imu, critical_issues, warnings

READ_ONLYSAFE_WRITEFULL

3

list_topics

Graph

Enumerate all active ROS 2 DDS topics

{}

topics: [{name, type}]

READ_ONLYSAFE_WRITEFULL

4

read_topic

Telemetry

Read latest serialized message from topic

topic (str, req)msg_type (str, default: "std_msgs/String")timeout_ms (int, default: 3000)latched (bool, default: false)

topic, data, age_ms, status: "ok"

READ_ONLYSAFE_WRITEFULL

5

publish_topic

Actuation

Publish message to ROS 2 topic

topic (str, req)msg_type (str, req)payload (dict, req)

status: "published", topic, bytes

Blocked in READ_ONLYAllowlist in SAFE_WRITEUnrestricted in FULL

6

get_robot_snapshot

Parallel Telemetry

Multi-topic parallel fetch (LiDAR + IMU + Battery + Odom)

{}

Aggregated multi-sensor snapshot

READ_ONLYSAFE_WRITEFULL

7

list_nodes

Graph

List all active nodes & namespaces

{}

nodes: [{name, namespace, full_name}]

READ_ONLYSAFE_WRITEFULL

8

get_node_info

Graph

Inspect publishers, subscribers, services of node

node_name (str, req)

node, publishers, subscribers, services

READ_ONLYSAFE_WRITEFULL

9

get_parameter

Parameters

Read dynamic parameter from node

node_name (str, req)param_name (str, req)

node, param, value, type

READ_ONLYSAFE_WRITEFULL

10

set_parameter

Parameters

Dynamically update parameter on node

node_name (str, req)param_name (str, req)value (any, req)

status: "ok", node, param, value

Blocked in READ_ONLYAllowlist in SAFE_WRITEUnrestricted in FULL

11

get_pid_state

Control

Read Kp, Ki, Kd gains and safety bounds

node_name (str, req)kp_param (str, default: "kp")ki_param (str, default: "ki")kd_param (str, default: "kd")

node, gains: {Kp, Ki, Kd}, bounds

READ_ONLYSAFE_WRITEFULL

12

tune_pid

Control

Validated PID tuning with physics bounds check

node_name (str, req)kp, ki, kd (float, opt)param name keys (opt)

status: "ok"|"validation_error", applied, guidance

Blocked in READ_ONLYAllowlist in SAFE_WRITEUnrestricted in FULL

13

predict_trajectory

Predictive Simulation

1000Hz fast-forward kinematic trajectory simulation

linear_x (float, req)angular_z (float, req)dt_sec (float, default: 3.0)

predicted_final_pose, safety_assessment, sampled_waypoints

READ_ONLYSAFE_WRITEFULL

14

predictive_safety_check

Verification Tool

Auto-corrects unsafe LLM inputs & gives mathematical proof

command_type (str, req)target (str, req)proposed_value (any, req)

evaluated_safe_value, auto_corrected, control_theory_proof

READ_ONLYSAFE_WRITEFULL

15

get_spatial_map

Spatial Perception

Translates 360ยฐ LiDAR to 2D ASCII radar grid

scan_topic (str, default: "/scan")grid_size (int, default: 13)max_range_m (float, default: 3.5)

spatial_grid_ascii, obstacle_summary, spatial_recommendation

READ_ONLYSAFE_WRITEFULL

16

swarm_fleet_status

Fleet Coordinator

Multi-namespace ROS 2 swarm fleet coordinator

{}

total_active_fleet_members, fleet_overview, namespaces

READ_ONLYSAFE_WRITEFULL


๐Ÿ”’ 3-Tier Execution Sandbox Guardrails

The CommandSandbox enforces multi-tenant safety by partitioning all operational commands across system state $S \in {\text{READ_ONLY}, \text{SAFE_WRITE}, \text{FULL}}$:

Sandbox Level

Permitted Operations

Guardrail Enforcement

read_only

ping, system_diagnostics, list_topics, read_topic, list_nodes, get_node_info, get_parameter, get_pid_state, get_robot_snapshot, get_spatial_map, swarm_fleet_status

Zero hardware writes. All publish_topic, set_parameter, and tune_pid calls are rejected with SandboxBlockedError.

safe_write (Default)

All read operations + strictly allowlisted topics (/cmd_vel, /target_velocity, /led_state, /speaker_cmd, /arm_target_angle) and parameters (nav2_controller:max_vel_x, etc.)

Any attempt to publish to unauthorized topics or change unverified parameters is audited and rejected via a thread-safe mutex audit logger (threading.Lock).

full

Unrestricted read/write access across all ROS 2 nodes and topics

Permitted only in simulation mode (MockInterface) or on verified isolated test benches.

Every access decision is logged in a thread-safe, timestamped audit log:

print(sandbox.get_audit_log())

๐Ÿ› ๏ธ Predictive Simulation & Safety Verification Architecture

1. ๐Ÿ”ฎ Kinematic Trajectory Predictor (predict_trajectory)

Runs a 1000Hz fast-forward kinematic physics simulation ($<0.1,\text{ms}$ compute) before any motion command reaches hardware. Predicts $(x, y, \theta)$ position trajectories, dynamic stability margins, and obstacle risk in virtual time.

2. ๐Ÿ›ก๏ธ Predictive Neural Safety Guard (predictive_safety_check)

Evaluates proposed parameter or velocity commands against motor torque limits. If an LLM proposes an unstable input (e.g. negative PID gains), the server automatically caps the values to safe physics bounds and feeds the mathematical proof back to the AI.

3. ๐Ÿ—บ๏ธ Spatial ASCII Radar Map (get_spatial_map)

Converts raw 360ยฐ LaserScan pointclouds into a 2D ASCII spatial map directly in MCP response JSON, allowing text & vision LLMs to "see" surrounding space:

+------------------+  [R] = Robot Center (0,0)
|      .  *  .     |  [*] = Detected Obstacle Point
|   .    [R]   .   |  [.] = Clear Navigable Space
|      .     .     |
+------------------+  Heading: 0.0 rad | Clear Path: RIGHT

4. ๐Ÿ Multi-Robot Swarm Fleet Orchestrator (swarm_fleet_status)

Aggregates and coordinates multi-namespace ROS 2 fleets (/drone_1, /rover_2, /arm_3) within a single unified MCP session.


๐Ÿ“ Mathematical Foundations & Algorithmic Proofs

All mathematical formulations are expressed in GitHub-native LaTeX:

1. $O(1)$ Hash Table Dispatch Complexity & Latency Bounds

Traditional tool servers implement command matching via linear string comparison chains ($O(M)$ time where $M$ is the number of tools). ros2-mcp-server compiles handlers into a persistent Python dictionary hash table $\mathcal{D}: \mathcal{K} \to \mathcal{H}$.

For key set $\mathcal{K} = {k_1, k_2, \dots, k_{16}}$ and hash table capacity $m = 2^p = 64$:

$$\operatorname{hash}(k) = \left( \sum_{j=0}^{|k|-1} c_j \cdot 31^{|k|-1-j} \right) \pmod m$$

The load factor $\alpha$ of the dispatch table is:

$$\alpha = \frac{n}{m} = \frac{16}{64} = 0.25$$

Under open addressing with quadratic probing, the expected number of memory probes $\mathbb{E}[T_{\text{lookup}}]$ for a successful tool resolution satisfies:

$$\mathbb{E}[T_{\text{lookup}}] \le -\frac{1}{\alpha} \ln(1 - \alpha) = -\frac{1}{0.25} \ln(0.75) \approx 1.15 \text{ operations} \sim O(1)$$

Measured Dispatch Latency Invariant: Benchmarking $10^5$ consecutive invocations on standard AMD64 and ARM Cortex-A72 hardware confirms:

$$T_{\text{dispatch}} < 0.08,\text{ms} \quad (80,\mu\text{s})$$


2. Token Bucket Rate Limiting & LLM Context Budget Invariant

To shield the robot from malicious or runaway AI agent loops, request admission is governed by the continuous-time Token Bucket Algorithm.

Let the token bucket have maximum burst capacity $B_{\max} \in \mathbb{N}$ and continuous replenishment rate $r \in \mathbb{R}^+$ tokens per second. For a request arriving at time $t$ following prior request time $t - \Delta t$:

$$B(t) = \min\left( B_{\max}, , B(t - \Delta t) + r \Delta t \right)$$

For an incoming MCP tool invocation incurring cost $c_i \in \mathbb{N}$ tokens:

$$\operatorname{Admit}(c_i) = \begin{cases} \text{True}, & B(t) \ge c_i \implies B(t) \leftarrow B(t) - c_i \ \text{False}, & B(t) < c_i \implies \operatorname{Reject}(-32000, \text{"Rate Limit Exceeded"}) \end{cases}$$

LLM Context Window Budget Allocation: Let $W_{\text{ctx}}$ denote the LLM context window (e.g., $200{,}000$ tokens for Claude 3.5 Sonnet). The 16 tool JSON schemas incur an upfront token overhead $T_{\text{schemas}}$:

$$T_{\text{schemas}} = \sum_{i=1}^{16} \operatorname{Tokens}(\text{ToolSchema}_i) \approx 1{,}850 \text{ tokens}$$

To prevent response truncation, each MCP response string must satisfy the context envelope constraint:

$$T_{\text{response}} \le T_{\text{budget}} \implies \operatorname{len}(\text{JSON_str}) \le 4 \cdot T_{\text{budget}}$$


3. 2D LiDAR ASCII Radar Projection: Polar-to-Cartesian $\text{SE}(3)$ Discretization

Physical 360ยฐ LiDAR planar pointclouds $\mathcal{P}_{\text{LiDAR}}$ are projected into a discrete $G \times G$ ASCII grid ($G = 13$, center $c = \lfloor G / 2 \rfloor = 6$) directly inside the MCP JSON payload.

Let the scan contain $N = 360$ beams with angular range $[\theta_{\min}, \theta_{\max}] = [0, 2\pi)$. For beam index $i \in {0, \dots, N-1}$ with measured range $r_i$:

$$\theta_i = \theta_{\min} + i \cdot \frac{\theta_{\max} - \theta_{\min}}{N - 1} = i \cdot \frac{2\pi}{360}$$

In the sensor coordinate frame $\mathcal{F}_S$, the Cartesian coordinates are:

$$\mathbf{p}_i^S = \begin{bmatrix} x_i^S \ y_i^S \ 0 \ 1 \end{bmatrix} = \begin{bmatrix} r_i \cos\theta_i \ r_i \sin\theta_i \ 0 \ 1 \end{bmatrix}$$

Using the rigid body transformation matrix $\mathbf{T}_S^B \in \text{SE}(3)$ from the sensor frame $\mathcal{F}_S$ to the robot base footprint $\mathcal{F}_B$:

$$\mathbf{p}_i^B = \mathbf{T}_S^B \mathbf{p}_i^S = \begin{bmatrix} \mathbf{R}_S^B & \mathbf{t}S^B \ \mathbf{0}{1 \times 3} & 1 \end{bmatrix} \mathbf{p}_i^S$$

For planar mobile robots where $\mathbf{R}S^B = \mathbf{I}{3 \times 3}$ and $\mathbf{t}S^B = \mathbf{0}$, the polar coordinates project directly onto the $G \times G$ discrete matrix with maximum sensor visualization radius $r{\max} = 3.5,\text{m}$:

$$g_x(i) = c - \operatorname{round}\left( \frac{r_i}{r_{\max}} \cdot c \cdot \cos\theta_i \right)$$

$$g_y(i) = c - \operatorname{round}\left( \frac{r_i}{r_{\max}} \cdot c \cdot \sin\theta_i \right)$$

The ASCII visualizer cell state $\mathcal{M}(g_x, g_y)$ is formally defined by the discretization map:

$$\mathcal{M}(g_x, g_y) = \begin{cases} \text{'R'}, & g_x = c \land g_y = c \quad (\text{Robot Center}) \ \text{'*'}, & \exists i \text{ s.t. } (g_x(i), g_y(i)) = (g_x, g_y) \land 0.1 < r_i \le r_{\max} \quad (\text{Obstacle}) \ \text{'.'}, & \text{otherwise} \quad (\text{Clear Navigable Space}) \end{cases}$$

Sector obstacle clearance metrics are computed across defined angular intervals:

$$d_{\text{front}} = \min_{\substack{|\theta_i| \le 15^\circ \ r_i > 0.1}} r_i, \quad d_{\text{left}} = \min_{\substack{75^\circ \le \theta_i \le 105^\circ \ r_i > 0.1}} r_i, \quad d_{\text{right}} = \min_{\substack{255^\circ \le \theta_i \le 285^\circ \ r_i > 0.1}} r_i$$


4. 3-Tier Command Sandbox State Machine & Mutex-Guarded Audit Logging

The CommandSandbox partitions all operational commands across system state $S \in {\text{READ_ONLY}, \text{SAFE_WRITE}, \text{FULL}}$.

Let the full action set $\mathcal{A}$ partition into telemetry reads, topic publishes, and parameter updates:

$$\mathcal{A} = \mathcal{A}{\text{read}} \cup \mathcal{A}{\text{pub}} \cup \mathcal{A}_{\text{param}}$$

The access control decision function $\Phi(S, a) \in {\text{ALLOW}, \text{BLOCK}}$ satisfies the following strict mathematical invariants:

  1. State $S = \text{READ_ONLY}$ (Zero Actuation Writes): $$\Phi(\text{READ_ONLY}, a) = \begin{cases} \text{ALLOW}, & a \in \mathcal{A}{\text{read}} \ \text{BLOCK}, & a \in \mathcal{A}{\text{pub}} \cup \mathcal{A}_{\text{param}} \end{cases}$$

  2. State $S = \text{SAFE_WRITE}$ (Allowlist Filtered Actuation): $$\Phi(\text{SAFE_WRITE}, a) = \begin{cases} \text{ALLOW}, & a \in \mathcal{A}{\text{read}} \ \text{ALLOW}, & a = \operatorname{publish}(t, m) \land t \in \mathcal{T}{\text{safe}} \ \text{ALLOW}, & a = \operatorname{set_param}(n, p, v) \land (n, p) \in \mathcal{P}{\text{safe}} \ \text{BLOCK}, & \text{otherwise} \end{cases}$$ where the default verified allowlists are: $$\mathcal{T}{\text{safe}} = { \text{/cmd_vel}, , \text{/target_velocity}, , \text{/led_state}, , \text{/speaker_cmd}, , \text{/arm_target_angle} }$$ $$\mathcal{P}_{\text{safe}} = { (\text{nav2_controller}, \text{max_vel_x}), , (\text{nav2_controller}, \text{max_vel_theta}), , (\text{nav2_controller}, \text{min_vel_x}) }$$

  3. State $S = \text{FULL}$ (Simulation / Unrestricted Development): $$\forall a \in \mathcal{A}, \quad \Phi(\text{FULL}, a) = \text{ALLOW}$$

  4. Thread-Safety Mutex Invariant for Audit Logging: Every decision creates an audit record $E = (t_k, \text{action}, \text{target}, \Phi, S)$. Under concurrent tool invocations, the audit log $\mathcal{L}{\text{audit}}$ is guarded by mutex $\mathcal{M}$: $$\forall t_1, t_2 \in \mathcal{T}{\text{threads}}, \quad \left( \operatorname{Write}(\mathcal{L}{\text{audit}}, t_1) \land \operatorname{Write}(\mathcal{L}{\text{audit}}, t_2) \right) \implies t_1 = t_2$$


5. Kinematic Trajectory Prediction & Neural Safety Auto-Correction

Before issuing actuation commands to hardware, predict_trajectory evaluates the unicycle kinematic model at $1000,\text{Hz}$ across time duration $T$:

$$\begin{bmatrix} \dot{x} \ \dot{y} \ \dot{\theta} \end{bmatrix} = \begin{bmatrix} v \cos\theta \ v \sin\theta \ \omega \end{bmatrix}$$

Using discrete integration over interval $\Delta t = 0.05,\text{s}$:

  • For curved trajectory ($|\omega_k| \ge 10^{-6},\text{rad/s}$): $$x_{k+1} = x_k + \frac{v_k}{\omega_k} \left( \sin(\theta_k + \omega_k \Delta t) - \sin\theta_k \right)$$ $$y_{k+1} = y_k - \frac{v_k}{\omega_k} \left( \cos(\theta_k + \omega_k \Delta t) - \cos\theta_k \right)$$ $$\theta_{k+1} = \theta_k + \omega_k \Delta t$$

  • For straight-line trajectory ($|\omega_k| < 10^{-6},\text{rad/s}$): $$x_{k+1} = x_k + v_k \cos\theta_k \Delta t$$ $$y_{k+1} = y_k + v_k \sin\theta_k \Delta t$$ $$\theta_{k+1} = \theta_k$$

Neural Parameter Clamping Formulation: When an LLM agent proposes PID gains or velocity vectors, predictive_safety_check applies non-linear bounding projections:

$$K_{\text{safe}} = \operatorname{clip}\left( K_{\text{LLM}}, , 0.0, , K_{\max} \right) = \max\left( 0.0, , \min(K_{\max}, K_{\text{LLM}}) \right)$$

$$\mathbf{v}_{\text{safe}} = \begin{bmatrix} \operatorname{clip}(v_x, -1.5, 1.5) \ \operatorname{clip}(\omega_z, -2.5, 2.5) \end{bmatrix}$$

This guarantees that negative feedback stability is preserved unconditionally before signals reach the robot's physical motor drives.


๐Ÿ“Š Performance Benchmarks & Verification

  • Tool Dispatch Overhead: < 0.08 ms ($O(1)$ compiled lookup table)

  • Kinematic Simulation: < 0.10 ms (1000Hz fast-forward compute)

  • Memory Footprint: ~14.2 MB RAM

  • Test Coverage: 42 / 42 Tests Passed (100% Success) (Simulation mode)

python run_tests.py

๐Ÿ“– Extended Documentation



๐Ÿ‘จโ€๐Ÿ’ป Author & License

Abdullah Bin Zafar โ€” Mechatronics & Control Engineering, UET Lahore
Building robots that think, act, and reason safely.

GitHub LinkedIn Gmail

This project is licensed under the MIT License. Contributions, bug reports, and pull requests are welcome!

Available Tools

16 tools
get_node_infoA

Inspect a specific ROS2 node and find its related topics (exact name match).

Inputs: node_name (required).

get_parameterA

Read a live parameter value from a running ROS2 node.

Inputs: node_name (required), param_name (required).

get_pid_stateC

Read current Kp, Ki, Kd gains from a PID controller node, with safety bounds.

Inputs: node_name (required), kd_param, ki_param, kp_param.

get_robot_snapshotA

Fetch LiDAR, IMU, battery, cmd_vel, and odometry in one parallel call. Faster than calling read_topic five times sequentially.

Inputs: no named parameters.

get_spatial_mapC

[WORLD-FIRST] Converts 360ยฐ LiDAR pointclouds into a 2D ASCII spatial radar grid directly inside MCP response JSON, allowing text & vision LLMs to 'see' surrounding space.

Inputs: grid_size, scan_topic.

list_nodesA

List all currently running ROS2 nodes with their namespaces.

Inputs: no named parameters.

list_topicsA

List all active ROS2 topics and their message types.

Inputs: no named parameters.

pingA

Test the connection to the ROS2 bridge. Returns status and active node count. Call this before any other tool to verify the server is reachable.

Inputs: no named parameters.

predictive_safety_checkB

[WORLD-FIRST] Evaluates proposed parameter or velocity commands against dynamic stability bounds, auto-correcting unsafe LLM inputs and returning mathematical proof.

Inputs: target (required), command_type (required), proposed_value (required).

predict_trajectoryA

[WORLD-FIRST] Pre-simulate robot trajectory (x,y,theta) over time dt_sec in 1000Hz fast-forward simulation (<0.1ms compute) BEFORE sending commands to hardware.

Inputs: linear_x (required), angular_z (required), dt_sec.

publish_topicA

Publish a message to a ROS2 topic. Sandboxed: blocked in READ_ONLY mode; allowlisted in SAFE_WRITE mode.

Inputs: topic (required), payload (required), msg_type (required).

read_topicA

Read the latest message from a ROS2 topic. Returns the serialized message and data age in milliseconds. For latched topics (/map, /robot_description), set latched=true.

Inputs: topic (required), latched, msg_type, timeout_ms.

set_parameterA

Dynamically update a parameter on a running ROS2 node. Sandboxed โ€” only allowlisted parameters can be modified in SAFE_WRITE mode.

Inputs: value (required), node_name (required), param_name (required).

swarm_fleet_statusA

[WORLD-FIRST] Scans multi-namespace ROS2 graph (/drone_1, /rover_2, /arm_3) and aggregates multi-robot fleet health in one call.

Inputs: no named parameters.

system_diagnosticsA

Run a full robot health check. Returns battery level, LiDAR status, IMU health, active node count, and lists of critical issues and warnings. ALWAYS call this first when the user asks 'what's wrong?' or 'is the robot ready?'

Inputs: no named parameters.

tune_pidA

Apply new PID gains to a controller node with safety bounds validation. Gains are validated BEFORE reaching hardware โ€” negative gains are rejected. Returns tuning guidance based on control theory.

Inputs: node_name (required), kd, ki, kp, +3 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelogโ€ฆ

    TDQS

    A3.5/5.0

    Scored across 16 tools

    Disambiguation4/5

    Most tools are clearly distinct, but system_diagnostics and get_robot_snapshot both report robot health, and predict_trajectory/predictive_safety_check could be confused at first glance. Descriptions help disambiguate, so the overlap is minor.

    Naming Consistency3/5

    The majority follow a verb_noun pattern (list_nodes, get_parameter, read_topic), but ping, system_diagnostics, and swarm_fleet_status break the convention with verb-only or noun-only names. The mix is readable but not fully consistent.

    Tool Count4/5

    With 16 tools, the count is slightly on the heavier side but appropriate for a ROS2 server that covers node inspection, parameter management, topic I/O, diagnostics, and advanced safety features. Each tool has a reasonable justification to exist.

    Completeness4/5

    The tool surface covers the core ROS2 interactions: listing nodes/topics, reading/writing parameters, publishing/subscribing to topics, and running diagnostics. It lacks direct service call support and topic lifecycle management, but these are minor gaps for the intended use in robot control.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI tools to interact with ROS2 robotics systems through natural language commands. Supports topic publishing/subscribing, service calls, message analysis, and auto-discovery of ROS2 interfaces for debugging and controlling robots.
      Mozilla Public 2.0
    • A
      license
      A
      quality
      D
      maintenance
      Enables controlling robots in ROS environments through natural language, supporting topics, services, actions, and GUI tools.
      24
      36
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables large language models to interact with ROS robots seamlessly, allowing natural language control, real-time sensor monitoring, and autonomous task execution without modifying existing robot code.
      Apache 2.0
    • A
      license
      A
      quality
      C
      maintenance
      Connects AI agents to ROS 2 robots via rosbridge, enabling observation, inspection, and control of robot topics, services, and actions through natural language.
      11
      2
      MIT