godot_edit_primitive_mesh
Modify PrimitiveMesh resources in Godot 4.5+ by changing mesh types and parameters for existing MeshInstance3D nodes to customize 3D geometry in game scenes.
Instructions
Modify the PrimitiveMesh resource attached to an existing MeshInstance3D by changing its mesh type and/or one or more mesh parameters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes | Path to the Godot project directory or its project.godot file. | |
| scene_path | Yes | Path to the target .tscn file. Absolute, relative, and res:// paths are supported. | |
| node_path | Yes | Scene-relative node path to the MeshInstance3D node that should be edited. | |
| mesh_type | No | Optional new PrimitiveMesh class such as BoxMesh, CylinderMesh, SphereMesh, CapsuleMesh, PlaneMesh, PrismMesh, QuadMesh, or TorusMesh. | |
| mesh_parameters | No | Primitive mesh property overrides such as size, radius, height, or segment counts. | |
| godot_executable | No | Optional explicit path to the Godot executable or .app bundle. |
Implementation Reference
- src/godot_mcp/godot.py:1387-1465 (handler)The implementation of `edit_primitive_mesh` method within `GodotController` which modifies the PrimitiveMesh resource of a MeshInstance3D.
def edit_primitive_mesh( self, project_path: str, scene_path: str, node_path: str, mesh_type: str | None = None, mesh_parameters: dict[str, Any] | None = None, godot_executable: str | None = None, ) -> dict[str, Any]: project_dir = ensure_project_path(project_path) executable, version = resolve_godot_executable(godot_executable) absolute_scene_path, resource_scene_path = resolve_scene_path(project_dir, scene_path) if not absolute_scene_path.exists(): raise GodotError(f"Scene not found: {absolute_scene_path}") normalized_node_path = normalize_scene_node_path(node_path) final_mesh_type = (mesh_type or "").strip() final_mesh_parameters = mesh_parameters or {} if not isinstance(final_mesh_parameters, dict): raise GodotError("`mesh_parameters` must be an object when provided.") if not final_mesh_type and not final_mesh_parameters: raise GodotError("Provide at least one of `mesh_type` or `mesh_parameters`.") payload: dict[str, Any] = { "mesh_parameters": final_mesh_parameters, } if final_mesh_type: payload["mesh_type"] = final_mesh_type try: with tempfile.NamedTemporaryFile( mode="w", encoding="utf-8", suffix="-godot-edit-primitive-mesh.json", delete=False, ) as handle: json.dump(payload, handle, ensure_ascii=False) config_path = handle.name except TypeError as exc: raise GodotError("`mesh_parameters` contains a value that could not be serialized to JSON.") from exc try: output = _run_godot_script( executable=executable, project_dir=project_dir, script_name="edit_primitive_mesh.gd", user_args=[ "--scene-path", resource_scene_path, "--node-path", normalized_node_path, "--config-path", config_path, ], ) finally: Path(config_path).unlink(missing_ok=True) parsed = _parse_script_json_output(output, "edit_primitive_mesh.gd") supported_mesh_parameters = parsed.get("supported_mesh_parameters", []) if not isinstance(supported_mesh_parameters, list): raise GodotError("Primitive mesh edit did not return a supported parameter list.") return { "project_path": str(project_dir), "scene_path": str(absolute_scene_path), "scene_resource_path": resource_scene_path, "node_path": parsed.get("node_path", normalized_node_path), "node_name": parsed.get("node_name"), "node_type": parsed.get("node_type", "MeshInstance3D"), "mesh_type_before": parsed.get("mesh_type_before"), "mesh_type_after": parsed.get("mesh_type_after"), "mesh_parameters": parsed.get("mesh_parameters", {}), "supported_mesh_parameters": supported_mesh_parameters, "updated_mesh_parameters": parsed.get("updated_mesh_parameters", []), "godot_executable": str(executable), "godot_version": version, } - src/godot_mcp/server.py:601-642 (registration)The definition and registration of the `godot_edit_primitive_mesh` tool within the MCP server.
name="godot_edit_primitive_mesh", description="Modify the PrimitiveMesh resource attached to an existing MeshInstance3D by changing its mesh type and/or one or more mesh parameters.", input_schema={ "type": "object", "properties": { "project_path": { "type": "string", "description": "Path to the Godot project directory or its project.godot file.", }, "scene_path": { "type": "string", "description": "Path to the target .tscn file. Absolute, relative, and res:// paths are supported.", }, "node_path": { "type": "string", "description": "Scene-relative node path to the MeshInstance3D node that should be edited.", }, "mesh_type": { "type": "string", "description": "Optional new PrimitiveMesh class such as BoxMesh, CylinderMesh, SphereMesh, CapsuleMesh, PlaneMesh, PrismMesh, QuadMesh, or TorusMesh.", }, "mesh_parameters": { "type": "object", "description": "Primitive mesh property overrides such as size, radius, height, or segment counts.", }, "godot_executable": { "type": "string", "description": "Optional explicit path to the Godot executable or .app bundle.", }, }, "required": ["project_path", "scene_path", "node_path"], "additionalProperties": False, }, handler=lambda args: self.controller.edit_primitive_mesh( project_path=args["project_path"], scene_path=args["scene_path"], node_path=args["node_path"], mesh_type=args.get("mesh_type"), mesh_parameters=args.get("mesh_parameters"), godot_executable=args.get("godot_executable"), ), ),