LiminaliaLiminalia
Technical docs: Using Liminalia from AI assistants (MCP)

Using Liminalia from AI assistants (MCP)

Open in Claude (new tab)
On this page

lim mcp is an MCP server (over standard input and output) for using Liminalia from AI assistants such as Claude Desktop, Claude Code and Codex. Ask for a visual novel, and the assistant can take it all the way: creating the project, writing the scenario, checking it, running it, confirming the result with screenshots and exporting it.

Tools

ToolWhat it does
list_projectsLists the projects in the project roots
create_projectCreates a project from a template (title, screen size, sound novel, blank, source language, and with ci the GitHub Actions check and a script test)
list_filesLists the scenarios, assets and characters
read_scenarioReads a scenario (a .lim in the scenario folder) and returns hash at the end. With numbered, the lines are numbered
write_scenarioSaves a whole scenario. For a scenario that already exists, pass the hash from when you read it as baseHash (see “Using it with Studio” below). If saving would add errors, it doesn’t save (see “Not adding errors” below). After saving, checks the whole project and returns the result
edit_scenarioRewrites some lines of a scenario. Confirms the lines before the rewrite (expect) and then saves. If that would add errors, it doesn’t save. After saving, checks the whole project
restore_scenarioRestores a scenario to an earlier version in .liminalia/history/. Without id, it’s the version just before (the contents before the last save); with list, returns the list of versions. If restoring would add errors, it doesn’t restore
apply_fixesApplies the suggested fixes attached to diagnostics (replacing a name with a similarly spelled one, deleting an unneeded line, combining several lines into one and so on; the same as “Fix” in Studio) and saves. Narrow them down with codes and lines. Suggested fixes that rewrite things outside the line, such as adding a speaker, aren’t applied and are returned
fmtTidies scenarios (the same as lim fmt). Without file, all of them (pack scenarios too, which can be named as packs/<id>/scenario/<scenario>). A scenario with syntax errors isn’t tidied, and the reason is returned. The previous version is kept in the history
read_castReturns as JSON the characters’ (cast.json) speaker names, name colors, sprite sets (the default one), variants (the base variant), positions (the names you can write in at=, and auto), layers of composited sprites, and the list of speakers. who narrows it to one character
list_macrosThe macros (@define): name, parameters (name: type = default), summary (the // lines just above), location, whether @with can pass content (whether it has @content), and how many times it’s called
line_stateThe stage at a scenario line (background, sprites, BGM, looping sound effects, window and so on), the variables, and the choices made up to there (the same as the current position in Studio). line, or from to to (up to 50 lines)
check_textChecks a scenario’s contents without saving and returns that file’s diagnostics as JSON (the same rules as ctx.check for Studio plugins)
checkChecks all scenarios (lim check). With format set to json, returns the JSON from lim check --json
queryLooks up definitions and references as JSON (lim query --json). Pass project and kind (label, var, asset); omit name for an inventory. Unknown names return candidates and isError
scenario_guideA guide to writing scenarios (kinds of lines, dialogue, labels, inline markup such as ruby, value types, sprites, choices, @if, variables and expressions, macros, expression functions). The resource liminalia://guide/scenario is the same thing
traceThe result of running without a screen (lim trace). The [N] at the start of each page is its number, counted from 1 from the start position; pass it to skip of screenshot (lim shot --skip, the player’s ?skip=) to stop at that page
screenshotReturns a screenshot as an image (lang sets the language; lim shot --lang). If the project is open in the Studio app or lim studio, it’s taken with that dev server; if not, with lim shot (Chromium is required). See “Using an open Studio” below
list_screensReturns the built-in screens (save, settings, log, ending and so on) as JSON. For each screen: its name, whether it opens with sample content (the reason if not), the states you can pick, the parts table (part name, CSS selector, and the theme values and CSS variables that decide its look), theme values, text keys, CSS classes and variables, and replacement hooks. With project, the themes you can pick are returned too. screen narrows it to one screen (the same as the tables in screens.md)
screen_shotOpens a built-in screen with sample content, captures it and returns the image (lim shot --screen; the same sample as “Game screens” in Studio). You can pick state (filled, empty or long), orientation (portrait or landscape; another orientation than the project’s swaps width and height), lang and theme. If it can’t open, the reason and problems are returned. If it captures but the screen isn’t visible, something still covers it (a load curtain or a full-screen effect layer) or the sample content isn’t showing, the image comes back with ok set to false and the reasons in problems. If a plugin replaces the screen, replacedBy names the plugin. Chromium is required
copy_screenCopies a built-in screen template into the project (same as lim screens copy). It goes to ui/screens/<screen>/<screen>.html (or the registered location), is registered in ui.templates, and the copied original is kept in .liminalia/screens/. parts copies only those parts, js also puts a screen JS skeleton. Existing files (parts) aren’t rewritten without force. Returns the file, the parts, whether it was registered, overriddenBy when a plugin comes first, and the template check after copying (diagnostics)
read_screen_filesReads a screen’s files: the project’s template (text is null if missing), the current built-in template and its part names, the screen rules (the data-role and data-field values that work, the required data-role), the screen JS and the project CSS (ui.css)
write_screen_fileWrites a screen’s file. kind is template (registered if it isn’t), script (the screen JS) or css (project CSS; pick it with file; without ui.css it writes ui/screens.css and registers it). After writing, runs the same template check as lim check (the project CSS check for css) and returns diagnostics and ok (no errors)
diff_screenHow the project’s template differs from the built-in one (same as lim screens diff): for each part, the diff from the current built-in part to the project’s (authorDiff), what changed in the built-in template since the copied version (standardChange), and a readable form (text)
command_referenceCommand specs. Narrow them down by putting what you want to do (“shake”, “fade to black”, “rain”) or a name in query
set_themeApplies a theme for the look of the whole game (Default, Washi, Night, Pastel, Terminal, Mansion, Near Future, School, Chat for portrait projects only, or themes/<id>/theme.json in the project) and copies its assets into the project. Trying to apply a portrait-only theme to a landscape project is refused, with the reason
install_pluginInstalls an official plugin (leave out the id to get the list)
import_assetCopies a file on this computer into the assets (you specify the kind)
register_characterRegisters a character (a person in cast.json) and links sprites to it, along with the name color, speaker name, sprite sets and default variant. Images given as absolute paths on this computer are copied to assets/fgimage/<character folder>/
read_settings / update_settingsReads / changes the project settings (title, version, author, screen size, start position, saves, export and so on) and the initial values of variables
list_variablesThe variables used in the scenarios, their initial values, and the lines that set and read them
searchSearches all scenarios (text only, regular expressions, treating hiragana and katakana, the two Japanese syllabaries, as the same)
story_mapThe branching map (scenes and how they connect; the same as the flowchart)
coverageThe all-routes test (lines reached and not reached, diagnostics from running). Pack scenarios are run too, with the packs laid over the main scripts as in lim coverage
text_statsCharacter counts (total, per file, per scene, per speaker) and possible spelling variants
rename_labelRenames a scene (label), and updates jump targets and references in liminalia.json too
i18n_syncUpdates the translation file of a language (lang/<language>.json) to the current scenarios (the same as lim i18n). With stampIds, fixed line IDs (#line:) are stamped first (lim i18n --stamp-ids)
read_translationReturns the translation, updated to the current scenarios, as JSON in pages. By default only items without a translation (with only set to changed, items whose source changed after translation; with all, everything). file narrows it to a scenario, and offset and limit (default 100) split it. Each item has the key, the source, the translation, the previous source and translation, the source when translated, and the place (file, line, scene, previous and next lines). Returns hash
write_translationSaves translations per key (pass the hash from read_translation as baseHash). Translations of text lines and choices are checked for how they’re written, and unreadable ones aren’t saved; which item it was and the reason are returned. With source, items whose source changed aren’t saved
voice_scriptReturns as JSON the rows of the recording script (the same as lim voice-script: voice file, speaker, line, acting notes, previous line, scene, place, why it won’t play, needs re-recording). Narrow it with speaker, and split it with offset and limit. With write, writes CSV files to exports/voice-script/
open_studioOpens Studio and returns its URL (for when a person edits by hand). If Studio is already open, uses that
buildExports (browser, mac, windows, linux)
run_testsRuns the scenario tests (tests/*.limtest; lim test --json) and returns each test’s result as JSON. paths narrows it to files or folders
reachSearches for choices that reach a place from the start (lim reach --json): target (file#label, file:line, file), ending (kind or name of an ending) or endings (every ending). When found, it also returns a test that can be written as is (test)
migrateMoves scenarios and settings to the current format (lim migrate --json). By default nothing is rewritten and it only returns what would move; with write, it rewrites. keepBehavior also writes settings that keep the old behavior (--keep-behavior)
renameRenames something and rewrites the references too (lim rename; kind is label, file, variable, character, speaker, asset or macro)
playtestPlays the exported browser version to the end automatically and returns the errors and where it stopped as JSON (lim playtest --json --fast --log; rebuild exports first)
read_playtest_logReads the log of lim playtest --log (playtest/run-N.jsonl in the export folder) and returns the pages and choices in order as JSON. run picks which run, and offset and limit (default 200) split it
read_crash_reportReads a crash record of an exported game, maps the program positions back to the original files and lines with the kept source maps, and returns them as JSON next to the scenario positions (lim crash --json)
record_videoRecords video from that position while advancing at real speed (lim shot --video; needs ffmpeg and Chromium). Output goes only inside the export folder. split, until, resume, redo (records one part again)

The tools run lim commands in child processes (so that the progress the commands write to standard output doesn’t get mixed into the MCP communication). Reading and writing scenarios, the check before saving, the command reference and the guide write no output, so they run in the same process (even if a project plugin loaded in that process writes output with console.log, it’s sent to standard error).

The tools from register_character onward call the same processing as Studio’s dev server API (@liminalia/studio/server, and @liminalia/web/caster-server, the save API of the sprite position editor) in the same process (packages/cli/src/commands/mcp-studio.ts). The rules and the change history are the same as in Studio:

  • register_character: the rules for character IDs (no spaces and none of " = ( ) # @), adding a character also adds it as a speaker, the castProblems check, not saving if the file was rewritten elsewhere after it was read, keeping the contents before saving in .liminalia/backups/cast-<date and time>.json, and, for projects made by import, writing back to the import source too. The position and size of a variant (frame) are fitted to the non-transparent part of the base variant (normal → default → the first variant), the same as when you drop an image onto Studio; without a base variant, the image is fitted to the screen (the transparent parts of the PNG are read in this process; packages/cli/src/image-info.ts). For a variant with the same name, only the image is replaced
  • update_settings: settings is laid over the current settings (objects are merged all the way down, and items set to null are removed). The shape check and, when baseHash is passed, the check that nothing was changed elsewhere after reading work the same as on the “Project” screen (setSettings). Initial values of variables work the same as on the “Variables” screen (setVariable; they can’t be set for temp.). The previous liminalia.json is kept in .liminalia/history/@config/. Settings that run outside commands or modules (build.windows.wrap, build.windows.sign, build.mac, build.store.desktop, build.store.android), allowScript (which allows scripts in the scenario), and paths and import (which can point outside the workspace) can’t be changed (so instructions planted in documents the AI reads can’t use them; the user changes them in liminalia.json or in Studio)
  • rename_label: the same as renaming a scene (renameLabel). The scenario change history is kept in .liminalia/history/
  • line_state: the current position in Studio (sweep of StudioWorkspace, made by running from the beginning as in the game). For text and choice lines it’s the state just before the line is shown, and for command lines just after it runs. Lines never reached are reached: false. It’s remembered until a scenario is rewritten, so it’s fast from the second time on
  • read_translation and write_translation: the same as the Translation screen in Studio (readTranslation and writeTranslation). The previous translation file is kept in .liminalia/history/@lang/<language>/. For languages other than Japanese and English, the system screen text is listed too, as ui:key items (the source is English)

read_cast, list_macros, line_state, the tools for translation and the voice script, restore_scenario, apply_fixes and fmt are in packages/cli/src/commands/mcp-authoring.ts. The tools from run_tests to record_video are in packages/cli/src/commands/mcp-testing.ts, and all of them run lim commands in child processes. list_screens, screen_shot, copy_screen, read_screen_files, write_screen_file and diff_screen are in packages/cli/src/commands/mcp-screens.ts. screen_shot runs lim shot --screen --json in a child process. Copying and diffing are the same as lim screens (@liminalia/project/screen-copy).

The instructions in the first exchange (initialize) tell the assistant to read scenario_guide before writing for the first time, and explain hash and baseHash, edit_scenario and check_text, read_cast and list_macros, not saving when errors would increase (allowErrors), restore_scenario, list_screens and screen_shot for changing the look of a built-in screen, and copy, edit, then capture (copy_screen, read_screen_files, write_screen_file, screen_shot, diff_screen) for changing its shape.

Not adding errors

Before saving, write_scenario, edit_scenario, restore_scenario and apply_fixes check the project as it would be before and after the save, and compare them (the diagnostics of that scenario and the checks across scenarios, counted by file, code and message, ignoring line numbers). If errors would increase, nothing is saved, and the added errors are returned as JSON (addedErrors). The AI fixes them and saves again. If errors that were already there just remain, it saves.

To save even with errors, set allowErrors to true (the earlier behavior; for example, when saving a scenario partway through writing it). What was saved can be restored to the version just before with restore_scenario.

Changing a built-in screen and checking it

When the author asks to change the look of a built-in screen, such as “put the save slots side by side,” the AI goes through these steps.

  1. With screen of list_screens (for example saveload), read the parts table of that screen and pick the part to change (such as .lm-slots) and the theme value that applies (such as saveSlots)
  2. Change ui in liminalia.json with update_settings (for a part with no value in the parts table, override its selector in the project’s CSS)
  3. Capture it with sample content using screen_shot and check it. Use long for state for lots of content and long text, empty for an empty screen, and portrait for orientation for a portrait screen

screen_shot starts a dev server and a headless Chromium each time it captures (it doesn’t use an open Studio). The sample content only exists inside the page, and nothing is written to the project’s files or the player’s saves. For a replaced screen (replacedBy), the built-in parts table and theme values may not apply.

Change the shape of a built-in screen (copy, edit, then capture)

For a shape that theme values and project CSS can’t reach, such as reordering buttons or adding elements, copy the built-in screen template into the project and edit it (design/screen-templates.md).

  1. Copy it with copy_screen (for example confirm). Right after copying, it works the same as the built-in screen
  2. Read the copied template and the screen rules (the data-role and data-field values that work) with read_screen_files
  3. Write the template (HTML and attributes), project CSS or screen JS with write_screen_file. The template check comes back after writing; fix any errors and write again
  4. Capture it with screen_shot and check it

When lim check reports template-outdated after an engine update, see what changed in the built-in template with diff_screen, copy it again, and set the part’s data-version to the current version.

The scenario writing guide

scenario_guide is a short version of design/format.md for AI (packages/cli/src/commands/scenario-guide.ts). It doesn’t list the parameters of each command, and leaves those to command_reference. The table of expression functions is made from the same table as lim reference (FUNCTION_* in @liminalia/lang). packages/cli/test/scenario-guide.test.ts checks that the guide contains format.md’s main headings, the list of inline markup, how the tables of line kinds and value types are written, and every expression function name, so when you edit format.md, update the guide to match.

Using it with Studio

Writing scenarios uses the same code as Studio’s dev server (write of StudioWorkspace in @liminalia/studio/server).

  • Pass the hash that read_scenario returns as baseHash to write_scenario. If the scenario was edited in Studio (or another editor) after it was read, nothing is saved, and the current contents and hash are returned. The AI adjusts its changes to them and saves again. A scenario that already exists isn’t saved without baseHash (it can be left out only for new scenarios)
  • edit_scenario takes the same form as ctx.script.apply for plugins (from, to, expect, text; plugins.md). It checks only that the lines being rewritten are unchanged, not the whole file, so it can save even while someone keeps writing other lines in Studio
  • The contents before saving are kept in .liminalia/history/<file>/, the same as when saving in Studio (you can restore them from “Change history” in Studio)
  • If Studio is open, the dev server’s file watching reports the write as an outside change, and an open scenario is merged with the text being edited (Studio waits while you’re typing, and when changes to the same line overlap, you choose in Studio)

Using an open Studio

When the Studio app (engine/run.ts in packages/studio-desktop) or lim studio opens a project, it writes the dev server’s URL and process to .liminalia/studio-server.json in the project, and deletes it when it quits (@liminalia/studio/running). The MCP server reads this file, and uses it only when the process is running and the dev server answers that it has the same project open (GET /__liminalia/studio/api/server). A file left behind by a crash is treated as if it weren’t there.

  • open_studio: if Studio is open, returns its URL without starting another dev server. An MCP server registered from the Studio app (the app’s executable run with ELECTRON_RUN_AS_NODE, where process.versions.electron exists) runs the app’s executable as a launch that opens the project (if the app is already running, the running app opens it or comes to the front), waits until the dev server starts, and returns the URL. The app in development receives the app’s folder in LIMINALIA_STUDIO_APP_PATH (“Connect an AI Assistant…” writes it into the registered settings). If neither applies, it starts lim studio as before
  • screenshot: if Studio is open, takes the screenshot with POST /__liminalia/studio/api/shot/play on that dev server (opened and waited for the same way as lim shot; the Studio app takes it in a hidden window of the app, so neither playwright nor Chromium is needed). If not, it takes it with lim shot. If playwright-core or Chromium is missing (always the case for an MCP server registered from the Studio app), it refuses and says to open the project with open_studio and try again

Where the tools can reach

The tools can read and write only inside the “project roots”. The roots are set with --root (as many as you like) and the environment variable LIMINALIA_MCP_ROOTS (separated by the OS path separator); if neither is given, the root is ~/Liminalia. A project is specified by its folder name in a root, or by an absolute path pointing inside a root. Reading and writing scenarios is limited to .lim files in the scenario folder (paths.scenario in liminalia.json; scenario/ by default).

Connecting (desktop version)

From “Help → Connect an AI Assistant…” in the desktop version’s menu, choose Claude Desktop, Claude Code or Codex, then choose the folder where the AI may put projects (the project root), and Liminalia is registered in that assistant’s settings. You don’t need Node or npm (the app’s executable is started as Node with ELECTRON_RUN_AS_NODE=1, and runs the mcp processing of the engine inside the app).

  • Claude Desktop: writes mcpServers.liminalia in claude_desktop_config.json (other servers and items are kept, and the contents before the change are kept in .bak)
  • Claude Code: runs claude mcp add-json --scope user liminalia … (the claude command is required)
  • Codex: rewrites the [mcp_servers.liminalia] section of ~/.codex/config.toml (in CODEX_HOME if that’s set) (other sections are kept)

After registering, restart that assistant. How each one is written is in packages/studio-desktop/src/shared/assistants.ts.

Connecting (running from this repository)

Claude Code:

claude mcp add liminalia -- node /path/to/liminalia/packages/cli/bin/lim.mjs mcp --root ~/Liminalia

Codex (~/.codex/config.toml):

[mcp_servers.liminalia]
command = "node"
args = ["/path/to/liminalia/packages/cli/bin/lim.mjs", "mcp", "--root", "/Users/me/Liminalia"]

Claude Desktop (mcpServers in claude_desktop_config.json):

{ "liminalia": { "command": "node", "args": ["/path/to/liminalia/packages/cli/bin/lim.mjs", "mcp", "--root", "/Users/me/Liminalia"] } }

You need the same version of Node.js as in the getting started section of the README.