What is in this repo is based on the April 2026 (3.2) release of Affinity.
- The MCP server has access to a bunch of documentation that an AI agent can use as reference for creating scripts etc. The
extract_docs.jsscript below can extract all these docs and save them locally so you can take a look at them. This includes some example affinity scripts. - Affinity has a scripts panel (Window > General > Scripts) which lets you see and run scripts created by the AI. However you cannot see the actual script's code, edit it or create your own scripts in the UI. The
script_mgr.jsscript below can be used to manage scripts in the library (add, list, save to disk). - The documentation tells the AI agent to use
search_sdk_skillsto search for solutions before creating its own. This doesn't actually exist in the list of MCP tools but there is asearch_sdk_hintstool. Thesearch_sdk.jsscript below can be used to call this tool, just pass it a search query. In my testing the returned results are not that accurate but they will no doubt get better over time, because the description for that tool says Search a global pool of SDK hints from millions of other MCP sessions. Use it to check for existing solutions to problems you are facing. - There is a
add_sdk_hinttool in the MCP which I'm guessing goes hand in hand withsearch_sdk_hintsbut it's documentation seems to indicate that actually updates thepreambledoc.
- enable the Affinity MCP connector: https://www.affinity.studio/help/ai-connector-setup/#configure-affinity NOTE: You do not need to set up Claude or the Claude connector
- Node.js installed
- Dependencies installed with
npm install - MCP server available at
http://localhost:6767/sse
To look at the Affinity MCP server and see what it can do, you can use the MCP Inspector tool:
npx @modelcontextprotocol/inspector --sse http://localhost:6767/sseDownloads all SDK documentation topics from MCP and saves them under docs/, preserving any nested paths returned by the server.
Run:
node extract_docs.jsSearches SDK hints using MCP and prints the response to the console.
Run:
node search_sdk.js "blend mode"Manages scripts in the Affinity script library.
Commands:
node script_mgr.js list
node script_mgr.js add --title "Hello World" --description "Says Hello World" --file helloworldexample.js
node script_mgr.js save --title "Hello World"
node script_mgr.js save --title "Hello World" --out exports/hello-world.jslist: lists installed library scriptsadd: adds a script from a local filesave: reads a library script and saves it to disk
NOTE: You cannot delete a script via the MCP so you will need to delete them in Affinity in the scripts panel.
markdown_import_to_text_frame.js was written using Codex via the Affinity MCP. It imports a markdown file into the currently selected text frame, mapping markdown elements to Affinity text styles.
You can test it by selecting a text frame in Affinity, running the script (by clicking on it in the scripts panel) and selecting a Markdown file when prompted. Note: The Markdown file must be on your desktop for the file picker to be able to select it.
Install with
node script_mgr.js add --title "Markdown import to selected text frame" --description "Imports a Markdown file into the selected text frame" --file markdown_import_to_text_frame.jsYou need to register the Affinity MCP server with Codex. It does have issues accessing the MCP server over SSE so you need to proxy it via stdio.
codex mcp add affinity -- uvx mcp-proxy --transport sse http://localhost:6767/sseYou will need python and uv installed for this to work
- The code in this repo was thrown together by Codex as I was tinkering so don't expect any masterful coding here
- Don't use this code or the MCP to do dumb and/or illegal things!