Skip to main content
Glama
affinity-mcp

affinity-mcp

by StevenJPx2

affinity-mcp

affinity-mcp is a small stdio MCP adapter for Affinity 3's local legacy SSE MCP connector. It exposes the connector's tools with stable affinity_ names and manages the upstream session for you: it connects on first use, reads the required SDK preamble, and reconnects (re-reading the preamble) if Affinity quits.

MCP host <-> stdio <-> affinity-mcp <-> legacy SSE <-> Affinity 3

The adapter always starts, whether or not Affinity is running. Any Affinity tool call opens Affinity if needed: it first tries to reconnect (in case Affinity is running but the session dropped), and only then launches it with macOS open -g -b com.canva.affinity in the background without stealing focus, waiting for the connector at http://localhost:6767/sse. If Affinity still cannot be reached, the tool returns AFFINITY_UNAVAILABLE with the reason. Nothing else activates, focuses, or scripts the application.

Install

Requires Node.js 22 or newer.

npm install
npm run check
npm link

Related MCP server: figma-local-bridge

Configuration

  • AFFINITY_MCP_URL: Affinity SSE endpoint. Default: http://localhost:6767/sse.

  • AFFINITY_SCRIPT_TIMEOUT_MS: upstream call timeout in milliseconds. Default: 300000.

  • AFFINITY_BUNDLE_ID: macOS bundle identifier affinity_open launches. Default: com.canva.affinity.

  • AFFINITY_LAUNCH_TIMEOUT_MS: how long affinity_open waits for the connector after launching. Default: 120000.

Generic stdio MCP configuration for OpenCode, Claude Desktop, or another MCP host:

{
  "mcpServers": {
    "affinity": {
      "command": "affinity-mcp",
      "env": {
        "AFFINITY_MCP_URL": "http://localhost:6767/sse",
        "AFFINITY_SCRIPT_TIMEOUT_MS": "300000"
      }
    }
  }
}

Without npm link, use the absolute built executable:

{
  "mcpServers": {
    "affinity": {
      "command": "node",
      "args": ["/absolute/path/to/affinity-mcp/dist/index.js"]
    }
  }
}

Tools

Adapter lifecycle:

  • affinity_status: connection state (disconnected with a reason, connecting, or connected). Never launches Affinity.

  • affinity_open: launches Affinity if needed, waits for the connector, and connects. Every other tool does this implicitly; use it to warm Affinity up ahead of a long session.

