Skip to content

Feat(mcp): attachments, task edits, daily notes and note sections as tools - #35

Merged
adibhanna merged 3 commits into
mainfrom
claude/mcp-asset-tools-34-d9c88e
Nov 4, 2026
Merged

adibhanna merged 3 commits into
mainfrom
claude/mcp-asset-tools-34-d9c88e

Conversation

@adibhanna

@adibhanna adibhanna commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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 mcp from 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

Tool Access What it does
read_asset read Returns an image, text or an embedded file, up to 5 MiB
upload_asset write Adds a file from base64, up to 16 MiB, never overwriting; returns the embed to paste into a note
rename_asset, move_asset write Also update the notes that link to the file
duplicate_asset write Copies a file next to itself
delete_asset, restore_asset write Soft delete with an undo token
update_task write Changes due date, priority, @waiting, state, status or text, by task id
daily_note read Finds the note under the vault's own settings and changes nothing; if it's missing, returns the arguments for create_note
note_sections read Lists a note's headings, or reads the part under one
edit_section write Appends to, prepends to or replaces the part under one heading

list_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

  • Purge and empty-deleted are not exposed. They can't be undone and only free disk space, which the user can do from the app's Trash.
  • Only attachments can be named, even at full access. Every asset tool finds its file in the asset listing, so .zennotes/vault.json and notes answer "not found". Loose CSV databases can't be renamed, moved, duplicated or deleted through these tools.
  • upload_asset only writes to assets. A client limited to --allow-path Projects can't upload.
  • Scoped renames and moves on a server are refused. The server rewrites links in every note, including hidden ones, so this follows the existing rename_note rule. On a local vault only visible notes are rewritten.
  • Scoped reads and copies on a server are refused. A client limited by paths on a server can list, upload, delete and restore attachments, but read_asset and duplicate_asset refuse there. A local vault and a whole-vault client on a server are unaffected.
  • daily_note is read-only. Creating goes through create_note and 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

  • Allow and deny entries can name attachments. --deny-path assets/secret used to count as stale and share nothing, and --allow-path assets was reported under missingAllow.
  • New local engine code. MoveAsset, DuplicateAsset and the link rewrite are new. vault.RenameAsset is unchanged for zn tui.

Known limits

  • Large files. Base64 goes through the tool call, so a model writing it out itself only manages small files. There's deliberately no source-path argument, because it would let an MCP-only assistant copy any file on the machine into the vault. An opt-in flag could add this later.
  • The desktop's server doesn't have these tools yet. internal/mcp/testdata/mcp-scope.json is therefore ahead of upstream, and its checksum matches nothing in ZenNotes/zennotes. docs/shared-contracts.md says so. Running sync:contract-fixtures --tui before the mirror lands would overwrite it and fail these tests. The mirror is in progress in its own session.
  • Spaced names on a server. On a local vault, a rename or move that gives a file a space or a parenthesis now puts a plain Markdown link in angle brackets, so it stays a link. A server rewrites links itself and still writes [x](../assets/new report.pdf), which stops being a link. znserver and the desktop's asset-link-rename.ts need the same fix.
  • In-app and website docs. help.ts and the website docs still need matching changes.

Synced copies

  • No task-line or stripCodeContent logic changed. update_task calls 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.go is 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.go drives 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 comment and allow and deny paths.
  • An upload of exactly 16 MiB passes, and one byte over is refused.
  • Removing each of ten scope and safety guards in turn fails a test.
ZN_MCP_E2E=1 ZENNOTES_SERVER_CONTRACT_BINARY=/path/to/zennotes-server go test ./internal/mcp -run TestStdio

Not tested: real assistant clients such as Claude Code or Claude Desktop, including how they show images and PDFs, and Windows.

…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.
@adibhanna
adibhanna merged commit 06ca624 into main Nov 4, 2026
4 of 5 checks passed
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.
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.

zn mcp: expose asset operations (upload/rename/move/delete) as tools — the server API already implements them

1 participant