Skip to main content

mjguard

PyPI CI License

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

A simulated Franka Panda moves to a checked target; a move into the table and an out-of-reach move are refused with a suggested safe point, and the arm then follows the suggestion

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
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.

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] }
mjguard check robot.toml     # loads it, checks the rest pose, prints the envelope
mjguard serve robot.toml     # MCP over stdio

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), move_joints({name: value}), gripper(opening) (when configured), rest, stop. 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mjguard 0.1.0
File Size Uploaded Provenance Actions
mjguard-0.1.0.tar.gz 9.1 MB With provenance Details for mjguard-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mjguard 0.1.0
File Interpreter ABI Platform Actions
mjguard-0.1.0-py3-none-any.whl Python 3 none any Details for mjguard-0.1.0-py3-none-any.whl

Total release size: 9.1 MB

Release files / mjguard-0.1.0.tar.gz

Download URL mjguard-0.1.0.tar.gz
Size 9.1 MB
Tags Source
SHA-256 checksum
How to use checksums
9b704bfd769ac794f2f900e45076c9bc7ac93b7d8719b49c2d6bc12b89988404
BLAKE2b-256 checksum
How to use checksums
5ebb86ee233f36c13a90348dd58ac9057ebe6aacdade4edcd638a445769baf19
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 log

Release files / mjguard-0.1.0-py3-none-any.whl

Download URL mjguard-0.1.0-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cff0d5d749d8ef50bf7e4e55b62af8001a68bc93178c5c89fea604a097fe3b04
BLAKE2b-256 checksum
How to use checksums
250bceaca327f501cb0d9d7a54358a452a1cada54ee78d5770f78bc53b96994a
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 log

Security for mjguard 0.1.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.

Select from 2 files

Attestation for mjguard-0.1.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page