Skip to main content
Glama

Execute Code

execute_code
Destructive

Run 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

NameRequiredDescriptionDefault
codeYesPython code to execute in Maya.
result_typeNoReturn 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 representationNONE
session_keyNoMaya session key (optional if only one session exists).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.0
    • changedInput schema / properties / code / description
      Previous value: -"Python or MEL code to execute in Maya."New value: +"Python code to execute in Maya."
  2. Changed3 schema fields changedv0.5.0
    • changedInput schema / properties / code / description
      Previous value: -"Python code to execute."New value: +"Python or MEL code to execute in Maya."
    • changedInput schema / properties / result_type / description
      Previous value: -"How to handle the result:\n- \"NONE\": Execute statements, don't capture result\n- \"JSON\": Evaluate expression, JSON encode result\n- \"RAW\": Evaluate expression, return string representation"New value: +"Return envelope handling for the execution result:\n- \"NONE\": Execute statements, don't capture result (returns None)\n- \"JSON\": Evaluate expression, JSON-encode result\n- \"RAW\": Evaluate expression, return string representation"
    • changedInput schema / properties / session_key / description
      Previous value: -"Session key (optional if only one session exists)"New value: +"Maya session key (optional if only one session exists)."
  3. First observedv0.4.1

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already flag destructiveHint=true and readOnlyHint=false, yet the description adds substantial context beyond them: execution is irreversible with no automatic undo chunk, code runs with full session privileges, and the safe_mode allowlist rules (permitted import roots, denied builtins, dunder access bans, unparseable input) plus the safe_mode_rejected error and mode: "safe" response field are all disclosed. The candid caveat 'This catches slips, it is not a sandbox' is exactly the kind of risk framing an agent needs before invoking a destructive tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The risk statement and session prerequisite are front-loaded before the safe_mode detail, which is the right ordering. The safe_mode paragraph is dense and runs long, but every clause carries operational meaning (rule categories, rejection identifier, success marker) rather than filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a high-risk arbitrary-execution tool with no output schema, the description covers the essential unknowns: privilege level, irreversibility, session prerequisite, safe_mode semantics, and how the return envelope is selected. An agent has enough to decide whether to call it and to interpret success or rejection.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with result_type's NONE/JSON/RAW modes fully enumerated in the schema itself, so the baseline is 3. The description only restates that 'The return value shape is governed by the result_type envelope parameter,' adding orientation but no semantics beyond the structured field.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The first sentence states a specific verb and resource — 'Execute arbitrary Python code in an active Maya session' — which unambiguously separates it from siblings like scene_nodes, scene_describe, or write_module. An agent knows exactly what capability this grants without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives a concrete prerequisite ('Requires an established Maya session (discoverable via list_sessions)') which routes the agent to the right sibling for setup. It also explains the safe_mode opt-in condition that changes this tool's acceptance behavior. It stops short of explicitly saying when to prefer structured siblings over raw code execution, but the context provided is clearly actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.