Write Module
write_moduleCreate an in-memory Python module in an active Maya session to inject reusable helper functions into sys.modules, with existing modules protected unless overwrite is explicitly enabled.
Instructions
Create a virtual in-memory Python module in an active Maya session.
Injects reusable Python functions into the target Maya session's sys.modules. Modules are virtual and in-memory: they do not persist across Maya restarts, and existing modules are protected unless overwrite=True is explicitly set. Requires an active Maya session.
Under safe_mode (MAYA_MCP_SAFE_MODE, opt-in, default off) this code payload passes the same deny-by-default allowlist as execute_code: non-allowlisted imports, denied builtin names (any reference, not just calls), builtins references, 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. Under the code allowlist, execute_code payloads can only import the v1 allowlisted roots, so a module defined here whose root is not one of those roots is not importable by name from allowlisted code.
Boundary: Use write_module to define reusable libraries and helper functions; use execute_code for one-shot imperative execution or expression evaluation.
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": {
"name": "<name>",
"code": "<code>"
},
"name": "write_module"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source code for the module. | |
| name | Yes | Module name. Can be a dotted path (e.g., 'mypackage.utils') in which case parent packages are created automatically. | |
| overwrite | No | If True, overwrite and replace existing module. If False, raise error if module already exists. | |
| session_key | No | Maya session key (optional if only one active session exists). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |