mjguard
Let an LLM agent drive any MuJoCo-modelled robot arm over MCP, with every motion checked in the model before it runs.
Language models refuse unsafe requests in chat, then carry them out when they hold a robot's tools: refusal falls from 73% of text requests to 18-25% once the model controls the arm ("Refuses in Chat, Complies with Arms", Sun et al., 2026). mjguard puts the check below the model, where a prompt cannot reach it: the agent asks for a pose, mjguard plans it, checks every waypoint against the robot's own MuJoCo model, and either moves or returns a refusal the model can act on.
uvx mjguard check panda # first run downloads MuJoCo Menagerie (about a minute)
uvx mjguard serve panda # MCP over stdio; or ur5e, or your own robot.toml
Franka Panda from MuJoCo Menagerie, driven through the same executor and guard the MCP server uses
(scripts/record_demo.py). A target into the table and one out of reach are refused; the refusal carries the
farthest checked-safe point, and the next call follows it.
What it checks
Every motion is planned into joint-space waypoints, and every waypoint is checked before anything moves:
| Check | Refusal code |
|---|---|
| Joint ranges from the model, minus a margin | JOINT_LIMIT |
| Contacts between moving links and the rest of the scene, from MuJoCo's own collision pipeline | COLLISION, TABLE_COLLISION |
| Distance from every moving collision geom (meshes included) and the tool point to the floor or table, with a planning margin above the hard limit | TABLE_CLEARANCE |
| Distance from every moving collision geom to every obstacle in the config | OBSTACLE_CLEARANCE, COLLISION |
| An optional workspace box for the tool point | WORKSPACE |
| IK convergence: a miss beyond 1 mm or 1.5° is a refusal, never a "close enough" plan | UNREACHABLE |
While the motion runs, and again after the servos settle, a monitor checks what the robot actually did and
halts it (ENVELOPE_BREACH) if the measured arm crosses the hard limit or touches anything. Plans keep a margin
(10 mm by default) above that limit: under physics, the UR5e and Panda presets settle about 6 mm below their plan,
and a test pins that they stay above the hard limit.
Refusals a model can use
{
"ok": false,
"refusal": {
"code": "UNREACHABLE",
"message": "no joint solution reaches the target; the closest misses by 2032.0 mm and 40.7 deg",
"suggestion": {"x_mm": 890.7, "y_mm": 125.3, "z_mm": 277.5,
"note": "farthest checked-safe point on the straight line toward the target (19% of the way)"}
}
}
The suggestion is the farthest point toward the target that passed every check, rounded the way a model will send
it back, and re-planned deterministically, so following it (with the tool_down it names) is accepted. A property test sends random targets and
follows every suggestion to keep it that way.
Built-in robots
Thirteen arms from MuJoCo Menagerie, downloaded on first use. CI runs every one of them end to end with its own servos under gravity: reach a target, refuse one in the table and one out of reach, stay above the hard clearance limit, follow the suggestion.
| Hobby and research | Collaborative and industrial |
|---|---|
so_arm100, so_arm101 (LeRobot) |
ur5e, ur10e (Universal Robots) |
low_cost_robot_arm |
panda, fr3 (Franka) |
piper (AgileX) |
iiwa14 (KUKA) |
yam (I2RT) |
gen3 (Kinova) |
z1 (Unitree) |
xarm7 (UFACTORY) |
Each preset's planning margin covers the tracking error its model's servos show in simulation (10 mm for most, 40 mm for the Z1). Grippers are configured for the Panda, SO-ARM100, SO-ARM101, low-cost arm, PiPER and YAM.
Your own robot
Write a small TOML file next to your MJCF:
name = "my_arm"
[model]
mjcf = "scene.xml" # or "menagerie:<name>"
floor_geom = "floor" # a plane; clearance is measured against it
keyframe = "home" # start and rest pose
[arm]
joints = ["joint1", "joint2", "joint3", "joint4", "joint5", "joint6"]
tcp_site = "tool" # or tcp_body = "hand" with tcp_offset_m = [0, 0, 0.1]
tool_axis = "z" # the axis that points out of the tool
actuators = ["a1", "a2", "a3", "a4", "a5", "a6"] # position servos: simulate with physics; omit for kinematic
[limits]
min_clearance_mm = 20 # hard limit, enforced on the measured arm
planning_margin_mm = 10 # plans keep 30 mm
workspace_mm = { x = [-600, 600], y = [-600, 600] }
obstacle_clearance_mm = 10
[gripper] # optional
joints = ["finger_left", "finger_right"]
closed = [0.0, 0.0]
open = [0.04, -0.04]
actuator = "gripper" # optional: drive it in physics
ctrl_closed = 0.0
ctrl_open = 0.04
[[obstacles]] # boxes, cylinders and spheres on the table; millimetres, z = height of the centre
name = "parts_bin"
shape = "box"
size_mm = [120, 160, 140] # box: x, y, z; cylinder: diameter, height; sphere: diameter
center_mm = [300, 0, 70]
mjguard check robot.toml # loads it, checks the rest pose, prints the envelope
mjguard serve robot.toml # MCP over stdio
Two kinds of contact are part of a model's design rather than a collision, and mjguard treats them that way:
contacts the model already has in its rest pose (Kinova Gen3's base and shoulder hulls overlap; closed fingers touch;
a UR shoulder sits on the floor) are allowed up to the depth they have at rest, and mjguard check lists them; and
bodies whose relative pose depends only on gripper joints (two fingers) are not checked against each other. Fingers
against the arm, the table and obstacles are. Contacts with a configured obstacle are never allowed, at rest or
otherwise.
Links whose moving joints all spin about a vertical axis (a turret on its base) cannot change height, so they are exempt from the clearance check; they are still collision-checked.
Claude Code
claude mcp add ur5e -- uvx mjguard serve ur5e
Tools
get_state, get_limits, move_to(x_mm, y_mm, z_mm, tool_down=true, speed, path="joint"),
move_joints({name: value}), gripper(opening) (when configured), rest, stop.
path="line" makes the tool point travel a straight line, sampled every 5 mm, with IK solved point to point so the
arm cannot flip configuration mid-way; a line that crosses a singularity or leaves reach is refused, and a refusal's
suggestion says which path it was checked with. Resources: mjguard://limits, mjguard://trace/latest.
Millimetres and degrees; z is the height above the floor plane.
Real hardware
mjguard drives a Transport: anything that can report joint positions and follow a list of checked waypoints. It
ships the MuJoCo simulator transport. A real arm needs a transport for its driver; the guard, the monitor and the
MCP surface stay the same. roarm-mcp is the RoArm-M3 application this
library was extracted from.
stop() is a software stop. On real hardware a physical e-stop is the only real emergency stop.
Limits of the method
- The check is only as good as the model. Objects that are not in the MJCF scene are invisible to it.
- Joint-space straight lines between waypoints are checked at a fixed spacing (3° by default), not continuously.
- Dynamics (speed, torque, payload) are not checked; the envelope is geometric.
Development
uv sync
uv run ruff check . && uv run ruff format --check . && uv run pyright && uv run pytest -q
License
Apache-2.0. Robot models come from MuJoCo Menagerie under their own licenses and are downloaded at runtime, not redistributed.
Metadata
Release files for mjguard 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mjguard-0.3.0.tar.gz | 9.1 MB | With provenance | Details for mjguard-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mjguard-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for mjguard-0.3.0-py3-none-any.whl |
Total release size: 9.1 MB
Release files / mjguard-0.3.0.tar.gz
| Download URL | mjguard-0.3.0.tar.gz |
|---|---|
| Size | 9.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
851694523edd79d0ad8524be9e1ff2171e9d85dd7647dd1f35856d6d8a603f66
|
|
BLAKE2b-256 checksum How to use checksums |
033afa46394fd4d3361f0618f9dbe318846198d8dd72c6d47fe0bad38d6bb8dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / mjguard-0.3.0-py3-none-any.whl
| Download URL | mjguard-0.3.0-py3-none-any.whl |
|---|---|
| Size | 37.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a525af2706a93b82628581b9a5544bd4da5edd4e4bfe72fdf3889826fd48814d
|
|
BLAKE2b-256 checksum How to use checksums |
834b2acdc79d21bf2b7763a39ddadf073ea029940dbe95a77022e720e43b5962
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for mjguard 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mjguard-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.