Skip to main content
Glama
EngineerAbdullahBinZafar

Principia Robotica

โšก PRINCIPIA ROBOTICA

Lex Prima: Safety is not a feature. It is the law.

World-first unified MCP gateway + Control Barrier Function (CBF-QP) safety engine for agentic robotics.

Give Claude, GPT-4o, Gemini, and any LLM mathematically proven safe control over physical robots via ROS2.

Version License Python CBF Author


Created: July 29, 2026 ยท Author: Abdullah Bin Zafar ยท UET Lahore, Pakistan

"What Newton's Principia was to classical mechanics, this is to the laws governing AI-controlled machines."


๐ŸŒ Why This Exists (The Problem)

Every AI agent โ€” Claude, GPT-4o, Gemini โ€” can be told to drive a robot. But none of them can mathematically guarantee safety. They can crash, over-accelerate, collide, or violate physical limits. There was no open-source bridge between LLM intelligence and control-theoretic safety.

Until now.


Related MCP server: Nonead Universal-Robots MCP Server

๐Ÿ”ฌ What This Is (The World-First Innovation)

Existing World

After Principia Robotica

AI sends cmd_vel. Robot may crash.

AI's command is intercepted by CBF-QP solver. Safe command issued.

No formal safety guarantee

โˆ€tโ‰ฅ0: h(x(t)) โ‰ฅ 0 โ€” mathematically proven forward invariance

Safety = hope + testing

Safety = formal theorem (Ames et al., proven 2017)

MCP server = passive sensor reader

MCP server = active safety enforcer

Pre-simulation not available

Certify trajectory BEFORE hardware moves


๐Ÿ“ The Mathematics (The Core Law)

The CBF-QP Safety Filter solves this problem in real-time (< 1ms in Python):

$$u^* = \arg\min_{u \in \mathcal{U}} \frac{1}{2}|u - u_{\text{AI}}|^2$$

$$\text{subject to:} \quad L_f h(x) + L_g h(x) u \geq -\alpha(h(x))$$

Where:

  • $u_{\text{AI}}$ = command from AI agent (Claude, GPT-4o, Gemini...)

  • $h(x)$ = Control Barrier Function (encodes obstacle avoidance)

  • $L_f h$, $L_g h$ = Lie derivatives along robot dynamics

  • $\alpha: \mathbb{R} \to \mathbb{R}$ = class-K function (typically $\alpha(h) = \gamma h$)

Result: The robot receives the closest safe command to what the AI wanted. Formally proven optimal by KKT conditions.


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    AI Agent (Claude / GPT-4o / Gemini)          โ”‚
โ”‚                    Tools: cbf_filter_velocity,                   โ”‚
โ”‚                           predict_safe_trajectory,              โ”‚
โ”‚                           lyapunov_stability_check, ...         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚  MCP stdio (JSON-RPC 2.0)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               PRINCIPIA ROBOTICA MCP SERVER                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  CBF-QP Solver   โ”‚   โ”‚ Kinematic World  โ”‚   โ”‚ Lyapunov   โ”‚  โ”‚
โ”‚  โ”‚  (CVXPY + OSQP)  โ”‚   โ”‚ Model (1000Hz)   โ”‚   โ”‚ Stability  โ”‚  โ”‚
โ”‚  โ”‚  < 1ms Python    โ”‚   โ”‚ Trajectory Sim   โ”‚   โ”‚ Analyzer   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”˜                   โ”‚         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚  ROS2 Bridge (optional)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         ROS2 Middleware โ€” /cmd_vel_raw โ†’ [CBF] โ†’ /cmd_vel        โ”‚
โ”‚                        โ†‘ /odom (live state)                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              PHYSICAL ROBOT (TurtleBot4 / Spot / Custom)         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽจ Interactive Web Visualizer Dashboard (1-Second Demo)

Launch the 60 FPS live HTML5 Canvas + Web GL simulator in your browser with a single command:

python -m principia.server --ui
  • Live Obstacle Field: Drag and drop circular obstacles in real-time.

  • AI Command Interceptor: Adjust AI linear/angular velocity sliders to observe real-time CBF-QP minimal perturbation filtering.

  • Multi-Mode Support: Unicycle differential drive, Quadrotor 2D altitude floor, Swarm fleet inter-robot collision check, and Dynamic moving obstacles.

  • Visual Telemetry: Real-time $h(x)$ safety gauge, Lyapunov energy $V(x)$ plot, and predicted trajectory path.


๐Ÿ› ๏ธ 1-Second Installation & Setup

git clone https://github.com/EngineerAbdullahBinZafar/principia-robotica
cd principia-robotica
pip install -e .

Verify everything works instantly:

python -m principia.server --doctor

โšก Quickstart (3 Commands)

1. Run the MCP server:

python -m principia.server

2. Test the CBF filter directly in Python:

import numpy as np
from principia.cbf_engine import (
    DifferentialDriveModel, CircularObstacleCBF, CBFQPSafetyFilter
)

robot = DifferentialDriveModel()
obstacle = CircularObstacleCBF(obstacle_x=2.0, obstacle_y=0.0, obstacle_radius=0.5)
safety_filter = CBFQPSafetyFilter(
    robot=robot,
    cbfs=[obstacle],
    u_min=np.array([-0.5, -2.5]),
    u_max=np.array([1.5, 2.5]),
)

