Skip to main content
Glama

Write Module

write_module
Destructive

Create 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

NameRequiredDescriptionDefault
codeYesPython source code for the module.
nameYesModule name. Can be a dotted path (e.g., 'mypackage.utils') in which case parent packages are created automatically.
overwriteNoIf True, overwrite and replace existing module. If False, raise error if module already exists.
session_keyNoMaya session key (optional if only one active session exists).

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.5.0
    • changedInput schema / properties / overwrite / description
      Previous value: -"If True, replace existing module. If False, raise error\n       if module already exists."New value: +"If True, overwrite and replace existing module. If False,\n       raise error if module already exists."
    • 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 active session exists)."
  2. First observedv0.4.1

TDQS

A4.4/5.0
Behavior4/5

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

Annotations already flag destructive=true and readOnly=false, and the description adds substantial context beyond them: modules are in-memory and lost on restart, existing modules are protected unless overwrite=True, and safe_mode rejects payloads with error id safe_mode_rejected and stamps mode: "safe" on responses. The only gap is that it never says what the failure mode looks like for a missing session, but the disclosure is well above the bar set by annotations.

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?

Front-loaded with the one-sentence purpose, then behavior, then safety, then boundary routing – a sensible progression. The safe_mode paragraph is long and somewhat tangential to calling the tool correctly, which keeps it from a 5.

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?

A mutation tool with full annotation coverage, 100% schema coverage, and an output schema, so the description need not explain return values. Persistence, overwrite protection, session requirement, and execute_code boundary are all covered, leaving nothing an agent needs to call it correctly.

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%, so name, code, overwrite and session_key are already documented including dotted-path parent creation. The description reinforces the overwrite default but adds no syntax or format information the schema lacks, so the baseline 3 applies.

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?

States a specific verb+resource: 'Create a virtual in-memory Python module in an active Maya session,' and the final Boundary paragraph explicitly separates it from execute_code (reusable libraries vs one-shot execution). An agent can route between the two without opening either schema.

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

Usage Guidelines5/5

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

Gives an explicit when-to-use boundary naming the alternative ('Use write_module to define reusable libraries... use execute_code for one-shot imperative execution'), plus a precondition ('Requires an active Maya session') and the overwrite condition that determines success vs error.

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