Skip to content

Fix(mcp): the new tools keep links, tasks and scopes straight - #46

Merged
adibhanna merged 4 commits into
mainfrom
claude/mcp-tools-review-fixes
Nov 4, 2026
Merged

adibhanna merged 4 commits into
mainfrom
claude/mcp-tools-review-fixes

Conversation

@adibhanna

@adibhanna adibhanna commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

A review of the desktop's port of the new MCP tools found bugs that are in zn's too, and this also takes the later rounds of that review. This fixes them for zn 0.17.0. Please do not merge until Adib says so.

What changes

Writes take turns

  • Tool calls are served concurrently, and parallel writes could lose an edit or a link rewrite. A write now waits its turn, one turn per server rather than per note, because a rename rewrites any number of notes and on a server does so where zn cannot lock them. This holds within one zn mcp process.

Links

  • rename_asset refuses # ? | [ ] ^ % : * " < >, a backtick, control characters, a trailing dot and Windows device names, each of which stops links reaching the file or does not survive on every system. An upload cleans its name instead, as the app's import does.
  • rename_asset and move_asset return linksNotUpdated, the notes a rewrite could not read or write, or whose wikilinks cannot hold the new path. This was silent before. It applies to a local vault only, because a server rewrites links itself and does not report.
  • A Markdown link encodes # and ? in a folder's name. A wikilink cannot hold them, so it keeps a bare name where that resolves, and is reported where it does not.

Tasks

  • Finishing a task with @repeat: writes its next occurrence. zn had no recurrence code, so toggle_task ended the series as well. internal/vault/task_recurrence.go is a port of task-recurrence.ts and runs the same 23-case table.
  • update_task takes optional expectedText: when a different task is at that id, the call fails, says what the task now reads, and changes nothing. Nothing calls task ids stable any more.
  • update_task, toggle_task and frontmatter edits keep a Windows note's line endings, and edit_section keeps a note that is all CRLF that way. A note mixing endings comes out of edit_section and frontmatter edits with plain newlines, as on the desktop.
  • On a task note, waiting now sets status: waiting, which the parser reads. completedDate clears on leaving done, and state: done on a finished note keeps its date. Passing any two of state, status and waiting is refused.

Scopes

  • A path scope is judged before anything looks at the disk, and a move's final path is checked too.
  • daily_note answers cannotCreate in place of createWith when the note's folder is not shared.
  • The database check reads the whole listing, in any case.
  • A copy or a restored file that lands outside what the client sees is undone.
  • A deleted record is judged by its cleaned path.

Edges

  • A case-only rename no longer overwrites a file at a fixed temp name, and goes back to the old name if it fails.
  • A hard link, or a link at the destination, counts as taken.
  • A move to a file's own folder does nothing, an existing folder is written as its parent lists it, and a move through a folder link is refused.
  • A move across volumes copies, keeps the file's time and leaves nothing behind if it fails.
  • edit_section keeps a heading with only spaces apart from its text.
  • list_assets leaves out .csv.base.json and .csv.bak files, as the app does.

Behaviour to check

  • Task-line logic changed. vault.ToggleTask and Remote.ToggleTask now go through ToggleTaskRepeating, so zn task toggle changes too. ToggleTaskInBody keeps each line's ending, which also reaches zn tui.
  • Upload names. sanitizeFileName now drops trailing dots and spaces and prefixes a device name with _, which also reaches zn tui imports.
  • Fixture. internal/mcp/testdata/mcp-scope.json changes expectations and gains a vault and three cases. The desktop's copy has to take them byte for byte.

Not in this change

  • zn tui and the editor still end a recurring series.
  • toggle_task has no expectedText.
  • The desktop's port, help.ts and the website docs.
  • Walking a linked attachment folder for an unscoped client, which the desktop does. zn has never listed through a link.
  • The markdown and kind that upload_asset gives PDF, audio and video on a local vault, which are behind the desktop's.
  • Writes from a second zn mcp process or from the app are not covered by the write turn.
  • A note name of about 215 bytes or more cannot be written on a local vault, because its metadata file's name gets too long. Reading works. Not changed here.

Tests

Each fix has a test. The fixes were removed one at a time to check that its test fails.

ZN_MCP_E2E=1 ZENNOTES_SERVER_CONTRACT_BINARY=<server> go test ./... passes, with the server built from znserver a2532b8, including stdio tests through the built binary on a local vault and on the server. The vault, backend and mcp tests also pass on a Windows 11 VM.