# Robot at (1.2, 0) heading toward obstacle at (2.0, 0)
x = np.array([1.2, 0.0, 0.0])
u_ai = np.array([1.5, 0.0])  # AI wants full speed ahead

result = safety_filter.solve(x, u_ai)

print(f"AI proposed:  v={u_ai[0]:.2f} m/s")
print(f"Safe command: v={result['u_safe'][0]:.2f} m/s")
print(f"Was modified: {result['was_modified']}")
print(f"Solve time:   {result['solve_time_ms']:.2f} ms")

3. Add to your AI client (Claude Desktop / Cursor):

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "principia-robotica": {
      "command": "python",
      "args": ["-m", "principia.server"],
      "cwd": "/path/to/principia-robotica"
    }
  }
}

๐Ÿ”ง MCP Tools (13 Total)

Tool

Type

Description

cbf_filter_velocity

๐Ÿ”ด WORLD-FIRST

Real-time CBF-QP safety filter for velocity commands

predict_safe_trajectory

๐Ÿ”ด WORLD-FIRST

Pre-simulate + certify trajectory before hardware moves

lyapunov_stability_check

๐Ÿ”ด WORLD-FIRST

Real-time Lyapunov stability verification

cbf_quadrotor_altitude

๐Ÿ”ด WORLD-FIRST

CBF altitude safety for quadrotors

minimal_perturbation_proof

๐Ÿ”ด WORLD-FIRST

Formal KKT proof of minimum-norm safety correction

clf_cbf_qp_solver

๐Ÿ”ด WORLD-FIRST

Unified Control Lyapunov + Control Barrier QP solver

swarm_cbf_fleet_safety

๐Ÿ”ด WORLD-FIRST

Multi-robot swarm inter-agent collision & barrier check

dynamic_obstacle_cbf

๐Ÿ”ด WORLD-FIRST

CBF safety filter for dynamic moving obstacles

get_cbf_spatial_map

๐Ÿ”ด WORLD-FIRST

ASCII radar safety map of surrounding obstacle space

batch_cbf_filter

๐Ÿ”ด WORLD-FIRST

Parallel batch CBF velocity filter for multi-robot fleets

get_cbf_safety_report

โœ…

Full safety audit of current robot state

principia_status

โœ…

Server status and capability report

principia_benchmark

โœ…

QP solver performance benchmark


๐Ÿงฌ File Structure

principia-robotica/
โ”œโ”€โ”€ principia/
โ”‚   โ”œโ”€โ”€ __init__.py           # Package metadata
โ”‚   โ”œโ”€โ”€ server.py             # MCP JSON-RPC 2.0 server (entry point)
โ”‚   โ”œโ”€โ”€ cbf_engine.py         # CBF-QP solver + robot models
โ”‚   โ”œโ”€โ”€ world_model.py        # Kinematic trajectory predictor + Lyapunov
โ”‚   โ”œโ”€โ”€ tools.py              # MCP tool handler functions
โ”‚   โ”œโ”€โ”€ ros2_bridge.py        # ROS2 live integration (optional)
โ”‚   โ””โ”€โ”€ theory_and_proofs.py  # Complete mathematical derivations
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_principia.py     # Full test suite
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ THEORY.md             # LaTeX-formatted mathematical proofs
โ”œโ”€โ”€ mcp_config.json           # MCP client configuration template
โ”œโ”€โ”€ pyproject.toml            # Package metadata + build config
โ”œโ”€โ”€ LICENSE                   # MIT + attribution clause
โ””โ”€โ”€ README.md                 # This file

๐Ÿ“Š Performance Benchmarks

Operation

Time

Frequency

CBF margin evaluation

< 0.01 ms

> 100,000 Hz

Early exit (safe command)

< 0.05 ms

> 20,000 Hz

CBF-QP solve (CVXPY/OSQP)

< 2 ms

> 500 Hz

Trajectory pre-simulation (3s horizon)

< 5 ms

> 200 Hz

Lyapunov check

< 0.1 ms

> 10,000 Hz

Real-time control loops run at 50โ€“200 Hz. This engine operates at > 500 Hz. โœ…


๐Ÿ“š Mathematical References

  1. Ames, A.D., Xu, X., Grizzle, J.W., Tabuada, P. (2017). Control barrier function based quadratic programs for safety critical systems. IEEE Transactions on Automatic Control, 62(8), 3861โ€“3876.

  2. Ames, A.D., Coogan, S., Egerstedt, M., et al. (2019). Control barrier functions: Theory and applications. European Control Conference.

  3. Zafar, A.B. (2026). Principia Robotica: World-first unified MCP+CBF-QP agentic safety engine. GitHub. https://github.com/EngineerAbdullahBinZafar/principia-robotica


๐Ÿ‘ค Author

Abdullah Bin Zafar
UET Lahore, Pakistan
GitHub: @EngineerAbdullahBinZafar

If this helped you, please โญ the repo. It costs you nothing and means everything.


ยฉ 2026 Abdullah Bin Zafar โ€” MIT License
All derivative works must attribute the original author.

A
license - permissive license
-
quality - not tested
B
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Control plane for autonomous software labor. Agents claim objectives over MCP with audit trail.

  • Coordinate multiple AI agents over MCP: atomic claims, leases, shared ledger, handoffs, tasks.

  • Phone, SMS & email for AI agents โ€” one remote MCP endpoint, OAuth login, zero install.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EngineerAbdullahBinZafar/principia-robotica'

If you have feedback or need assistance with the MCP directory API, please join our Discord server