Repository navigation
Feat(mcp): the bundled server gets zn's attachment and work tools - #1051
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bundled MCP server gets the eleven tools
zn mcpgained 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, pluslist_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
edit_sectionandupdate_taskadd to agent edit review.list_assetsnow 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.Also in here
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.daily_noteanswerscannotCreatefor a folder the client cannot see, and a move has to be accepted where it lands.linksNotUpdatedlists 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_sectionand link rewrites write a note whole or not at all, throughwriteFileAtomic, moved tomain/atomic-write.tsfor this.append_to_note,prepend_to_note,insert_at_line,replace_in_noteandtoggle_taskstill 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@rendereralias for main, sodaily_noteandnote_sectionsshare app-core's vault layout, outline and template code.Fixture
packages/bridge-contract/fixtures/mcp-scope.jsontakes zn's file unchanged, from ZenNotes/tui#46 (sha25604a3229b...): the desktop's cases plus the new vault and cases, with the tool counts updated.sync:contract-fixtures -- --tuiagainst that branch reports a match. Those bytes reach zn'smainwhen that PR lands.Testing
Run against a real server 2.82.1 built from its tag, with
ZENNOTES_SERVER_CONTRACT_BINARYset. 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:verify-packaged-clipasses.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.scope-contract.test.tspasses on the shared fixture.--read-only,--access readand--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_notetakes no path, so under an allow path it gives no template and does not find a hidden note. 193 checks passed.windows-latestandwindows-11-armCI jobs run the suite, junction tests included.zn mcpfrom 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 andtoggle_taskmatch 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.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_assetembeds 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.link, and fields such asassetEmbedsandsiblingOrder.Unknown tool: xas a tool error, where Go's SDK uses a protocol error. Filesystem error text differs on an unscoped local vault.mainhas 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.update_taskandedit_section, and does not walk a linked attachment folder for a client with no path scope.Known limits
write_notenow 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.tsis the source to borrow from.