Skip to content

Feat(mcp): the bundled server gets zn's attachment and work tools - #1051

Merged
adibhanna merged 10 commits into
v2.83.0from
claude/mcp-tools-mirror-34
Nov 4, 2026
Merged

adibhanna merged 10 commits into
v2.83.0from
claude/mcp-tools-mirror-34

Conversation

@adibhanna

@adibhanna adibhanna commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

The bundled MCP server gets the eleven tools zn mcp gained in ZenNotes/tui#34, one for one: read_asset, upload_asset, rename_asset, move_asset, duplicate_asset, delete_asset, restore_asset, update_task, daily_note, note_sections, edit_section, plus list_assets {deleted: true}. That makes 45 tools at full access, 44 under a path scope, 18 with comment access and 15 read-only.

What changes for people

  • An assistant can read, add, rename, move, copy, delete and restore attachments, change a task's fields by id, find or start a daily note, and read or edit one section of a note. The Help cards list them, along with what edit_section and update_task add to agent edit review.
  • list_assets now lists every file that is not a note, as the server, the app's Assets view and zn do. Before, it listed the attachment folders only. A linked attachment folder is still walked for a client with no path scope.
  • Allow and deny entries can name attachments and their folders.
  • A client that sees part of a server's vault can list, upload, delete and restore attachments, and cannot rename, move, read or copy them.

Also in here

  • Stdio limit: the SDK's transport closed the session on any message over 10 MiB, so a legal upload of about 7.5 MiB killed the server. It is now 128 MiB, so an oversized file gets its refusal.
  • asset-link-rename.ts (shared): a Markdown link gaining a space or a parenthesis stays a link, in angle brackets. This also changes the app's own asset rename.
  • Under a path scope: a link rewrite writes the whole path, daily_note answers cannotCreate for a folder the client cannot see, and a move has to be accepted where it lands.
  • Files and notes under failure: asset writes on a vault take turns, and a rename no longer replaces what is there, so parallel moves and renames cannot lose a file. linksNotUpdated lists the notes a link rewrite could not read or write, or whose wikilinks cannot hold the new path, which may still use the old name. Link rewrites and note edits take turns per note, so neither overwrites the other. write_note, update_task, edit_section and link rewrites write a note whole or not at all, through writeFileAtomic, moved to main/atomic-write.ts for this. append_to_note, prepend_to_note, insert_at_line, replace_in_note and toggle_task still write in place, so a crash partway through one can truncate the note.
  • main/remote/connection.ts: sends bytes and forms, and trims server error text, on every route.
  • electron.vite.config.ts: a @renderer alias for main, so daily_note and note_sections share app-core's vault layout, outline and template code.

Fixture

packages/bridge-contract/fixtures/mcp-scope.json takes zn's file unchanged, from ZenNotes/tui#46 (sha256 04a3229b...): the desktop's cases plus the new vault and cases, with the tool counts updated. sync:contract-fixtures -- --tui against that branch reports a match. Those bytes reach zn's main when that PR lands.

Testing

Run against a real server 2.82.1 built from its tag, with ZENNOTES_SERVER_CONTRACT_BINARY set. The last commit (dbdb59b) ran the MCP and vault suites (608 passed, 11 skipped) and both typechecks. Commit 64f98e5 ran those plus the link-rewrite and help suites and the comparison with zn. The stdio proof and the full suites below are from earlier commits:

  • Both typechecks pass, and verify-packaged-cli passes.
  • Desktop suite: 1737 passed, 5 skipped (Windows-only, live service and performance tests). On the first commit, 7 of 9 repeat runs were clean with other work loading the machine: one failed a timing check in watcher.test.ts, which this PR does not touch, and one, at a load average of about 400, had 12 failures, the ones checked being 5-second timeouts. An earlier run had a single failure whose name was not captured.
  • shared-domain 2529 passed; app-core help and outline tests 31 passed.
  • scope-contract.test.ts passes on the shared fixture.
  • Over real stdio, against the built CLI, on a local vault and on the server: every new tool works. Under --read-only, --access read and --access comment, each writing tool is not offered. Under an allow path, a deny path and both together, each tool answers a hidden path as missing, with nothing changing on disk. daily_note takes no path, so under an allow path it gives no template and does not find a hidden note. 193 checks passed.
  • On Windows 11, over stdio on the built CLI: paths below a file, junctions, and parallel moves and renames (before these fixes 10 and 3 of 15 rounds lost a file; now none). The windows-latest and windows-11-arm CI jobs run the suite, junction tests included.
  • Compared with zn mcp from Fix(mcp): the new tools keep links, tasks and scopes straight tui#46 at 16929fa, same calls on identical vaults, local and server: the same tool counts per scope, the new tools and toggle_task match on description, schema and annotations, and disk differences only for a Windows note's line endings, which this PR keeps. Answers differ as listed below, plus the order of files with the same timestamp.
  • 13 changes that removed or weakened a scope guard, one at a time, each failed a test. Three survived at first and got tests. The tests for the later fixes were run against the earlier code and failed there, apart from those that guard behaviour which already held.

Not tested: real assistant clients rendering image or embedded content, and a full packaged app. Windows was exercised through CI and through the built CLI on a Windows 11 machine, not through the installed app.

Known differences from zn

  • upload_asset embeds PDF, audio and video (![[assets/a.pdf]]), as the app and the server do. zn's local vault uses a plain link, and is the one that should change.
  • On a server, results pass through the server's JSON, as every older tool does here: no link, and fields such as assetEmbeds and siblingOrder.
  • A tool a scope does not offer answers Unknown tool: x as a tool error, where Go's SDK uses a protocol error. Filesystem error text differs on an unscoped local vault.
  • zn's main has moved past the port on rewriting attachment links (a raw % in a name). That is not mirrored here, because the shared rewrite also serves the app.
  • zn turns a Windows note into LF on update_task and edit_section, and does not walk a linked attachment folder for a client with no path scope.

Known limits

  • A hung filesystem call holds that vault's asset turn, and so other asset writes.
  • A linked attachment folder that points out of the vault is listed for a client with no path scope, and the other tools refuse its files.
  • A crash can leave a scratch file or a partly written upload behind. Listings skip the scratch names, not a partial upload.
  • Note turns hold inside one MCP server. The app or a second server editing the same note can still overlap with it, and two hard links to one note take separate turns.
  • write_note now replaces the file, so a read-only folder refuses it where a plain write would not, and a hard link to the note stays on the old text. The app's own saves behave the same way.

Website docs need the new tools, limits and scope rules; the Help text in packages/app-core/src/lib/help.ts is the source to borrow from.

`zn mcp` gained eleven tools in ZenNotes/tui#34, and the bundled server now has
the same ones, with the same names, schemas, results and errors: read_asset,
upload_asset, rename_asset, move_asset, duplicate_asset, delete_asset,
restore_asset, update_task, daily_note, note_sections and edit_section.
`list_assets` takes `deleted: true`, and lists every file in the vault that is
not a note, as the server, the app's Assets view and zn do. It no longer walks
through a linked attachment folder.

Scopes hold for the new tools as for notes: a hidden file answers like a missing
one, and allow and deny entries can name attachments and their folders. A client
that sees part of a server's vault can list, upload, delete and restore
attachments, and cannot rename, move, read or copy them.

The shared fixture now holds zn's asset and work cases, so both repositories
carry the same bytes again and the sync leaves zn's copy alone.

Also here because the tools need it:
- The stdio transport closed the session on any message over 10 MiB, so a legal
  upload of about 7.5 MiB killed the server. The limit is now 128 MiB.
- A renamed attachment with a space or a parenthesis in a Markdown link stays a
  link, in angle brackets. This also changes the app's own rename.
- Server errors are trimmed, and the remote client can send bytes and forms.
…oves only into a folder its parent lists

Windows answers ENOENT for a path below a file, where POSIX says ENOTDIR, so
the link check read one as plain absence and two Windows builds failed. It now
sees the file for itself. A junction counts as a link, which the new tests hold
on every platform, since Windows makes one without any privilege.
…rite fails

Tool calls run at the same time, so two moves or renames onto one name could
each find it free and the second would replace the first, with both reporting
success. Asset writes on a vault now take turns, and a rename no longer replaces
what is there, which also holds against another program.

Also:
- rename_asset refuses a name that would break every link to the file, and names
  Windows keeps. upload_asset still cleans what it is given.
- A failed link rewrite is reported as `linksNotUpdated`, and a note is written
  whole or not at all. writeFileAtomic moves to main/atomic-write.ts for this.
