Skip to content

Add Notes read filters, accounts, stats, attachments, and create - #384

Merged
mattt merged 8 commits into
mattt:mainfrom
oliverames:pr/notes
Nov 24, 2026
Merged

mattt merged 8 commits into
mattt:mainfrom
oliverames:pr/notes

Conversation

@oliverames

@oliverames oliverames commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This adds the read parity and create layers of what a Notes MCP needs. Notes is read-only in iMCP today: a client can fetch and read notes but cannot filter them by tag or checklist, or create one. sweetrb/apple-notes-mcp was the design reference for what to cover, and none of its code is used. It follows the order you suggested on #311: read parity, then create.

The private NotesShared tools and the edit, move, delete, export and attachment tools stay on my fork and are not part of this PR.

Every tool that changes something is gated by the Allow writes setting from #377 (writesEnabledByDefault is false for Notes). While it is off, those tools are not listed and a direct call is refused. Tools that only read are marked readOnlyHint: true.

What changed

  1. Read tools. notes_fetch gains tag, has, pinned, locked, word-count, created-date and includeRecentlyDeleted filters. Notes carry a url and tags. New: notes_accounts, notes_stats, notes_attachments. No new entitlements and no writes.
  2. Create. notes_create and notes_create_folder, through a fixed AppleScript that takes each value as a handler argument (an Apple event descriptor), never as script text. Adds com.apple.Notes to the Apple Events exception list in both entitlements files (the AUTOMATION_APPLE_EVENTS build setting already supplies the Apple Events entitlement) and updates the Apple Events usage string. Both tools return the scripting id as scriptIdentifier, and return identifier only when the new note or folder can be found in the database, so it works with the read tools. README documents what Notes drops when a note is written through scripting (link addresses, checklists, numbered lists).

Review fixes

  • The scan budget counts the notes the search examined (scannedNoteCount), not the notes it returned, and both limit and scanLimit on each request are capped by what is left of the budget, so a text query with a sparse filter can't scan past it.
  • Unreadable notes are reported once, whether or not they matched, so the warning is not dropped for a plain text search.
  • A tag filter on a database that can't supply tag records reports an error instead of returning no notes.
  • Tag filters read the same database tag records that keywords does, inside notes_fetch's snapshot, instead of tags parsed from the note text.
  • keywords is no longer overwritten by tags parsed from the note text.
  • The Markdown table converter does not pad a short row to the header's width.
  • TagTally and its test are gone, and notes_tags stays with Add Notes smart folders, tags and note links #351.
  • A Markdown link address with parentheses, such as a Wikipedia URL, keeps its full address.
  • Markdown brackets, parentheses and emphasis runs are matched in one pass over a line, and links and emphasis nest at most eight levels.
  • The README no longer says Notes can't be created, and says the 2,000-note budget applies to every notes_fetch call.

Testing

  • swift format lint --strict is clean on the changed files.
  • imcp-serverTests: 308 tests, 1 skipped (pre-existing), 0 failures. NotesTests and NotesWriteTests cover the filter, the tag records, the table converter, the scan budget with a sparse filter, unreadable notes, the cursor, and the create results. The search loop now runs over a small protocol so these run without a real Notes database.

Not verified

  • The create scripts have been checked by hand, not against a real Notes app on this exact branch.
  • Finding a created note or folder in the database: the matching is unit-tested, but whether the database catches up within the one-second retry hasn't been checked against a real Notes app. When it doesn't, identifier is left out.
  • notes://showNote?identifier= has not been confirmed to open the right note.

@mattt

mattt commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Following up from #364, for 4668fb0 and a148b35: please bound the scan for the pinned, locked, and creation date filters, drop the com.apple.security.automation.apple-events key (the AUTOMATION_APPLE_EVENTS build setting already supplies it), remove format: html, and leave notes_tags to #351, which reads the tag records directly.

@oliverames oliverames changed the title Add Notes read filters, create, edit, export and private NotesShared tools Add Notes read filters, accounts, stats, attachments, and create Nov 20, 2026
@oliverames

oliverames commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@mattt Rebased onto the updated #377, kept only the read filters and create commits (keeping edit and NotesShared on my fork), and made all four fixes: bounded metadata scans for pinned, locked, and creation dates at 2,000 notes, dropped com.apple.security.automation.apple-events from both entitlements files, removed format: html, and removed notes_tags to leave that to #351. Ready for another look.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 20, 2026
@mattt

mattt commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks, @oliverames. All four changes are in. A few things left before I merge:

  • The scan limit counts the notes that a search returns, not the notes it examined, so a text query with few matches can go well past 2,000. Could you count scannedNoteCount, and cap limit and scanLimit by what's left of each budget?
  • unreadableNoteIDs are only kept when they're also among the matches, so the warning about notes that couldn't be searched gets dropped, even for a plain text search.
  • The Markdown table converter pads every row to the header's width. A wide header with many short rows could produce a lot of cells, so please skip the padding or cap the total.
  • TagTally and its test are left over from notes_tags.

This also needs a rebase onto main now that #351 is merged. The new filters should go inside the snapshot code there, and tag filters should use the same tag records that keywords does.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 20, 2026
Mattt's pre-merge findings on mattt#384:

- The scan budget counts the notes the search examined
  (scannedNoteCount), not the notes it returned, and the page request is
  capped by what is left of the budget, so a text query with few matches
  cannot scan far past it.
- Unreadable notes are reported whether or not they matched, so the
  warning is not dropped for a plain text search.
- Tag filters read the same database tag records that keywords does, and
  keywords is no longer overwritten by tags parsed from the note text.
- The Markdown table converter does not pad a short row to the header's
  width.
- TagTally and its test are gone; notes_tags uses the database records.

The filters now run inside notes_fetch's snapshot, alongside the search,
instead of in a second pass over the results.
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 20, 2026
@oliverames

oliverames commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @mattt. I rebased onto main and fixed all four.

The scan budget counts scannedNoteCount, the notes the search actually examined, and the page request is capped by what's left of the budget, so a text query with few matches can't scan far past it. Unreadable notes are kept whether or not they matched, so the warning survives a plain text search. Tag filters read the same database tag records that keywords uses, inside notes_fetch's snapshot, and keywords doesn't get overwritten by tags parsed out of the note text anymore. The Markdown table converter doesn't pad a short row to the header's width, and TagTally and its test are gone since notes_tags reads the database records.

The PR is read filters plus create only; the private NotesShared and edit tools stay on my fork.

imcp-serverTests is at 251 tests with 1 skipped and no failures, and format is clean.

@oliverames

oliverames commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@mattt The macOS 26 job is failing on the stale Helper module cache described in #393, which is the runner image moving to Xcode 26.0.1. The macOS 27 job passes, and #393's macOS 26 job is green. Once #393 lands I'll rebase onto main and this job should go green.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 20, 2026
The fork's integration build still had the pre-review code for the
Reminders, Notes and AppleScript helper work. Bring in the same fixes
Mattt is reviewing upstream:

- Reminders: clamp stored relative alarms instead of trapping; carry the
  reminder's calendar and time zone on all-day and timed dues and keep
  seconds; read views in the stored time zone; include the house number
  in the street match and reject a bare locality; gate complete by
  reminders_update and rename by reminders_lists_rename; report an
  uncertain result when a complete's readback finds no reminder; accept
  completion_date on update; use the database tag records for notes_tags.
- Notes: count scannedNoteCount against the scan budget and cap the page
  request by what is left; keep unreadableNoteIDs whether or not they
  matched; read tag filters from the database tag records; stop
  overwriting keywords from note text; don't pad short table rows; drop
  TagTally.
- AppleScript: make beforeSending @sendable, drop nonisolated(unsafe),
  and check cancellation after the hook returns.

781 tests, 0 failures; format clean; the app builds.
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 20, 2026
@oliverames

Copy link
Copy Markdown
Contributor Author

@mattt I went back over this and found that two of the fixes from my last round were only partly done, plus one real bug in create.

The scan budget capped limit but not scanLimit, and TopoText examines up to scanLimit candidates on a text query no matter what limit is, so a sparse filter could still scan well past the 2,000-note budget. Both are capped by what's left of the budget now. Unreadable notes could also be listed twice. The search loop runs over a small protocol now, so there are tests for the budget, the unreadable notes and the cursor without a real Notes database.

notes_create was returning the AppleScript x-coredata id as identifier, which none of the read tools accept. It comes back as scriptIdentifier now, and identifier is only included when the new note or folder turns up in the database, so a client can pass it straight to notes_read.

I fixed a few smaller things too. A tag filter on a database that can't supply tag records now reports an error instead of returning nothing, link addresses with parentheses keep their full URL, and I took out a README sentence that still said notes can't be created. The description was out of date on the entitlements too, and it's fixed. imcp-serverTests is at 258 with 1 skipped and no failures.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 21, 2026
Mattt's pre-merge findings on mattt#384:

- The scan budget counts the notes the search examined
  (scannedNoteCount), not the notes it returned, and the page request is
  capped by what is left of the budget, so a text query with few matches
  cannot scan far past it.
- Unreadable notes are reported whether or not they matched, so the
  warning is not dropped for a plain text search.
- Tag filters read the same database tag records that keywords does, and
  keywords is no longer overwritten by tags parsed from the note text.
- The Markdown table converter does not pad a short row to the header's
  width.
- TagTally and its test are gone; notes_tags uses the database records.

