Execute Code
execute_codeRun arbitrary Python code in an active Maya session to inspect, modify, or verify 3D scenes and return results as JSON, raw strings, or no output.
Instructions
Execute arbitrary Python code in an active Maya session.
Runs arbitrary code with full session privileges of the connected Maya process. Execution is irreversible and cannot be undone (modifications do not register an automatic undo chunk). The return value shape is governed by the result_type envelope parameter. Requires an established Maya session (discoverable via list_sessions).
Under safe_mode (MAYA_MCP_SAFE_MODE, opt-in, default off) the code payload passes a deny-by-default allowlist checked on the parsed code before dispatch: imports outside the v1 roots (maya/math/json/re/collections/ itertools/functools/dataclasses/typing), denied builtins (eval/exec/open/import/getattr/setattr/...), builtins references (any use of a denied name rejects, not just calls), dunder attribute access, and unparseable input are rejected with safe_mode_rejected naming the triggering rule id. Successful responses carry mode: "safe" on their structured payload. This catches slips, it is not a sandbox — code that passes still runs with full session privileges.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code to execute in Maya. | |
| result_type | No | Return envelope handling for the execution result: - "NONE": Execute statements, don't capture result (returns None) - "JSON": Evaluate expression, JSON-encode result - "RAW": Evaluate expression, return string representation | NONE |
| session_key | No | Maya session key (optional if only one session exists). |