Not tested: real assistant clients. Linux CI skips the tests that need a case-insensitive volume, so those ran on macOS and Windows.

A review of the desktop's port of these tools found bugs that are in zn's
too.

A rename could take a name that link syntax reads as something else, such as
b#c.png, and report success while every link to the file stopped resolving.
Those names are now refused. An upload still cleans its name, as the app's
import does. A note a rewrite could not change now comes back in
linksNotUpdated, where it used to be silent.

Finishing a recurring task ended the series, because zn had no recurrence at
all, though the desktop's task-recurrence.ts says zn mirrors it. This ports it
with the shared case table, and update_task, toggle_task and zn task toggle now
write the next occurrence. This changes task-line behaviour for those three.
ToggleTaskInBody itself is untouched, so zn tui and the editor still end a
series.

Task ids count position, so they move when the note above them changes.
Nothing should call them stable, and update_task takes expectedText to refuse
an id that now names another task. On a task note, waiting wrote a field the
parser ignores and a status change left completedDate behind. State, status and
waiting are one frontmatter field there, so asking for two is refused.

Under a path scope, a rewrite writes a link's full path, since whether a bare
name is still unique depends on files the client cannot see. move_asset checks
the final path, numbered name included, and not only the folder. daily_note no
longer names a hidden folder. The database check reads the whole listing, since
a scope can share a CSV and hide its schema file. The numbered name a write gets
beside a hidden file has no cheap complete fix, so the docs now say what it
reveals.

Smaller edges: a case-only rename no longer overwrites a file at a fixed temp
name, a hard link or a link at the destination counts as taken, moving a file to
its own folder under another spelling does nothing, a heading with only spaces
keeps its first line of text, and list_assets leaves out what the app hides.

The shared mcp-scope.json fixture changes two expectations, which the desktop's
copy has to take.
This brings the tools in step with the desktop's port of them.

A destination folder that exists now has to be a name its parent lists, as the
desktop requires, and a folder name that ends in a dot or a space or holds a
colon is refused, since it does not mean the same folder on every system. A new
test checks that a folder link, a junction on Windows, shows nothing and takes
no write.

A rename also refuses a colon or a trailing dot. A name that reads as a note
once a system drops the end of it counts as a note, and Windows' device names
are refused. Refusals and descriptions use the desktop's words, so the two
servers answer alike. expectedText now answers null like any id that no longer
matches, where it was an error.

update_task and edit_section said the rest of the note keeps its bytes, yet they
turned a CRLF note into LF. update_task now leaves every other line as it was and
edit_section keeps a note that is all CRLF that way. A note mixing endings still
comes out of edit_section with plain newlines, as on the desktop.

The read-only folder test is skipped on Windows, where such a folder does not
refuse a write. That was the Windows failure in CI.
The two ports each took the other's wording at the same moment, so they swapped
strings rather than meeting. The desktop now holds this branch's earlier text,
so this goes back to it: the rename_asset, move_asset, list_assets and update_task
descriptions, the task id lines in the instructions, and the task note refusal.

expectedText fails again rather than answering null. Saying what the task now
reads tells the assistant what happened, where null looks like a deleted task.
Tool calls are served concurrently, and parallel writes lost edits: a link rewrite
could put back a note's old text, and a server's read and write could interleave.
Writes now take turns, one turn per server rather than per note, since a rename
rewrites any number of notes and on a server does so where zn cannot lock them.

A path scope is now judged before anything looks at the disk, and a move's answers
stay the same whatever lies behind a folder the client may not use. daily_note
answers cannotCreate rather than offering to start a note it could only misfile.

Links hold up in a folder whose name has link syntax in it. A Markdown link encodes
it, and a wikilink keeps a bare name or is reported in linksNotUpdated. A bare link
under a scope no longer depends on hidden notes or files.

An upload now cleans a name that would not survive on every system, which reaches
zn tui's imports too, and a rename refuses it. A move keeps a real folder under any
name, writes it as its parent lists it, refuses a link in the path, and works across
volumes. A failed case-only rename goes back. toggle_task and frontmatter edits keep
a Windows note's line endings, and state done keeps a finished note's date. The
recurrence port reads Unicode spaces and far-off years as the original does.

The shared fixture gains a vault and three cases, and daily_note's expectation
changes, so the desktop's copy has to take the new bytes.
@adibhanna
adibhanna merged commit 4157c3c into main Nov 4, 2026
7 checks passed
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