- update_task finishing a recurring task writes its next occurrence, as
  toggle_task does, keeps a Windows note's line endings, and takes `expectedText`
  so a stale id cannot land on another task. A task note has one status, so
  state, status and waiting are refused together, and waiting is a status the
  parser reads. edit_section keeps a Windows note's line endings too.
- list_assets walks a linked attachment folder for a client with no path scope,
  as it did before and as the app does, and skips a folder it cannot read.
- A wikilink that names a note stays when a file of that name moves, in the app
  too. Moving a file to its own folder under another spelling does nothing.
- A database pair stays a pair when part of it is out of view, a deleted asset's
  record is read like a client's path, the trash stays refused through a link,
  and base64 padding takes linear time.
- Agent edits are recorded under the note's own spelling, and Help says what a
  numbered name can show.
…'s again

The shared fixture moves to zn's newest bytes. Under a path scope a link rewrite
writes the whole path, since whether a bare name stays unique depends on files
the client cannot see, and daily_note leaves out a folder the client cannot see.
A move also has to be accepted where it lands, numbered name included.

move_asset refuses a folder name ending in a dot or a space or holding a colon.
expectedText that no longer matches now fails with what the task reads, rather
than answering null. list_assets leaves out what a loose CSV keeps beside it. The
descriptions of the new tools and toggle_task, and the instructions, are zn's.
…stay honest

Parallel calls could still lose note edits: a link rewrite read a note, another
tool wrote it, and the rewrite put the old text back, both reporting success. They
now share one turn per note. The rewrite also runs after the vault's asset turn,
since it reads every note and held up other asset calls.

Also:
- A change of case that fails partway puts the file back under its old name.
- upload_asset checks the name it will really write, and move_asset refuses a
  target with whitespace around it, so each checks what it uses.
- write_note refuses a read-only note, as append_to_note does.
- A move writes a folder as its parent lists it, so a note reads like the listing.
- A wikilink with an anchor counts as naming its note.
- A deleted asset's record is checked by its real path under a scope.
- update_task keeps a Windows task note's line endings.
- linksNotUpdated names only notes that could not be written.
- rename_asset refuses more names that break links or that Windows keeps.
- A move across volumes keeps the modified time and leaves no partial copy.
- duplicate_asset undoes a copy that lands out of a scope's view.
- A failed close leaves no scratch file.
A note that cannot be read may still use the old name, and saying nothing about
it hides that. The list now means what it says in the tool descriptions: notes
that may still use the old name. A note a path scope hides is never named.
… folder name

The shared fixture moves to zn's newest bytes. Where a note's folder or path is
not shared, daily_note answers `cannotCreate` rather than offering a createWith
that would misfile the note.

A move's answers no longer depend on what is at a path the client may not see:
under a scope nothing is read from the disk until the path is visible, and the
trash answers like any other folder. The rule about names other systems read
differently applies only to folders that do not exist yet, so a real folder keeps
working. A link through a folder is refused for every client.

A Markdown link encodes `#` and `?` in a folder's name. A wikilink cannot hold
such a path, so it takes the bare name where that resolves, which it always does
under a scope, and otherwise stays as it was with the note in `linksNotUpdated`.
Under a scope a wikilink is read as naming visible notes only.

Also from zn: an upload cleans a device name rather than refusing it, a database's
backups are refused as names, a pair is matched however it is spelled, a restore
that lands out of view is undone, and a finished task note keeps its date.
They timed out at 5 s on windows-latest with no assertion failing. Ten rounds
still catch a lost edit, which the old code lost every round.
…rrival order

An attachment's link rewrite and a tool editing the same note could still lose
an edit while both reported success. The turn was keyed on the client's text, so
another case, Unicode form, ./ prefix or folder link gave two turns on one note.
It is now keyed on where the path really leads, folded. write_note could also be
overtaken by a later call, because it looked the note up before taking its turn;
the turn now comes first.

A move a path scope refuses no longer leaves an empty folder behind.
@adibhanna
adibhanna merged commit 283cb28 into v2.83.0 Nov 4, 2026
10 checks passed
@adibhanna
adibhanna deleted the claude/mcp-tools-mirror-34 branch November 4, 2026 23:20
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.

1 participant