Skip to main content
Glama

photoshop_execute_script

Destructive

Execute custom ExtendScript (JSX) in Photoshop when no existing tool covers the operation. Use for advanced automation; returns script output as text or JSON.

Instructions

Execute custom ExtendScript (JSX) code inside Photoshop (advanced escape hatch).

Use when: no existing tool covers the operation and you can write safe JSX. Do NOT use when: a recipe or atomic tool exists — prefer photoshop_recipe_* or photoshop_* tools. Do NOT use when: painting a two-color gradient — use photoshop_fill_gradient. Document.gradients does not exist and throws "undefined is not an object".

Returns: script return value serialized as text/JSON. IMPORTANT: Your code runs inside a wrapping IIFE. Use an explicit return to pass data back — a bare trailing expression returns undefined. Example: return { ok: true }; Objects are serialized with toSource() and parsed automatically on macOS and Windows. Long scripts: pass timeout_ms (up to 600000) so the default 30s budget does not kill the job. Preconditions: valid ExtendScript; active document if script expects one. Side effects: depends on code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesExtendScript code to execute
timeout_msNoScript timeout in milliseconds (default 30000, max 600000). Override with env PHOTOSHOP_SCRIPT_TIMEOUT. Use for long loops, batch jobs, or large documents.
document_idYesPhotoshop document id from photoshop_get_state / photoshop_list_documents. Send null or 0 to use the active document. A positive number activates that document before the tool runs. When no document is open, a stale id does not block the call.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.7.33
    • changedInput schema / properties / document_id / description
      Previous value: -"Photoshop document id from photoshop_get_state / photoshop_list_documents. Send null to use the active document. A number activates that document before the tool runs."New value: +"Photoshop document id from photoshop_get_state / photoshop_list_documents. Send null or 0 to use the active document. A positive number activates that document before the tool runs. When no document is open, a stale id does not block the call."
  2. Changed4 schema fields changedv1.7.32
    • addedInput schema / additionalProperties
      Added value: +false
    • changedInput schema / properties / document_id / description
      Previous value: -"Optional Photoshop document id from photoshop_get_state / photoshop_list_documents. When set, the tool activates that document before running so a UI tab switch cannot retarget the edit."New value: +"Photoshop document id from photoshop_get_state / photoshop_list_documents. Send null to use the active document. A number activates that document before the tool runs."
    • changedInput schema / properties / document_id / type
      Previous value: -"number"New value: +[
      +  "number",
      +  "null"
      +]
    • changedInput schema / required
      Previous value: -[
      -  "code"
      -]New value: +[
      +  "code",
      +  "document_id"
      +]
  3. Changed1 schema field changedv1.7.20
    • addedInput schema / properties / timeout_ms
      Added value: +{
      +  "description": "Script timeout in milliseconds (default 30000, max 600000). Override with env PHOTOSHOP_SCRIPT_TIMEOUT. Use for long loops, batch jobs, or large documents.",
      +  "maximum": 600000,
      +  "minimum": 1000,
      +  "type": "number"
      +}
  4. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already flag destructive/openWorld/idempotent=false, and the description adds substantial context beyond them: the IIFE wrapping requirement, the explicit-return semantics, toSource() serialization, timeout budget override behavior, and preconditions/side-effects caveat. This is the rare case where a description genuinely augments the safety profile rather than restating it.

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 purpose, then labeled Use/Do NOT use/Returns/Preconditions blocks that are easy to scan. The Document.gradients aside is a niche gotcha that is useful but slightly tangential to the core definition.

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?

With no output schema, the description carries the return-value burden and does so ('script return value serialized as text/JSON'), plus preconditions, side-effect caveat, and timeout behavior. Nothing an agent needs to invoke it correctly is missing.

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

Parameters4/5

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

Schema coverage is 100%, so the schema already documents all three params, setting the baseline at 3. The description still adds operational meaning: guidance to pass timeout_ms for long scripts so the default 30s budget does not kill the job, and the active-document precondition for document_id.

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 (execute) and resource (ExtendScript/JSX code) plus its role as an 'advanced escape hatch'. This framing immediately distinguishes it from the ~100 atomic and recipe siblings that do bounded operations.

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?

Explicit 'Use when' and two 'Do NOT use when' clauses naming the preferred alternatives (photoshop_recipe_*, photoshop_fill_gradient) with a concrete failure case for gradients. An agent has a complete routing rule for picking this over siblings.

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

Deploy Server

Other Tools