MuJoCo MCP服务器
   
65个MCP工具 暴露 MuJoCo 物理模拟 克劳德代码 以及任何 模型上下文协议 客户。
加载机器人、步进物理、分析联系人、优化轨迹、导出视频——所有这些都可以通过人工智能助手中的自然语言完成。
______________________________________________________________________
需求
- Python≥3.10,MuJoCo≥2.3
- 带有EGL(GPU)或OSMesa(CPU无头)的Linux用于渲染
- 紫外线 推荐
______________________________________________________________________
快速开始
git clone https://github.com/Rongxuan-Zhou/mujoco-mcp-server.git
cd mujoco-mcp-server
pip install -e .添加到克劳德代码
claude mcp add mujoco-sim -- uv run --directory /path/to/mujoco-mcp-server mujoco-mcp或手动输入 ~/.claude.json:
{
"mcpServers": {
"mujoco-sim": {
"type": "stdio",
"command": "uv",
"args": ["run", "--directory", "/path/to/mujoco-mcp-server", "mujoco-mcp"],
"env": { "MUJOCO_GL": "egl" }
}
}
}HTTP传输(远程)
python -m mujoco_mcp --transport streamable-http --host 0.0.0.0 --port 8080______________________________________________________________________
你能做什么
连接后,只需问克劳德:
轨迹优化与控制
"Run iLQR on the Franka arm to reach [0.4, 0, 0.5] in 50 steps — show the control sequence and waypoints"
"Compare MPPI (200 samples) vs iLQR on the hopper reaching task; which converges to lower cost?"
"Plan a min-jerk Cartesian trajectory for the end-effector, step the PD controller, and plot joint torques over time"稳健性&逼真
"Sweep body mass ±40% and floor friction [0.1, 2.0] over 50 random samples — report mean/std of max CoM speed"
"Apply 30 N lateral impulses across 16 Fibonacci sphere directions; what is the stability margin of the current controller?"
"At what force magnitude does the bipedal walker fail to recover in more than 25% of directions?"接触力学和模型验证
"Validate this MJCF for dangling actuators and solref instabilities before I load it"
"Are the contact parameters between the gripper fingers and the object causing numerical stiffness? Suggest alternatives"
"Show the active contact forces and check whether the friction cone constraints are satisfied"运动学和工作空间分析
"Compute the manipulability index at this Franka configuration — is it near a singularity?"
"Solve IK for site 'ee' at [0.5, 0.2, 0.3] and verify the joint limits are respected"
"Map reachable workspace by sweeping joint angles and recording Cartesian ee positions"RL和数据管道
"Set up a Gymnasium env for the hopper, run 500 steps with random actions, and export a phase portrait of hip angle vs angular velocity"
"Record a 10-second rollout, export full state log with body positions and sensor data, then plot the 3D CoM trajectory"
"Run domain randomization on link masses and timestep — export CSV and show which parameter range produces the worst instability"______________________________________________________________________
工具
| 组 | 工具 | 描述 |
|---|---|---|
| 模拟 | sim_load sim_step sim_forward sim_reset sim_get_state sim_set_state sim_record sim_list | 加载MJCF/XML模型和步骤物理 |
| 渲染 | render_snapshot render_depth | PNG快照和深度图 |
| 分析 | analyze_contacts analyze_energy analyze_forces compute_jacobian compute_derivatives read_sensors | 接触、能量、力、雅可比矩阵、线性动力学 |
| 模型 | modify_model reload_from_xml | 就地编辑参数(无需重新编译)或完全重新加载XML |
| 批次 | run_sweep | 并行参数扫描通过 ProcessPoolExecutor |
| 出口 | export_csv plot_data export_state_log plot_trajectory | 将轨迹保存到CSV并绘制 |
| 媒体 *(可选)* | export_video | 将轨迹渲染为MP4或GIF视频 |
| 空间 | scene_map body_aabb surface_anchor compute_placement | AABB、表面锚、位置计算 |
| 动物园 | list_menagerie_models validate_menagerie_model load_menagerie_model | 从MuJoCo动物园下载并加载50多个机器人 |
| 控制 | create_controller plan_trajectory step_controller get_controller_state | PID+手臂/四足动物/类人机器人的最小急动轨迹 |
| 传感器融合 | configure_sensor_fusion get_fused_state | 低通滤波联合状态估计 |
| 协调 | coordinator_add_robot coordinator_get_status coordinator_check_collisions coordinator_assign_task | 多机器人车队管理 |
| 强化学习 | create_rl_env rl_step | 体育馆兼容RL环境包装 |
| 观众 | viewer_open viewer_sync viewer_close | 实时交互式查看器(需要显示) |
| 视觉 *(可选)* | analyze_scene compare_scenes track_object render_figure_strip | Gemini 2.5 Pro场景分析和轨迹跟踪 |
| 运动学 | solve_ik | 末端效应器位置的阻尼最小二乘IK |
| 优化 | optimize_ilqr optimize_mppi | iLQR和MPPI轨迹优化 |
| 鲁棒性 | apply_perturbation stability_analysis randomize_dynamics | 扰动鲁棒性分析和域随机化 |
| 诊断 | validate_mjcf model_summary suggest_contact_params diagnose_instability | 预加载XML验证、模型概述、联系人调优、不稳定性检测 |
| 工作流程 | run_and_analyze debug_contacts evaluate_trajectory compare_trajectories | 复合研究工作流程 |
| 元 | server_diagnostics | 服务器运行状况、GL后端和已加载插槽 |
______________________________________________________________________
任选附件
视频导出
pip install -e ".[media]"启用 export_video --将任何记录的轨迹渲染为 四个 (要求 imageio[ffmpeg])或 图形交换格式 (仅提供枕头,不额外收费)。
视觉分析
pip install -e ".[vision]"
export GEMINI_API_KEY=your_key启用 analyze_scene, compare_scenes, track_object,以及 render_figure_strip 通过Gemini 2.5 Pro。
______________________________________________________________________
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
MUJOCO_GL | 自动探测 | GL后端: egl (GPU)或 osmesa (CPU无头) |
MUJOCO_MCP_RENDER_WIDTH | 640 | 渲染宽度(像素) |
MUJOCO_MCP_RENDER_HEIGHT | 480 | 渲染高度(像素) |
MUJOCO_MCP_NO_RENDER | 0 | 设置 1 完全跳过GL初始化 |
MUJOCO_MCP_MAX_WORKERS | 8 | 工人流程 run_sweep |
GEMINI_API_KEY | -- | 视觉工具需要 |
GEMINI_VISION_MODEL | gemini-2.5-pro | 覆盖Gemini模型 |
______________________________________________________________________
建筑
src/mujoco_mcp/
├── server.py # FastMCP app + lifespan context
├── sim_manager.py # Multi-slot simulation manager (thread-safe)
├── _registry.py # FastMCP instance (avoids circular imports)
├── constants.py # Shared constants (yield intervals, thresholds)
├── tools/ # All @mcp.tool() registrations (one file per group)
├── resources.py # MCP Resources
├── prompts.py # MCP Prompts (7 workflow prompts)
└── utils/
└── gl_setup.py # Probe EGL → OSMesa; sets MUJOCO_GL before mujoco import关键模式:
- 每个工具组都有一个
_XXX_impl()同步功能(用于测试)+异步MCP包装器 @mcp.tool()外部装饰师,@safe_toolinternal——所有异常都返回JSON错误,从不引发SimManager保存命名插槽("default","exp1",…),每个都有模型、数据、轨迹和可选的控制器/RL环境
______________________________________________________________________
发展
# Run all tests
pytest tests/
# Single file
pytest tests/test_sim_tools.py -v
# Lint
ruff check src/mujoco_mcp测试需要OSMesa进行无头渲染(conftest.py 套 MUJOCO_GL=osmesa 自动)。
______________________________________________________________________
贡献
欢迎捐款。一些指导方针:
- 新工具组: 创建
src/mujoco_mcp/tools/.py,注册server.py,在中添加测试tests/test_.py _impl图案: 保持同步_XXX_impl()用于直接测试调用的函数;异步MCP包装器是一个薄壳- 先测试: 在实现之前编写失败的测试
- 没有新的硬依赖关系 无需讨论——可选附加内容
pyproject.toml[project.optional-dependencies]
在启动大型功能之前打开一个问题。
______________________________________________________________________