The filters now run inside notes_fetch's snapshot, alongside the search,
instead of in a second pass over the results.
@mattt

mattt commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks, @oliverames. The search limits, the warnings, the table expansion, and the merge with the Notes code on main all look good. Two things before I merge:

One smaller thing: the test for the incomplete-search warning passes without the fix, because its fake returns the unreadable note as a match.

@oliverames

oliverames commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@mattt I fixed the link recursion and the warning test in 30ee512.

inline now takes a depth, and past eight levels of links or emphasis the rest is escaped text. A line also stops looking for links once a scan finds no ] after it. There's a test for each: 40,000 nested links convert without crashing, and a line of 100,000 [ converts well inside a two-second bound. With the fix reverted, the first crashes the test runner and the second took 257 seconds.

You were right about the fake. It now returns an unreadable note only when its number matches, the way a real text query can't match a note it can't read. The warning test has one unreadable note that matches and one that doesn't, and it fails without the fix.

The rebase waits on #390, as you suggested. Its CI is green now that #393 is in.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 21, 2026
@mattt

mattt commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks, @oliverames. The depth limit, the scan stop, and the warning test all look good. Two things left before I merge:

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 23, 2026
Mattt's pre-merge findings on mattt#384:

- The scan budget counts the notes the search examined
  (scannedNoteCount), not the notes it returned, and the page request is
  capped by what is left of the budget, so a text query with few matches
  cannot scan far past it.
- Unreadable notes are reported whether or not they matched, so the
  warning is not dropped for a plain text search.
- Tag filters read the same database tag records that keywords does, and
  keywords is no longer overwritten by tags parsed from the note text.
- The Markdown table converter does not pad a short row to the header's
  width.
- TagTally and its test are gone; notes_tags uses the database records.

The filters now run inside notes_fetch's snapshot, alongside the search,
instead of in a second pass over the results.
@oliverames

Copy link
Copy Markdown
Contributor Author

@mattt Both are done, and the branch is rebased on main.

Foundation+Extensions.swift is main's version now, with no changes from this branch.

For the scan, a606d91 matches brackets and parentheses in one pass over the line, so a [ or an address looks up where it closes and nothing is scanned again. Emphasis had the same problem with a line like ***a ***a, so those runs are matched in that pass too. testDelimitersThatNeverMakeALinkAreMatchedOnce covers [ with the same number of ], repeated [a](, and repeated ***a, each at 50,000.

I also ran the old and new converters against each other on 600,000 random lines, and the output was the same on all of them. imcp-serverTests is at 308 with 1 skipped and no failures.

The branch still includes the three commits from #377.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 23, 2026
@mattt

mattt commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks, @oliverames! The one-pass matching looks great, and nothing else needs to change. I merged #377 first, so this branch now conflicts with main in iMCP.xcodeproj/project.pbxproj. Could you rebase on main once more and drop the #377 commits, since they're in main now? I'll merge as soon as CI passes.

Oliver Ames added 8 commits November 24, 2026 09:48
Mattt's pre-merge findings on mattt#384:

- The scan budget counts the notes the search examined
  (scannedNoteCount), not the notes it returned, and the page request is
  capped by what is left of the budget, so a text query with few matches
  cannot scan far past it.
- Unreadable notes are reported whether or not they matched, so the
  warning is not dropped for a plain text search.
- Tag filters read the same database tag records that keywords does, and
  keywords is no longer overwritten by tags parsed from the note text.
- The Markdown table converter does not pad a short row to the header's
  width.
- TagTally and its test are gone; notes_tags uses the database records.

The filters now run inside notes_fetch's snapshot, alongside the search,
instead of in a second pass over the results.
…ated ids, balance link parens

- notes_fetch search is now searchNotes over a NoteSearchSource, so tests drive it; each request's scanLimit is capped by the remaining scan budget
- unreadable note IDs are reported once; a tag filter throws when tag records can't be read
- notes_create and notes_create_folder return the scripting id as scriptIdentifier and the database id as identifier only when one note or folder matches
- Markdown link targets keep balanced parentheses
- README: drop the stale create and smart folder sentence; the 2,000-note budget covers every notes_fetch scan
…et, test unreadable notes that don't match
@oliverames

Copy link
Copy Markdown
Contributor Author

@mattt Rebased on main with the #377 commits dropped, so it's just the eight Notes commits now. The files are identical to a606d91.

oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 24, 2026
@mattt
mattt merged commit 8967760 into mattt:main Nov 24, 2026
2 checks passed
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 25, 2026
The fork already carries this work. Conflicts keep the fork's exact id lookup
(NotesIDMapper) over upstream's title matching, so the tree does not change.
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 25, 2026
@oliverames
oliverames deleted the pr/notes branch November 25, 2026 15:12
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.

2 participants