Repository navigation
Feat(mcp): attachments, task edits, daily notes and note sections as tools - #35
Merged
Merged
Conversation
…tools An assistant could list a vault's attachments and do nothing else with them (#34). Eleven tools fill that gap and the three jobs it was next most often doing badly, taking zn mcp from 34 tools to 45. Attachments: read_asset, upload_asset, rename_asset, move_asset, duplicate_asset, delete_asset and restore_asset, with list_assets {deleted: true} in place of a separate listing tool. Each finds its file in the asset listing even at full access, so nothing but an attachment can be named, and none of them changes a loose CSV database or its schema file. upload_asset is bounded at 16 MiB before it decodes and never overwrites; read_asset at 5 MiB, and it answers with an image, text or an embedded file. A delete is the soft delete the app's Trash can undo. Purge and empty-deleted are left out on purpose: they cannot be undone and only free disk space, which the user can do in the app. Renames and moves keep links working. The local engine gains MoveAsset and DuplicateAsset, and asset_link_rename.go is znserver's rewrite, ported with a filter on which notes it touches. The old vault.RenameAsset stays as it was for zn tui, which rewrites through its open buffers. update_task changes a due date, priority, @waiting, state, status or text by id. It edits the single line the scan pointed at, because the line setters count with the editor's fence rule and ids come from the CLI's, which disagree on a four-space fence. No task-line logic changed. daily_note finds a note under the vault's own settings and changes nothing; if it is missing, it returns the arguments for create_note, so read-only clients can use it. note_sections and edit_section read and change the part of a note under one heading. Scope: every tool honors --allow-path, --deny-path, --read-only and --access. A hidden file answers exactly like a missing one, nothing is written through a symbolic link, upload_asset needs the assets folder shared, and a server, which rewrites links in every note itself, refuses a path-restricted rename or move as it does for rename_note. Allow and deny entries can now name an attachment or its folder: --deny-path assets/secret used to count as stale and share nothing, and --allow-path assets was reported as missing. The desktop's bundled server does not have these tools yet, so internal/mcp/testdata/mcp-scope.json is ahead of upstream and its checksum matches nothing in ZenNotes/zennotes. docs/shared-contracts.md says so, and that syncing from zennotes would overwrite it. The mirror is in progress. Tests: stdio_e2e_test.go drives the built binary with the SDK's client on a local vault and on a real znserver, for every new tool and a denied call under each scope, checking the files on disk. It runs with ZN_MCP_E2E=1, and the server half with ZENNOTES_SERVER_CONTRACT_BINARY. Removing each of ten scope and safety guards in turn fails a test.
…rking rename_asset and move_asset kept a link's style, so a plain [x](../assets/report.pdf) became [x](../assets/new report.pdf). The desktop's renderer only reads a destination with a space as a link inside angle brackets, so the link stopped working. A move can do this with no rename at all, because a taken name gets a number: photo 2.png. A Markdown destination with a space or a parenthesis now gets angle brackets, a bracket in the name is encoded so it cannot close them, and the next rename still finds the link. Wikilinks and percent-encoded links are as they were. This is the one place asset_link_rename.go goes beyond the copies it was ported from. znserver's and the desktop's still write the broken form, so on a server these links still break until they get the same fix. Tests: every shape in TestAssetRenameKeepsMarkdownLinksWorkingWithSpacedNames fails with the fix reverted where it adds brackets, and TestStdioASpacedNameKeepsPlainLinksWorking drives both tools over stdio.
…ntents read_asset and duplicate_asset hand over a file's bytes, or a readable copy of them. For a client limited by --allow-path or --deny-path on a server, they now refuse, as rename_asset and move_asset already do there. It can still list, upload, delete and restore. A local vault and a whole-vault client on a server are unchanged.
This was referenced Nov 4, 2026
Merged
adibhanna
added a commit
that referenced
this pull request
Nov 4, 2026
A second review of the text diagrams found more that was misread. A state's :::class became a label and could lose the edge, and a %% comment holding a semicolon drew false edges from its text, because comments were cut after the line was split into statements. `A --> C(f(x))` lost its closer without a note, since any leftover closer counted as a doubled shape's; closers are now only allowed when the shape opened doubled. IDs in any script now draw. The parser's IDs are ASCII, so others are renamed while it reads them, and this also covers IDs with dots. Entities like #amp; and #35; decode, an empty diagram says it has nothing to draw, and front matter with CRLF line ends is skipped. Two long inputs are now linear: a zen table row of many links, and picking mask runes for a label holding many private-use runes. A zen table also keeps a row with no outer pipes once its separator has been seen.
adibhanna
added a commit
that referenced
this pull request
Nov 5, 2026
c38bd53 hid every `#word;` from the statement split, and that also took a hex colour. `style A fill:#f9f; B-->C` then read as one statement and the block showed its source. A semicolon is now hidden only for a name that is an entity and that does not follow a colon, since `fill:#123;` could read as one. `A[d #35; e]` still draws.
adibhanna
added a commit
that referenced
this pull request
Nov 5, 2026
…and scoped tools leave databases whole (#49) Fixes for a 0.17.1 release. One commit per fix, each with a test. ## Reading view - `j`, `k`, Ctrl+D, Ctrl+U, PgDn, PgUp and the mouse wheel move the view on their first press. The highlighted row moves with the view, and on the first and last screens it moves alone, so every row can still take it for Enter and `x`. - Ctrl+F pages in `listNav`. Ctrl+B is also bound there, but by default it stays the sidebar toggle, because `chordKey` takes it first and the README documents it. It pages up only when `global.toggleSidebar` and `global.toggleConnections` are both rebound, since a terminal sends Ctrl+Shift+B as Ctrl+B. - With Vim off, or after leaving insert mode, keys in the reading view went to the hidden editor and letters were typed into the note. They now go to the view. - Switching to the reading view cancels an open command line, and `gd` follows the link on the highlighted row. ## Previews - A wide flowchart draws a row only when every edge joins neighbouring boxes. Otherwise it draws a column, with other edges listed under their source. - A table under a list item keeps its blank row, and an image in running text keeps its `⟦⟧` in the default style. - `zen` style: callout titles render as inline text, markers around code or links are dropped unless spacing makes them literal, `***` reads whole, a link label is inline text, and indented code is code unless it continues a paragraph, quote or list item. - Mermaid: an entity outside quotes such as `#35;` no longer splits its statement while a colour's `;` still does, paired inline tags such as `<b>x</b>` are dropped while `Vec<i>` stays, and a flowchart fits panes of 1 to 7 cells with its edge styles. ## Names on a terminal Status lines, the status bar, dialogs, menus, prompts, sidebar folder rows and `zn mcp` notices show a name's control codes as text. Pipes and files keep every byte. ## `zn mcp` - On a local vault, record pages in a `.base` folder are notes: in `list_notes`, `list_tasks`, tags and link rewrites. A deny entry on a page or database hides just that. An entry that names nothing still stops the client. `zn list` and `zn tui` are unchanged. - Under a path scope, a client can read and edit a record page but not rename, move, copy, archive, trash or delete it, and a `.base` folder is not a folder: it is not in `list_folders` and cannot be renamed or deleted as one. This holds on a local vault and through `zn mcp` on a server, and reaches a server's `/mcp` with its next pin. At full access nothing changes. - `rename_asset` and `upload_asset` refuse a name with spaces around it. - `spell` tries case and composition before folding accents, so an NFD path finds `Café` beside `Cafe`, for notes, the attachments folder and destinations. `internal/mcp/testdata/mcp-scope.json` is unchanged. ## Checked and left alone - `zn rename` leaves `[[inbox\C]]` and `[[inbox\C\|e]]`. With no slash and no `.md` they name a note with a backslash in its title, and resolve to nothing in the desktop and the server too. Pinned with a test. - `zn move` and `zn folder rename` leave `[[sub/D\|d]]`, the same as `[[sub/D]]`. Neither the desktop nor the server rewrites links on a move or a folder rename, so this is not an escaping bug. Rewriting them would be a change across all three. - `[[a\\|b]]` is not changed. `SplitWikilinkContent` matches `wikilinkAliasStart` in the desktop's shared code and `wikiAliasStart` in the server, and the three are kept in step. Note names cannot hold a backslash, so the link resolves to nothing either way. - `move_asset` back into an emptied subfolder works at full access since #48, pinned by `TestHTTPMCPFullAccessMovesBackIntoAnEmptiedSubfolder`. A scoped client on a server is refused the tool, as before. - `A--->>B` already shows its source with a note. Now pinned. - An embed in a zen table cell already shows whole. Now pinned. - `zn`'s own path errors were already clean. Now pinned. ## Follow-ups for other repos - The desktop's `spell` in `apps/desktop/src/mcp/scoped-backend.ts` needs the same passes: exact, lower-cased NFC, then folded, each counting one path once. - The desktop's bundled MCP server still skips record pages. ## Testing - `go vet ./...` and `go test ./...` pass. - `ZN_MCP_E2E=1` stdio tests pass. - The shared scope contract and the HTTP tests pass through `/mcp` with `ZenNotes/znserver` main at 09b46e1 built on this branch. On that server's v0.17.0 pin, `TestRecordPageStaysPutThroughHTTP` and `TestDatabaseIsNotAFolderThroughHTTP` fail, as expected, until it pins a tag with this change. The rest pass there. - The real `zn tui` was run in a private tmux server with isolated config and throwaway vaults. The reading view keys were compared with main, with Vim on and off, and main typed `jZ` into a note where this branch does not. Flowcharts, tables, placeholders, zen rendering, and panes of 5, 9 and 60 columns were checked on this branch. - Status lines were compared with main on a real terminal. - Windows skips the three tests that create a file name with a control character. - `zn mcp` was compared with main over stdio using the reproduction for record pages.
1 task
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.
For #34. An assistant could list a vault's attachments and do nothing else with them. This adds the asset tools the issue proposes, plus the four things an audit found assistants most often do badly today, taking
zn mcpfrom 34 tools to 45.This does not close #34 by itself, so the issue can get its own comment once this is merged.
New tools
read_assetupload_assetrename_asset,move_assetduplicate_assetdelete_asset,restore_assetupdate_task@waiting, state, status or text, by task iddaily_notecreate_notenote_sectionsedit_sectionlist_assets {deleted: true}lists what can be restored, in place of a separate tool. Tool definitions grow by about 6 KB at full access.Decisions to review
.zennotes/vault.jsonand notes answer "not found". Loose CSV databases can't be renamed, moved, duplicated or deleted through these tools.upload_assetonly writes toassets. A client limited to--allow-path Projectscan't upload.rename_noterule. On a local vault only visible notes are rewritten.read_assetandduplicate_assetrefuse there. A local vault and a whole-vault client on a server are unaffected.daily_noteis read-only. Creating goes throughcreate_noteand its scope rules, and read-only clients can still find a note. A path-restricted client gets no template, because a template isn't under any path a scope can name. The app's task rollover is left out.Behavior changes outside the new tools
--deny-path assets/secretused to count as stale and share nothing, and--allow-path assetswas reported undermissingAllow.MoveAsset,DuplicateAssetand the link rewrite are new.vault.RenameAssetis unchanged forzn tui.Known limits
internal/mcp/testdata/mcp-scope.jsonis therefore ahead of upstream, and its checksum matches nothing in ZenNotes/zennotes.docs/shared-contracts.mdsays so. Runningsync:contract-fixtures --tuibefore the mirror lands would overwrite it and fail these tests. The mirror is in progress in its own session.[x](../assets/new report.pdf), which stops being a link. znserver and the desktop'sasset-link-rename.tsneed the same fix.help.tsand the website docs still need matching changes.Synced copies
stripCodeContentlogic changed.update_taskcalls the existing setters on the one line the scan pointed at, because the setters and task ids count tasks differently around a four-space fence.internal/vault/asset_link_rename.gois a new copy of znserver's file, with a filter on which notes get rewritten.Testing
go test ./...passes, including the extended scope contract.internal/mcp/stdio_e2e_test.godrives the built binary over stdio with the SDK's client, on a local vault and on a real znserver 2.82.0, checking the files on disk. It covers every new tool, plus denied calls under--read-only,--access read,--access commentand allow and deny paths.ZN_MCP_E2E=1 ZENNOTES_SERVER_CONTRACT_BINARY=/path/to/zennotes-server go test ./internal/mcp -run TestStdioNot tested: real assistant clients such as Claude Code or Claude Desktop, including how they show images and PDFs, and Windows.