Architecture
┌──────────────┐ stdio (Claude Desktop, Claude Code, Cursor, VS Code) ┌──────────────── MCP server (Node, dist/index.js) ─────────────────┐
│ MCP client │────────────────────────────────────────────────────────►│ transport/ stdio | Streamable HTTP (bearer / secret path) │
│ Claude, GPT… │ HTTPS tunnel → Streamable HTTP (ChatGPT, remote) │ mcp/tools/ 296 tools → Zod validation → handlers │
└──────────────┘ │ design-engine/, workflow-engine/ briefs → plans → bridge ops │
│ jobs/ background jobs, executions │
│ photoshop/bridge/ PhotoshopBridge: allowlist, serial queue, │
│ script builder, timeouts, envelope + postprocess │
└───────────────┬───────────────────────────────────────────────────┘
Windows: powershell.exe run-jsx.ps1 ──► COM Photoshop.Application.DoJavaScriptFile
macOS: osascript run-jsx.applescript ──► do javascript file
┌───────────────▼──────────────── Photoshop (ExtendScript, ES3) ─────┐
│ photoshop-scripts/bootstrap.jsx MCP.main, JSON, MCP.toDesc │
│ document / layers / drawing / editing / inspect / design .jsx │
│ → Photoshop DOM + Action Manager (executeAction) │
└────────────────────────────────────────────────────────────────────┘
No plugin, panel or socket runs inside Photoshop. Each bridge call is one short-lived script run.
Layers
| Layer | Location | Responsibility |
|---|---|---|
| Transports | src/index.ts, src/transport/http.ts |
stdio for local clients; Streamable HTTP (sessions, bearer / secret-path auth, DNS-rebinding protection) for remote clients. Both build the same McpServer from src/server.ts. |
| MCP layer | src/mcp/tools/*, resources/, prompts/ |
Tool registration with Zod schemas, path sandboxing, confirmation gates, structured results (ok, source, data, warnings, optional images). |
| Design engine | src/design-engine/*, src/schemas/design-plan.ts, data/*.csv |
Brief analysis → template + style system → DesignPlan JSON → validation → compilation → one execute_plan op. Composition analysis, critique, revision diffing, plan versions, variations, UI auto layout. Pure TypeScript. |
| Workflow engine | src/workflow-engine/* |
Natural-language photo/design briefs (product ads, thumbnails, retouch) → ordered tool steps, run with placeholders, cancellation and per-step status. |
| Jobs | src/jobs/* |
background: true on long tools returns a jobId; jobs run one at a time with PHOTOSHOP_JOB_TIMEOUT_MS. |
| Bridge | src/photoshop/bridge/bridge.ts, queue.ts, script-builder.ts, commands.ts, postprocess.ts |
Op allowlist (BRIDGE_OPS, 88 ops), serial OperationQueue, script generation, timeout watchdog, envelope parsing, error mapping, preview/pixel-stat decoding. |
| Adapters | com-adapter.ts, applescript-adapter.ts, mock-adapter.ts, detect.ts |
Windows COM via powershell.exe; macOS via osascript; in-memory mock for tests. detect.ts finds the install and running process. |
| ExtendScript | photoshop-scripts/*.jsx, run-jsx.ps1, run-jsx.applescript |
ES3 op library registered in MCP.ops; MCP.main dispatches and writes a JSON envelope. |
Request flow
- The client calls e.g.
create_rectangle {x: 100, y: 80, width: 400, height: 200, fill: "#1A2B3C"}. - Zod validates; the handler sandboxes paths (
PathPolicy), enforcesconfirmfor destructive tools and callsbridge.run("shape.rect", args)(composite tools run several ops in aSequence). - The bridge checks
ALLOWED_OPS, queues the call (Photoshop is single-threaded) and builds a self-contained script: every JSX module followed byMCP.main(<command literal>, <result path>). Client data is embedded only as a JSON literal, never as code. - The adapter writes the script to
%TEMP%/photoshop-ai-mcp/<uuid>.jsxand runs the runner: Windowsrun-jsx.ps1→Photoshop.Application.DoJavaScriptFile; macOSrun-jsx.applescript→do javascript file.MCP.mainsets ruler/type units to pixels anddisplayDialogs = NO, runs the op, restores the preferences, and writes{ok, data | error, warnings, document}to<uuid>.json. - The bridge parses the envelope.
ok: falsebecomes a typedMcpDesignError;ok: trueis the only path to success. - If the op rendered a file (
ps.preview,ps.analyze),postprocess.tsreads it, returns base64 or pixel statistics, and deletes it. - The tool returns JSON with
source: "photoshop"(or"mock"/"server"); preview tools add MCP image content.
Action Manager descriptors
Most non-trivial edits (adjustment layers, smart filters, layer effects, Select Subject, masks, gradients) are Action Manager calls.
The JSX writes them in the batchPlay-style JSON form ({_obj, _target, _ref, _enum, _unit}) and MCP.toDesc in
bootstrap.jsx converts them to ActionDescriptor / ActionReference / ActionList before executeAction.
This keeps descriptors readable and lets you paste ones captured with Actions panel → Copy as JavaScript.
Previews and pixel statistics
ExtendScript has no in-memory imaging API. ps.preview saves a downscaled JPEG/PNG copy to the temp folder;
ps.analyze saves a small PNG sample. Node decodes it (decodePng, a dependency-free PNG decoder) and computes
luminance/channel statistics used by data-driven tools such as correct_exposure, auto_white_balance and match_colors.
Why a per-call COM / AppleScript host
- Windows:
Photoshop.Application.DoJavaScriptFileis the documented COM entry point (Adobe Photoshop Scripting Reference: VBScript). - macOS:
tell application id "com.adobe.Photoshop" … do javascript fileis the documented Mac entry point (Photoshop Scripting Reference: AppleScript). - A short-lived PowerShell /
osascriptprocess per call can be killed on timeout without affecting the server. - Cost: process start overhead per call (~0.3–1 s). Design plans are built in one
execute_plancall to amortise it. PHOTOSHOP_ADAPTER=autopicks COM onwin32and AppleScript ondarwin.- Nothing has to be installed into Photoshop. A UXP plugin was prototyped earlier and dropped: it needs a panel to be open and a socket bridge, and adds an install step.
Tool catalog layers
| Layer | Example | Notes |
|---|---|---|
| Primitive | create_rectangle → shape.rect |
One op. |
| Composite | remove_background → layer.select, select.subject, mask.create, select.none |
Sequence records each step; a failure names the step and what already ran. |
| Data-driven | correct_exposure |
Reads pixel statistics measured in Photoshop (ps.analyze) and computes settings server-side. |
| Design plan | generate_design, create_poster, create_app_screen |
Design engine compiles a plan and sends one execute_plan; revise_design sends update_elements. |
| Workflow | execute_workflow { brief } |
Workflow engine plans tool steps and runs them. |
| Unsupported / provider | apply_liquify, generative_fill |
Throw UNSUPPORTED_OPERATION / PROVIDER_NOT_CONFIGURED with an alternative. |
Verified vs. assessed
- Verified: anything read back from Photoshop (
inspect_document,list_layers, measured pixel statistics, export files checked on disk). - Visual assessment: only the AI client can provide it, by looking at the image returned by
capture_preview,generate_export_previeworcritique_design. If no image was produced, the tools say so.
Key files
| File | Role |
|---|---|
src/server.ts |
Builds the context (bridge, paths, jobs, providers) and the McpServer |
src/mcp/tools/registry.ts |
tool() definition, catalog, Sequence, result envelope |
src/photoshop/bridge/commands.ts |
The single list of allowlisted ops (unit test checks each is implemented in photoshop-scripts/) |
src/photoshop/bridge/bridge.ts |
PhotoshopBridge: queue, timeouts, envelope, postprocess |
photoshop-scripts/bootstrap.jsx |
MCP.main, JSON, MCP.toDesc, helpers |
photoshop-scripts/design.jsx |
execute_plan, update_elements, check_fonts |