Labsco
attalla1 logo

Photopea MCP Server

โ˜… 21

from attalla1

Design posters, edit photos, and manipulate images directly from your terminal. Powered by Photopea -- a free, browser-based alternative to Photoshop -- connected to your AI agent via MCP.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup
<p align="center"> <img src="assets/photopea-icon.svg" alt="Photopea" width="120" height="120"> </p> <h1 align="center">Photopea MCP Server</h1> <p align="center"> Design posters, edit photos, and transform images directly from your terminal. Powered by <a href="https://www.photopea.com">Photopea</a> -- a free, browser-based alternative to Photoshop -- connected to your AI agent via <a href="https://modelcontextprotocol.io">MCP</a>. </p> <p align="center"> <a href="https://glama.ai/mcp/servers/attalla1/photopea-mcp-server"><img src="https://glama.ai/mcp/servers/attalla1/photopea-mcp-server/badges/score.svg" alt="Glama score"></a> <a href="https://www.npmjs.com/package/photopea-mcp-server"><img src="https://img.shields.io/npm/v/photopea-mcp-server.svg" alt="npm version"></a> <a href="https://github.com/attalla1/photopea-mcp-server/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a> <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/photopea-mcp-server.svg" alt="node"></a> </p> <p align="center"> <a href="https://glama.ai/mcp/servers/attalla1/photopea-mcp-server"><img src="https://glama.ai/mcp/servers/attalla1/photopea-mcp-server/badges/card.svg" alt="photopea-mcp-server MCP server"></a> </p>

Demo

<p align="center"> <img src="assets/demo.gif" alt="Demo" width="1000"> </p> <p align="center"> <em>Prompt used in this demo: <a href="examples/album-cover-demo.md">examples/album-cover-demo.md</a></em> </p>

How It Works

Copy & paste โ€” that's it
graph LR
    A[Agent] <-->|stdio| B[MCP Server]
    B <-->|WebSocket| C[Browser]
    C <-->|postMessage| D[Photopea]

Your agent sends editing commands through the MCP protocol. The server translates these into Photopea JavaScript API calls and executes them via a WebSocket bridge to the browser.

Note: A browser window will open automatically on the first tool call. This is expected -- Photopea runs entirely in the browser and the server needs it to perform image editing operations.

Available Tools

Document (5 tools)

ToolDescription
photopea_create_documentCreate a new document with specified dimensions and settings
photopea_open_fileOpen an image from a URL or local file path
photopea_get_document_infoGet active document info (name, dimensions, resolution, color mode)
photopea_resize_documentResize the active document (resamples content to fit)
photopea_close_documentClose the active document

Layer (11 tools)

ToolDescription
photopea_add_layerAdd a new empty art layer
photopea_add_fill_layerAdd a solid color fill layer
photopea_delete_layerDelete a layer by name or index
photopea_select_layerMake a layer active by name or index
photopea_set_layer_propertiesSet opacity, blend mode, visibility, name, or lock state
photopea_move_layerTranslate a layer by x/y offset
photopea_duplicate_layerDuplicate a layer with optional new name
photopea_reorder_layerMove a layer in the stack (above, below, top, bottom)
photopea_group_layersGroup named layers into a layer group
photopea_ungroup_layersUngroup a layer group
photopea_get_layersGet the full layer tree as JSON

Text & Shape (3 tools)

ToolDescription
photopea_add_textAdd a text layer at specified coordinates
photopea_edit_textEdit content or style of an existing text layer
photopea_add_shapeAdd a shape (rectangle or ellipse)

Image & Effects (9 tools)

ToolDescription
photopea_place_imagePlace an image from URL or local path
photopea_apply_adjustmentApply brightness/contrast, hue/saturation, levels, or curves
photopea_apply_filterApply gaussian blur, sharpen, unsharp mask, noise, or motion blur
photopea_transform_layerScale, rotate, or flip a layer
photopea_add_gradientApply a linear gradient fill
photopea_make_selectionCreate a rectangular, elliptical, or full selection
photopea_modify_selectionExpand, contract, feather, or invert a selection
photopea_fill_selectionFill the current selection with a color
photopea_clear_selectionDeselect the current selection

Export & Utility (6 tools)

ToolDescription
photopea_export_imageExport to PNG, JPG, WebP, PSD, or SVG
photopea_load_fontLoad a custom font from a URL (TTF, OTF, WOFF2)
photopea_list_fontsList available fonts, with optional search filter
photopea_run_scriptExecute arbitrary Photopea JavaScript
photopea_undoUndo one or more actions
photopea_redoRedo one or more actions

Development

Copy & paste โ€” that's it
git clone https://github.com/attalla1/photopea-mcp-server.git
cd photopea-mcp-server
npm install
npm run build

Commands

CommandDescription
npm run buildCompile TypeScript to dist/
npm run devWatch mode with auto-reload
npm testRun unit and integration tests
npm startStart the server

Architecture

The server has four main components:

MCP Server (src/server.ts) -- Registers all 34 tools with the MCP SDK and connects via stdio transport.

WebSocket Bridge (src/bridge/websocket-server.ts) -- Manages the connection between the MCP server and the browser. Queues script execution requests and handles responses with timeouts.

Script Builder (src/bridge/script-builder.ts) -- Pure functions that translate tool parameters into Photopea JavaScript API calls. Each builder function generates a script string that Photopea can execute.

Browser Frontend (src/frontend/index.html) -- A single-page app that loads Photopea in an iframe, connects to the WebSocket bridge, and relays scripts to Photopea via postMessage. Returns results back through the WebSocket.

Copy & paste โ€” that's it
src/
  index.ts              # Entry point: HTTP server, browser launch, MCP startup
  server.ts             # MCP server initialization and tool registration
  bridge/
    websocket-server.ts # WebSocket bridge with request queue
    script-builder.ts   # Photopea JS code generators
    types.ts            # Protocol message types
  tools/
    document.ts         # Document operations (5 tools)
    layer.ts            # Layer operations (11 tools)
    text.ts             # Text and shape operations (3 tools)
    image.ts            # Image, adjustment, filter operations (9 tools)
    export.ts           # Export and utility operations (6 tools)
  utils/
    file-io.ts          # Local file read/write, URL fetching
    platform.ts         # Port discovery, browser launch
  frontend/
    index.html          # Browser UI with Photopea iframe

Security

  • The MCP server binds to 127.0.0.1 (localhost only) and is not accessible from the network.
  • The photopea_run_script tool executes arbitrary JavaScript inside Photopea's sandboxed iframe. It is marked as destructive and requires user approval in MCP clients that support tool annotations.
  • File operations (open_file, export_image, place_image) read and write files with the same permissions as the user running the server.

License

MIT