Document management (implemented as SDK scripts over the connector's execute_script; each opens Affinity first if needed):

  • affinity_list_documents: open documents with session_uuid, title, path, is_dirty, is_current.

  • affinity_new_document: create from a preset name ({ "preset": "A4" }) or explicit size ({ "width": 1080, "height": 1080, "units": "Pixel", "dpi": 72 }), optionally saving to save_as. An unknown preset fails with the list of available names.

  • affinity_open_document: open a file by absolute path, or return it if already open. Paths outside Affinity's permitted folders (Desktop by default) fail with PERMISSION_DENIED.

  • affinity_get_document_settings: read pixel dimensions, dpi, units, colour format and profile, mask format, layer and artboard counts, fonts, and dirty/undo state. Defaults to the current document; pass session_uuid to target another.

  • affinity_set_document_settings: change units, dpi, width_pixels/height_pixels, and transparent_background, returning the updated settings. Units use a dedicated command; dpi, size, and transparency rewrite document setup (other settings are preserved, but background transparency resets to opaque unless transparent_background is given).

Content and output (also SDK scripts over execute_script; each opens Affinity first if needed):

  • affinity_export: export to an absolute path as png, jpeg, tiff, pdf, svg, webp, or gif. area is whole_document (default), current_spread, current_page, or selection. Writing outside Affinity's permitted folders (Desktop by default) fails with PERMISSION_DENIED.

  • affinity_add_shape: add a rectangle or ellipse at pixel x, y, width, height with an optional #RRGGBB/#RRGGBBAA fill.

  • affinity_add_text: add a text frame with text at pixel x, y, width, height, using the document's default text style.

  • affinity_place_image: place an image file; give x, y, width, height to fit a rectangle or omit them for natural size. Reading outside permitted folders fails with PERMISSION_DENIED.

Content tools return the target session_uuid and the document's new layer_count. Script failures from all script-backed tools are reported as AFFINITY_SCRIPT_ERROR.

Affinity connector tools (unchanged upstream semantics; each opens Affinity first if it is not running):

  • affinity_add_sdk_hint

  • affinity_execute_script

  • affinity_list_library_scripts

  • affinity_list_sdk_documentation

  • affinity_read_library_script

  • affinity_read_sdk_documentation_topic

  • affinity_render_selection

  • affinity_render_spread

  • affinity_report_sdk_issue

  • affinity_save_script_to_library

  • affinity_search_sdk_hints

Security

affinity_execute_script runs JavaScript inside Affinity and can modify open documents. Depending on Affinity's settings, scripts may also use AI, networking, or limited filesystem capabilities. Review generated scripts and keep Affinity's permissions restricted to what the task requires.

The only process the adapter starts is open -g -b <bundle id>, run only when Affinity is not reachable and only on macOS. It never uses osascript or asks Affinity to become the active application.

Architecture

  • src/affinity-client.ts owns the lazy upstream SSE session: connect on demand, preamble read per session, timeout, dropping the session when the event stream errors or a send fails, and error normalization.

  • src/affinity-launcher.ts launches Affinity and waits (bounded) for the connector.

  • src/script-runtime.ts builds each generated script (a marker-line success/failure protocol, since Affinity reports uncaught script exceptions as plain text with isError: false) and decodes the result.

  • src/documents.ts, src/document-settings.ts, src/export.ts, and src/primitives.ts build the document, setup, export, and content scripts on that runtime and define their result schemas.

  • src/server.ts defines the typed stdio-facing tools and delegates calls without changing upstream text, image content, or isError.

  • src/index.ts serves stdio immediately, attempts an opportunistic upstream connection, and closes both sides during shutdown. Diagnostics use stderr only.

Available Tools

22 tools
affinity_add_sdk_hintC

Add a verified SDK hint to Affinity's preamble for future sessions.

Inputs: hint (required).

affinity_add_shapeA

Add a rectangle or ellipse at pixel coordinates (x, y, width, height) with an optional #RRGGBB or #RRGGBBAA fill. Defaults to the current document; pass session_uuid to target another.

Inputs: x (required), y (required), kind (required), width (required), +3 more.

affinity_add_textA

Add a text frame containing text at pixel coordinates (x, y, width, height), using the document's default text style. Defaults to the current document; pass session_uuid to target another.

Inputs: x (required), y (required), text (required), width (required), +2 more.

affinity_execute_scriptC
Destructive

Execute JavaScript in Affinity. This can modify documents and access capabilities allowed by Affinity settings.

Inputs: script (required).

affinity_exportA

Export a document to an absolute path as png, jpeg, tiff, pdf, svg, webp, or gif. area is whole_document (default), current_spread, current_page, or selection. Affinity's filesystem setting limits where files can be written; the Desktop is allowed by default. Defaults to the current document.

Inputs: path (required), format (required), area, session_uuid.

affinity_get_document_settingsA
Read-onlyIdempotent

Read a document's setup: pixel dimensions, dpi, units, colour format and profile, layer and artboard counts, fonts, and dirty/undo state. Defaults to the current document; pass session_uuid to target a specific one.

Inputs: session_uuid.

affinity_list_documentsA
Read-onlyIdempotent

List the documents currently open in Affinity with their session UUIDs, titles, paths, and dirty state.

Inputs: no named parameters.

affinity_list_library_scriptsB
Read-onlyIdempotent

List scripts in Affinity's script library.

Inputs: no named parameters.

affinity_list_sdk_documentationB
Read-onlyIdempotent

List available Affinity SDK documentation topics.

Inputs: no named parameters.

affinity_new_documentA

Create a new Affinity document, either from a named preset (for example 'A4', 'IG Post', 'Icon') or from explicit width, height, and units. Optionally save it straight to save_as. Returns the document's session UUID for later tools.

affinity_openA
Idempotent

Launch Affinity if it is not running, wait for its local MCP connector, and connect. Other tools do this automatically; use this to warm Affinity up ahead of time.

Inputs: no named parameters.

affinity_open_documentA

Open an existing document from an absolute path (or return it if it is already open). Affinity's filesystem setting limits which folders are readable; the Desktop is allowed by default.

Inputs: path (required).

affinity_place_imageA

Place an image file into the document. Give x, y, width, height to fit it to a rectangle, or omit them for the image's natural size. Affinity's filesystem setting limits which folders are readable; the Desktop is allowed by default. Defaults to the current document.

Inputs: image_path (required), x, y, width, +2 more.

affinity_read_library_scriptC
Read-onlyIdempotent

Read a named script from Affinity's script library.

Inputs: title (required).

affinity_read_sdk_documentation_topicC
Read-onlyIdempotent

Read an Affinity SDK documentation topic by filename.

Inputs: filename (required).

affinity_render_selectionC
Read-onlyIdempotent

Render the selected nodes in a document session as a JPEG.

Inputs: document_session_uuid (required).

affinity_render_spreadC
Read-onlyIdempotent

Render a zero-based spread in a document session as a JPEG.

Inputs: spread_index (required), document_session_uuid (required).

affinity_report_sdk_issueB

Report a confirmed Affinity SDK issue with optional reproduction code.

Inputs: description (required), code.

affinity_save_script_to_libraryC
Destructive

Save a completed JavaScript script to Affinity's script library.

Inputs: code (required), title (required), description (required).

affinity_search_sdk_hintsC
Read-onlyIdempotent

Search shared Affinity SDK hints for an existing solution.

Inputs: prompt (required).

affinity_set_document_settingsA
Destructive

Change a document's setup and return the updated settings. Supports units, dpi, pixel width/height, and transparent_background. Changing dpi, size, or transparency rewrites document setup; other settings are preserved, but background transparency resets to opaque unless transparent_background is given. Defaults to the current document; pass session_uuid to target a specific one.

Inputs: dpi, units, session_uuid, width_pixels, +2 more.

affinity_statusA
Read-onlyIdempotent

Report whether the adapter is connected to Affinity's local MCP connector. Does not launch Affinity.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 22 tools

    Disambiguation4/5

    Most tools have clearly distinct resource/action targets, such as document lifecycle, settings, export, and rendering. The main overlap is in the SDK/scripting cluster, where add_sdk_hint, search_sdk_hints, read_sdk_documentation_topic, report_sdk_issue, save_script_to_library, and execute_script require careful reading to distinguish.

    Naming Consistency4/5

    All tools use the affinity_ prefix with snake_case, giving a predictable namespace and mostly verb_noun naming. A few standalone operations like affinity_status and affinity_open are minor deviations but remain readable.

    Tool Count3/5

    The 22-tool surface is broad but feels heavy for the core purpose. While each tool has a plausible role, the scripting and SDK documentation tools push the count into a crowded range.

    Completeness4/5

    The set covers connection, document creation/open/listing, settings, export, basic shape/text/image insertion, rendering, and scripting/SDK support. Gaps remain around closing/deleting documents and deeper layer/selection editing, but execute_script provides a workaround.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to read and modify the currently open Figma design file through a paired local Figma plugin, supporting operations like creating nodes, editing properties, and exporting PNG/SVG.
      2
      MIT
    • A
      license
      C
      quality
      B
      maintenance
      Enables MCP clients to inspect and modify SketchUp models through a local authenticated bridge, covering entity creation and editing, geometry, materials, tags, cameras, scenes, transactions, snapshots, and file or view export. It also offers an optional full SketchUp Ruby API execution channel and batch operations for furniture, architectural, and analysis tasks.
      37
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables local MCP-capable assistants to connect to Figma Desktop to read documents, pages, and selections, edit native layers and components, and export PNG/SVG across multiple files without Figma API keys.
      2
      MIT