Patton Story Mapper MCP Server
by FranzAudio
README.md
# Patton Story Mapper
The source of truth is `<project>/backlog/map.md`, using [format v1](docs/FORMAT.md). The HTML is a view of that file. It no longer loads or saves backlog data in browser storage, and standalone HTML export is retired (DEC-22). Existing browser data is left untouched; migrating real legacy data is deferred until needed. AI connection preferences still use their existing separate browser settings key.
Requires Node.js 22 or newer. Install and open an **existing** project backlog:
```sh
npm ci
npm start -- /path/to/project
```
Open the printed `http://127.0.0.1:<port>` URL. A random loopback port is used for each run. Opening the HTML directly does not provide file access. The frontmatter `project` value must match the project folder name exactly, including case, spaces and dots. Missing or invalid backlogs show an error; the browser never automatically initializes a backlog or loads prototype examples as project data. Agents can explicitly initialize a project through MCP. Reload the page to see changes written by another agent or editor.
## Shared write path
`src/format.js` parses and validates the Markdown, including all twelve rules in FORMAT section 8. It reports file/line diagnostics. Unsupported schemas remain available as raw text but are read-only. The browser projection retains unexposed metadata and body paragraphs on save; unchanged documents are byte-identical, and ordinary edits patch only the changed fields. Changed table rows may be normalized; adding an optional column normalizes that table. Slice/story moves carry their complete original text and preserve the order of unrelated stories.
`src/store.js` exports `BacklogStore` for both transports. The HTTP adapter in `src/server.js` serves only the view assets and the backlog endpoint. The MCP adapter in `src/mcp.js` exposes the same store to agents over stdio.
```js
import { BacklogStore } from './src/store.js';
const store = new BacklogStore(projectDirectory);
const current = await store.read();
// Inspect current.problems/readOnly before editing.
// This no-op illustrates the gate; pass explicitly edited Markdown to save a change.
const saved = await store.write(current.text, current.revision);
```
`read()` returns `{text, revision, state, problems, readOnly}`. `write(text, revision)` validates the complete document; `writeView(state, revision)` merges an explicit browser proposal into the current Markdown, preserving fields the UI does not expose. `create(text)` initializes an absent backlog. All three call the same commit gate. Updates must supply the revision actually read; creation instead requires that the target file be absent. Re-read and reconcile a conflict; never retry by attaching a fresh revision to an old proposal.
For updates, the gate takes an exclusive sibling lock, checks the SHA-256 revision, validates the candidate, writes and flushes a temporary sibling, checks the revision again, then renames over `map.md`. Creation validates before creating directories, takes the same lock and flushes the same temporary sibling, then publishes with an atomic hard link that fails if `map.md` already exists. It creates only the exact project directory and its `backlog/`, never missing ancestors. On POSIX the gate also flushes affected directories; updates preserve file permissions. Pre-publication failures leave existing file contents untouched. Readers see complete files. A failure after publication may already have committed; re-read before retrying. The browser does this automatically and reports the failure. Filesystems without hard-link support reject initialization safely; there is no overwriting fallback. An I/O failure may leave newly created empty directories for a retry, but never an intentionally partial `map.md`.
Writers using this module are serialized. An external editor does not obey its lock: revisions catch edits before the final rename, but an arbitrary external write racing the final check/rename cannot be made transactional by a portable filesystem API. Keep one writer at a time, as FORMAT F6 requires. After a process crash, a sibling `map.md.lock` may remain; verify that no writer is running before manually removing that exact lock. Temporary `.map-*.tmp` files from a crashed process are recovery artifacts, never auto-restored as authoritative state.
The HTTP view uses a session token for writes, checks Host/Origin, limits request size, and has request timeouts. It does not expose arbitrary files. It is intended for a local operator, not public hosting.
## MCP for agents
Configure the client to launch Node with the server entry point and an explicit allowlist of project directories. For example, the client's command/arguments settings are:
```json
{
"command": "node",
"args": ["/path/to/storymapper/src/mcp.js", "/path/to/sprout", "/path/to/another-project"]
}
```
Replace those example paths with real absolute paths. This works independently of the client's working directory. Use an absolute Node executable path if the client does not inherit your shell's PATH. To launch from this repository in a terminal:
```sh
node src/mcp.js /path/to/sprout
```
The process waits for MCP messages on stdin; stdout contains only protocol messages and errors go to stderr. Configure clients to launch Node directly, not a plain `npm run` command whose banner would pollute stdout. The server supports modern and legacy MCP clients through the official SDK's stdio entry point. No HTTP listener, credentials or persistent background service is needed for MCP, and no client settings are changed by installing this repository.
Only the supplied directories are accessible. They are resolved to canonical paths; their folder names are the project identifiers. A launch argument may name a not-yet-existing project directory whose parent already exists; the server reserves that exact target in its allowlist without creating it at startup. Duplicate folder names are rejected rather than made ambiguous. There is no directory crawl. A configured directory with no backlog can be listed, but reading it returns a file error and does not create it. Symlinked backlog files/directories are rejected by the shared store.
| Tool | Input | Result |
| --- | --- | --- |
| `list_projects` | `{}` | Configured project identifiers, directories and backlog file paths |
| `read_backlog` | `{project}` | Fresh complete `text`, its `revision`, file path, `readOnly` and diagnostics |
| `write_backlog` | `{project, revision, text}` | The complete saved text and new revision, using the shared validation/atomic-write gate |
| `init_project` | `{project, id_prefix, status_values?}` | An empty valid backlog and initial revision; refuses to overwrite any existing `map.md` |
| `reset_backlog` | `{project, revision, confirmed: true}` | Empty planning sections with the existing frontmatter/configuration retained |
Inputs reject unknown keys and project identifiers. Tool results include both JSON text and equivalent `structuredContent`. Validation and conflict failures return `isError: true` with `error: {code, message, problems}`, where each validation problem retains its original `file`, `line` and `message`. Invalid/unknown-schema reads also return the raw text and revision with `readOnly: true`; write attempts remain rejected. I/O errors are surfaced, never treated as success. After a disconnected call or I/O error, re-read to establish whether a write committed.
Agent workflow: list configured projects, read the chosen backlog, edit the complete Markdown, then submit that text with the exact revision read. Vision, personas, backbone, slices including free-text metrics, and full story bodies/metadata are all writable through the same tool. Whole-document writes do not normalize or transform the supplied text: it is accepted as valid and saved exactly, or rejected. On `CONFLICT`, re-read and reconcile against the new source before retrying. Tool descriptions and server instructions carry this rule as well.
For a new project, call `init_project` with the allowlisted folder name and an explicit 2–4 uppercase-letter `id_prefix`. The optional status list defaults to `todo`, `doing`, `done`. The canonical skeleton is generated by `src/lifecycle.js`: schema-1 project frontmatter, `# Backlog`, empty Vision, header-only Personas/Slices/Backbone tables, and an empty Unassigned section. The Slices table includes the optional metrics column. No personas, slices, activities, stories or placeholder vision are invented. Populate it by submitting the complete edited Markdown through `write_backlog` with the returned revision; no separate populate tool exists.
For reset, obtain explicit operator confirmation in chat, read the current backlog, then call `reset_backlog` with that revision and `confirmed: true`. Omitted or false confirmation is rejected. Reset deletes vision, personas, slices, activities and all story bodies; it retains frontmatter byte-for-byte, including comments, status vocabulary, mappings and extra configuration. Stale revisions and unsupported schemas still fail. This uses the normal validated update path and does not create backups or commit to git automatically; versioned content can be recovered from project history.
## Verification
```sh
npm test
npx playwright install chromium
npm run test:browser
```
The unit/integration suite covers validation errors without disk mutation, exact round trips, references/extra metadata, CRLF/BOM, ordering, completed-story retention, stale/concurrent writes, and HTTP validation/conflict boundaries. Lifecycle checks cover valid empty skeletons, invalid/concurrent/no-clobber initialization, exact-target directory creation, symlink rejection, confirmation, stale reset rejection, frontmatter retention, and empty-to-populated writes. MCP tests launch real stdio subprocesses and verify protocol negotiation, strict tool inputs, project listing, reads/writes, all writable entities, exact shared diagnostics, read-only schemas, conflicts between MCP and HTTP writers, and init/populate/reset. The Chromium suite checks save/reopen against the file, ignored old browser/embedded snapshots, inert closing-script/event-handler text, filtered Sortable callbacks, and rejected invalid/stale proposals. Browser tests use the production scripts with the existing Sortable version served offline; they do not assert visual styling or physical drag gestures.
Prototype templates remain as examples in the source, but their load action is retired. Existing AI operations and legacy imports now submit to the same validation gate; proposals using old IDs, invalid categories or missing references are rejected. Their proposal quality and migration are separate work. Referenced personas or activities must be reassigned before deletion.
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues