Skip to content

Developer MCP: Digitone II tools over MIDI - #1846

Draft
prodbysmolec wants to merge 12 commits into
repeat98:mainfrom
prodbysmolec:improve/digitone-ii-mcp-tools
Draft

prodbysmolec wants to merge 12 commits into
repeat98:mainfrom
prodbysmolec:improve/digitone-ii-mcp-tools

Conversation

@prodbysmolec

@prodbysmolec prodbysmolec commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Developer MCP: Digitone II tools over MIDI (piece 7, first step). Stacked on #1844 (the site's upload transport), itself on #1823 (the link client): until they merge, this branch carries their commits too.

  • What was wrong or hard: The recipe asks every machine for device tools in the developer MCP, and the Digitone II had none. Agents could reach the unit only through the host script.
  • What this changes:
    • scripts/digitone-device.ts runs the site's own link client over the computer's MIDI, through zoom-device.ts's RtMidi access. It joins SysEx that RtMidi hands over in pieces, and sends one upload frame at a time.
    • frontend-mcp.mjs gains five tools behind --digitone-midi. digitone_status and digitone_log are read-only. digitone_trial takes a runtime package by name from --digitone-packages; it and digitone_keep need --allow-device-writes and confirm: true. digitone_undo rolls the trial back.
    • While a trial is open the server sends a HELLO every three seconds, because the unit rolls a trial back after ten silent seconds. Closing the server rolls an open trial back.
    • As the MCP's limits ask, there is no raw memory, key or flashing tool. Whether a read-only screenshot may be added is asked on the board.
    • Docs: docs/FRONTEND_MCP.md#a-digitone-ii-over-midi, the goal row, and a changelog entry.
  • How I checked it:
    • scripts/digitone-device.test.mjs: 5 tests against fakeDigitone, which speaks link.c's ident, diag, mem and upload and splits each reply over two events as RtMidi does.
    • The tests cover status and log through the real UploadSession, a trial whose keepalive sends frames and stops after Keep, Undo, the refusal while playing, a port list without one Digitone II, the MCP's write gates (flag, confirm, plain package names), and the rollback on close.
    • tsc -b and eslint are clean.
    • npm run pr:ready fails locally only on the runtime loader test that fails on current main (stale Octatrack standalone recipes, finding on the board).

Tested on a unit: a Digitone II, OS 1.12, running #1842's loader base from RAM (main CRC 304cfcdc), on 20 November 2026.

  • Through the real MCP, read-only (createFrontendTools with --digitone-midi, no write flag): digitone_status read the link (armed, boot 1, 58,029 ticks) and the loader (phase normal, generation 30). digitone_log read the log: START only, six load records.
  • Through the same DigitoneUnit the write tools call, with real MIDI:
    • a trial of an 88-byte test package, held past the unit's ten seconds by the keepalive (still trial after 15 s);
    • Undo, back to the previous set;
    • a trial again, then Keep: one module live.
    • The test module was removed after.
  • The write tools themselves were not run with --allow-device-writes on the unit: the developer keeps that flag off.
    Edge cases
Case Why this change makes it a risk How run Result
A trial held past the unit's ten seconds the server, not the host script, must keep it open DigitoneUnit.trial on the unit, 15 s idle, then status pass: still in trial
Keep, then no more keepalive a settled trial must not keep sending frames test against fakeDigitone pass
The server closes with a trial open an unkept trial must roll back test against fakeDigitone pass; on the unit not run: the developer keeps the write flag off for the MCP
SysEx split over events RtMidi hands long SysEx over in pieces fakeDigitone splits every reply in two; the unit through real RtMidi pass
A trial while the unit plays the unit refuses, the tool must report it fakeDigitone playing pass (the unit's own refusal ran in #1842)
Write gates no write without the flag, confirm and a plain package name the MCP tests pass
Two Digitone II ports, or none the tool must not guess a unit a port list without one pass for none; two not run: one unit here
  • What the guides lacked or got wrong, and where I fixed it: docs/FRONTEND_MCP.md had no machine over MIDI beside the Zoom pedal. The new section says how a development base's trial stays open.

🤖 Generated with Claude Code

prodbysmolec and others added 5 commits November 20, 2026 11:02
…loadSession

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r stack's link.c

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Undo)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@repeat98

Copy link
Copy Markdown
Owner

I checked the MIDI reader with two requests pending on the same line. I delivered both replies, but the first read timed out and the second got the first reply. This can happen during a trial because the keepalive uses the upload queue while status and log reads call the same MIDI line outside it.

Please serialize complete request/reply exchanges on that line, including the keepalive, and cover a log or status read while a trial is open. There is a related cleanup case in finish(). If Keep or Undo loses its acknowledgement, the upload session becomes unusable while the keepalive continues. Stop that keepalive on an unconfirmed result and recover through a fresh status read so the unit can time out safely. Once #1844 is updated, please refresh this draft against it.

prodbysmolec and others added 5 commits November 22, 2026 19:19
…-mcp-tools

# Conflicts:
#	scripts/frontend-mcp.mjs
#	src/engine/elektron/dn2-link.test.ts
#	src/engine/elektron/dn2-link.ts
…ne; an unconfirmed Keep or Undo stops the keepalive

