Skip to content

Fix #18: populate layers and add execute_jsx tool#67

Open
lcdzyj wants to merge 1 commit into
loonghao:mainfrom
lcdzyj:fix/issue-18-layers-and-jsx-execution
Open

Fix #18: populate layers and add execute_jsx tool#67
lcdzyj wants to merge 1 commit into
loonghao:mainfrom
lcdzyj:fix/issue-18-layers-and-jsx-execution

Conversation

@lcdzyj

@lcdzyj lcdzyj commented Jun 17, 2026

Copy link
Copy Markdown

Summary

Fixes three issues discovered during real-world testing:

1. Fix #18: get_active_document_info returns empty layers

The original code had a TODO comment and never populated layers, layer_sets, or channels. Now reads them from the PhotoshopApp document object (artLayers, layerSets, channels).

2. Add execute_jsx universal tool

New MCP tool that executes arbitrary JSX scripts via doJavaScript, unlocking the full Photoshop API beyond the 8 predefined tools. Follows the MCP + script + COM architecture pattern.

3. Fix doJavaScript COM dispatch error

comtypes requires all 3 arguments (script, None, 1) for doJavaScript. Single-argument calls trigger COM error -2147352567 on Photoshop CC2017+. Also injects a JSON.stringify polyfill since Photoshop's ExtendScript (ES3) lacks a native JSON object.

Changes

  • ps_adapter/action_manager.py — populate layers/layer_sets/channels
  • ps_adapter/application.py — fix 3-arg doJavaScript + JSON polyfill
  • tools/script_tools.py — new execute_jsx MCP tool

Test plan

  • get_active_document_info returns layer names, visibility, opacity
  • execute_jsx runs simple scripts: 'hello';, app.activeDocument.name;
  • execute_jsx runs complex scripts with JSON.stringify
  • execute_jsx can create shapes, modify layers via JSX
  • Tested on Photoshop 2022 (v23.1.1) via COM

…tool

- Fix loonghao#18: get_active_document_info now returns layers, layer_sets, and
  channels by reading from PhotoshopApp document object instead of
  leaving them as empty arrays.

- Add execute_jsx MCP tool for universal Photoshop JSX script execution,
  unlocking the full Photoshop API beyond the predefined tools.

- Fix doJavaScript COM dispatch: comtypes requires all 3 arguments
  (script, None, 1) to work correctly. Single-argument calls trigger
  COM error -2147352567 on Photoshop CC2017+.

- Add JSON.stringify polyfill for ExtendScript (ES3) since Photoshop's
  scripting engine lacks a native JSON object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

可以创建,但是无法获取图层内容

1 participant