# MCP Server

> Drive the Miso Score engine from Claude and AI agents over stdio MCP with verified Flow readback.

Canonical page: [https://docs.score.miso.fm/ai/mcp/](https://docs.score.miso.fm/ai/mcp/)

The Score MCP server exposes the native `notate` engine over stdio using the official `@modelcontextprotocol/sdk` and `zod`. It contains no music logic of its own: each open score spawns one `notate session` process (the exact JSON-lines session used by the browser editor), and engraving, checks, and MusicXML operations invoke the `notate` CLI directly.

## Setup

Build the Zig engine binary and install the MCP package dependencies:

```sh
cd engine && zig build          # produces engine/zig-out/bin/notate
cd ../mcp && npm install
node test.mjs                   # end-to-end verification
```

### Claude Code

Register the server from the repository root:

```sh
claude mcp add notate -- node "$PWD/mcp/server.mjs"
```

Or add `.mcp.json` to your workspace:

```json
{
  "mcpServers": {
    "notate": {
      "command": "node",
      "args": ["/path/to/score/mcp/server.mjs"]
    }
  }
}
```

### Claude Desktop

Add the entry with absolute paths to `claude_desktop_config.json` (`~/Library/Application Support/Claude/` on macOS, `%APPDATA%\Claude\` on Windows) and restart Claude Desktop:

```json
{
  "mcpServers": {
    "notate": {
      "command": "node",
      "args": ["/path/to/score/mcp/server.mjs"],
      "env": {
        "NOTATE_ROOT": "/path/to/score"
      }
    }
  }
}
```

**Environment variables:**
- `NOTATE_BIN` — path to the engine binary (default: `engine/zig-out/bin/notate`).
- `NOTATE_ROOT` — base directory for resolving relative score paths (default: repository root).

## Tools Reference

| Tool | Purpose | Engine Command / Message |
| --- | --- | --- |
| `notate_spec` | Fetch the current Flow language specification as stated by the engine | `notate spec` |
| `notate_open` | Open a score JSON, MusicXML file, or project; returns `session` ID and readback | `notate session`, `notate import` |
| `notate_close`, `notate_sessions` | Close a session or list active sessions | Session lifecycle |
| `notate_readback` | Read the full Flow 1 document plus its link, layout, style, and project lines | `{"readback": {}}` |
| `notate_flow` | Apply Flow lines as one atomic undo step | `{"flow": {"lines": [...]}}` |
| `notate_preview` | Dry-run Flow lines to inspect remarks or refusals without changing state | `{"preview": ...}` |
| `notate_undo`, `notate_redo` | Step backward or forward through the session draft | `{"undo": {}}`, `{"redo": {}}` |
| `notate_key` | Send a key event using the editor's keymap | `{"key": ...}` |
| `notate_select` | Select by musical address (`Tpt1 9-12`, `Tpt1 12@3`, `Tpt1 12@n2`, `20-42`) | `{"select": ...}` |
| `notate_cmd` | Execute an engine command by name (`popover.open`, keymap commands) | `{"cmd": ...}` |
| `notate_text` | Type text into an open popover or command palette | `{"text": ...}` |
| `notate_message` | Send any other session message or query (`pointer`, `midi`, `state`, `events`, `hit`) | Raw session JSON |
| `notate_draft` | Inspect draft steps, compacted Flow lines, and remarks | `{"draft": {}}` |
| `notate_history` | Inspect draft steps and the current score hash | `draft`, `hash` |
| `notate_hash` | Return the score's BLAKE3 hash including the current draft | `{"hash": {}}` |
| `notate_send` | Compact and verify the draft as one revision (unsigned, local only) | `{"send": ...}` |
| `notate_save` | Serialize the score (including draft) as JSON | `{"score": {}}` |
| `notate_engrave` | Engrave a book or conductor's score to SVG pages (and optionally one PDF with `pdf: true`) | `notate engrave --out`, `--pdf --fonts` |
| `notate_check` | Run the engraver's collision and engraving-quality report | `notate engrave --check` |
| `notate_import_musicxml` | Import MusicXML with full diagnostic report (`open: true` opens a session) | `notate import --json-report` |
| `notate_export_musicxml` | Export MusicXML (`mxl: true` for compressed) with diagnostic report | `notate export-musicxml --json-report` |

The MCP server operates on local sessions and does not sign or publish revisions to a hosted show server.

## Flow Verification Loop

Every tool response returns the engine's exact outcome on its first line (`APPLIED`, `REMARKED`, `REFUSED`, or `MOVED`), followed by the Flow operations, remarks, or refusal message with suggested repairs.

```text
notate_open     {path: "examples/miso-demo/quill-street/numbers/01-every-clock.flow"}
                -> {session: "s1", readback: "..."}

notate_preview  {session: "s1", lines: ["4 Tpt1 add :ff"]}
                -> APPLIED (preview): 4 Tpt1 add :ff

notate_flow     {session: "s1", lines: ["4 Tpt1 add :ff"]}
                -> APPLIED: 4 Tpt1 add :ff

notate_flow     {session: "s1", lines: ["7 Nell: C4 D lyr bad bar"]}
                -> REFUSED: 7 Nell, bar 7: these notes add up to 2 quarter notes
                   but the bar holds 4 (4/4); add a rest of 2 or change a length

notate_readback {session: "s1"}
                -> canonical Flow 1 document reflecting all applied edits

notate_check    {session: "s1", book: "Tpt1"}
                -> 0 collisions; quality report
```

Recommended agent loop:

1. Call `notate_spec` once if you need the engine's exact grammar for the current build.
2. Open the score with `notate_open` and inspect the Flow readback.
3. Dry-run risky or multi-bar edits with `notate_preview`, or apply directly with `notate_flow`.
4. On `REFUSED`, read the engine's exact bar/duration diagnostic, fix the Flow line, and retry; no state changed.
5. Verify visual integrity with `notate_check` (or `notate_engrave`) and revert unwanted steps cleanly with `notate_undo`.