Status and log reads called the MIDI line outside the upload queue, so a reply could reach the wrong request during
a trial. Every complete exchange (upload frame, keepalive, ident, a whole log read) now takes a LineLock turn. If
Keep or Undo loses its acknowledgement, the session is dropped, the keepalive stops so the unit settles the trial
by itself, and a fresh read reports the loader's phase. The upload base is the one the unit names in HELLO (a
development build's layout digest, repeat98#1842); --digitone-base FILE refuses a unit on another build. Tests: a delayed
line never has two requests in flight during a trial with status and log reads; a cut-short accept stops the
keepalive; a base mismatch is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…file main lacks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Undo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@prodbysmolec

Copy link
Copy Markdown
Collaborator Author

Thanks, both fixed in 51b1d25 (and two small follow-ups):

  • One exchange at a time on the line. Every complete request and reply, meaning an upload frame (the session's or the keepalive's), ident or a whole log read, takes a turn on one LineLock. Status and log reads during a trial wait for the keepalive frame, and the other way round. Test: a fake unit whose replies arrive late, a trial with a 5 ms keepalive, then status() and log() together. Both answer correctly, at least four keepalive frames go out, and the fake never sees two requests in flight.
  • An unconfirmed Keep or Undo. If finish() loses the acknowledgement, the session is dropped, the keepalive stops so the unit's own timeout settles the trial, and a fresh status read (a new UploadSession on the same line) reports the loader's phase in the error. Test: the accept reply comes back cut short → keep() rejects, no further frames go out, and status() works again.
  • Base. Digitone II: the runtime loader in the development base, over the link #1842 makes HELLO name the development build (a layout digest from machine-base.py) instead of the fixed string, so the MCP no longer assumes UPLOAD_BASE. It binds the session to the base the unit names in HELLO, and --digitone-base FILE|HEX (the build's .identity) refuses a unit on another build. It works with both old and new dev bases.
  • Refreshed against main now that Digitone II: the site's upload transport over the link #1844 has merged (took main's exact-length upload response check). docs/FRONTEND_MCP.md no longer links LOADER.md, which only exists on the base drafts. pr:ready Ready.

@repeat98

Copy link
Copy Markdown
Owner

The original reply-order and unconfirmed-Keep tests pass. I found a timing case with a trial open and a slower MIDI line. With the existing 6,148-byte fake log and replies 220 ms apart, the log read held the line for every chunk. No keepalive reached the controller in the first ten seconds. Individual replies were all within their timeout, but the unit’s trial watchdog can expire during that read.

Could you serialize one request and reply at a time and let a due keepalive run between log chunks? A slow-log test should see a keepalive before the watchdog deadline while still observing at most one exchange in flight.

prodbysmolec and others added 2 commits November 25, 2026 11:29
…-mcp-tools

# Conflicts:
#	scripts/frontend-mcp.mjs
…ive goes between its chunks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@prodbysmolec

prodbysmolec commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Fixed in 286ee99 (after merging main). What changed: a log read now takes one turn on the line per request instead of one for the whole log. A due keepalive goes between its chunks, and there is still only one exchange in flight.

  • readLog(line, turn) in dn2-link.ts takes a turn function and runs diag and every mem chunk through it. DigitoneUnit.log() passes its LineLock, the same lock the keepalive and the upload frames take.
  • Slow-log test (digitone-device.test.mjs): your case scaled down ten times, with the 6,148-byte log (49 reads), replies 22 ms apart, a keepalive every 100 ms, and a 1,000 ms watchdog. The read takes over a second; the test checks there are at least five keepalives during it, no gap over 500 ms, and mostInFlight 1. With the old log() it fails: one keepalive in the whole read.
  • Merge conflict in frontend-mcp.mjs close(): I took main's version (idle timer, closeZoom()) and kept the Digitone undo.
  • pr:ready: Ready.

@repeat98

Copy link
Copy Markdown
Owner

Thanks, a turn per log request is what I asked for, and the slow-log test with mostInFlight 1 shows it.

Since then the Model:Cycles' tools have landed on main (#2126), and they change what this one should look like:

  1. Please merge main. Model:Cycles: developer MCP device tools for a Modwerk base #2126 conflicts here in scripts/frontend-mcp.mjs and docs/FRONTEND_MCP.md.
  2. The same tools, not new ones. The machine recipe asks for each machine's link behind the shared device tools (docs/MACHINE_RECIPE.md, "MCP device tools"), and the Model:Cycles now does exactly that: --elektron-midi with device_status, device_log, device_review, device_trial, device_keep and device_undo, packages from --elektron-images. Please put the Digitone II behind those instead of the digitone_* tools and --digitone-* flags: the same flags, a device_review step that returns the package's SHA-256 before device_trial, and device_load reporting unsupported. Keep what you built for the line (LineLock, a turn per request, the keepalive, the unconfirmed Keep and Undo), and the build check of --digitone-base can go into the review, against the base the unit names in HELLO.

On timing: this can go to main once the loader from #1842 is there through #1767, the way the Model:Cycles' tools followed its base.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants