standardnotes-mcp 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -3,6 +3,8 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
3
3
  import { z } from "zod";
4
4
  import { logger } from "./security/logger.js";
5
5
  import { isToolError } from "./security/errors.js";
6
+ import { makeDeleteGuard } from "./confirmDelete.js";
7
+ import { compactResult, installSlimToolList } from "./slimTools.js";
6
8
  import { loadConfig } from "./config.js";
7
9
  import { VERSION } from "./version.js";
8
10
  import { createClientFromSession } from "./sn/client.js";
@@ -10,7 +12,7 @@ import { degradedFeatures } from "./sn/entitlement.js";
10
12
  import { appendInput, createInput, createManyInput, deleteInput, deleteManyInput, frontmatterInput, getInput, listInput, registerNoteHandlers, replaceInInput, searchInput, statsInput, updateInput, updateManyInput, } from "./tools/notes.js";
11
13
  import { registerTagHandlers, syncInput, tagsAttachInput, tagsCreateInput, tagsDeleteInput, tagsDetachInput, tagsGetInput, tagsListInput, tagsUpdateInput, } from "./tools/tags.js";
12
14
  import { notesQueryInput, registerSmartViewHandlers, smartviewsListInput, smartviewsNotesInput, } from "./tools/smartviews.js";
13
- import { dailyAppendInput, dailyListInput, periodicAppendInput, periodicListInput, registerDailyHandlers, } from "./tools/daily.js";
15
+ import { periodicAppendInput, periodicListInput, registerDailyHandlers, } from "./tools/daily.js";
14
16
  import { registerTaskHandlers, tasksInput, taskToggleInput, } from "./tools/tasks.js";
15
17
  import { exportInput, registerExportHandlers } from "./tools/export.js";
16
18
  import { historyInput, registerHistoryHandlers, revisionGetInput, revisionRestoreInput, } from "./tools/history.js";
@@ -35,27 +37,34 @@ export async function startServer() {
35
37
  // wins; otherwise fall back to the name the client reports at initialize.
36
38
  // Read lazily — the handshake name only exists after connect.
37
39
  clientName: () => config.clientName ?? server.server.getClientVersion()?.name ?? null,
40
+ newNoteEditor: config.newNoteEditor,
38
41
  });
39
42
  const scoped = config.scope.readTags !== null || config.scope.denyTags.length > 0;
40
43
  const plan = client.entitlement().plan;
41
44
  const instructions = [
42
45
  "Standard Notes MCP: end-to-end encrypted vault. All content is decrypted locally; the server only ever sees ciphertext.",
43
- "Prefer notes_search to find notes before reading or editing; prefer notes_append / notes_replace_in over notes_update for targeted edits.",
46
+ "How to work: (1) find the note with notes_search (or notes_list for a tag) to get its uuid; (2) read it with notes_get (format=outline first for long notes); (3) edit with notes_append to add text or notes_replace_in to change text, and use notes_update only to replace the whole note. Tools take uuids, not titles: get tag uuids from tags_list. Deletes go to trash unless the user explicitly asks for permanent deletion.",
47
+ "Note flags (trashed, archived, pinned, locked, protected) appear in results only when true.",
44
48
  config.readOnly
45
49
  ? "READ-ONLY mode is active: write tools are not available."
46
50
  : null,
47
51
  scoped
48
52
  ? "A tag-based read scope is active: notes and tags outside the scope are hidden and appear as not found."
49
53
  : null,
50
- config.deleteElicitation
51
- ? "Deletions require user confirmation via elicitation."
52
- : null,
54
+ config.deleteConfirm === "off"
55
+ ? null
56
+ : config.deleteConfirm === "prompt"
57
+ ? "Deleting or trashing a note asks the user in the app's confirmation prompt; if the app can't show one, deletes are refused with reason confirmation_unavailable."
58
+ : "Deleting or trashing a note needs the user's OK. If a delete returns confirmationRequired, nothing was deleted: ask the user the question it gives, and only if they clearly say yes, repeat the call with its confirmToken. Never pass a confirmToken the user hasn't agreed to.",
59
+ // Surface scope entries that match no tag (issue #18): otherwise a
60
+ // misspelled SN_READ_TAGS silently leaves the AI looking at nothing.
61
+ ...(client.scopeReport()?.warnings ?? []).map((w) => `Scope configuration problem: ${w} Tell the user if they ask why notes are missing.`),
53
62
  config.governance
54
63
  ? 'Frontmatter AI governance is enforced: notes with "ai: read-only" cannot be modified, "ai: no-access" notes are hidden entirely, and per-client keys like "ai-claude: no-access" apply to matching clients only.'
55
64
  : null,
56
65
  plan === "paid"
57
66
  ? null
58
- : "This account is on the free Standard Notes plan (or its plan could not be confirmed). Paid Standard Notes features are not created on its behalf: new notes are plain text, folders stay top-level, and [[wikilinks]] stand in for native note links. A tool refusing with reason paid_feature means exactly that; tell the user it is a paid Standard Notes feature and offer the suggested alternative.",
67
+ : "This account is on the free Standard Notes plan (or its plan couldn't be confirmed), and the tools adapt: new notes are plain text, tags stay top-level, and links are [[wikilinks]] in the text. These are normal; don't suggest upgrading or bring up paid plans unless the user asks. If a tool refuses with reason paid_feature, use the alternative it gives.",
59
68
  ]
60
69
  .filter((s) => s !== null)
61
70
  .join(" ");
@@ -63,44 +72,20 @@ export async function startServer() {
63
72
  name: "StandardNotes-MCP",
64
73
  version: VERSION,
65
74
  }, { instructions });
66
- const confirmDelete = config.deleteElicitation
67
- ? async (note) => {
68
- try {
69
- const res = await server.server.elicitInput({
70
- message: `Delete note "${note.title}" (${note.uuid})? Trash is recoverable; permanent delete is not.`,
71
- requestedSchema: { type: "object", properties: {} },
72
- });
73
- return res.action === "accept";
74
- }
75
- catch {
76
- // Client without elicitation support: fall back to immediate
77
- // delete (documented behavior).
78
- return true;
79
- }
80
- }
81
- : undefined;
82
- const confirmBatchDelete = config.deleteElicitation
83
- ? async (count, permanent) => {
84
- try {
85
- const res = await server.server.elicitInput({
86
- message: `Delete ${count} note(s)${permanent ? " PERMANENTLY (irreversible)" : " (to trash)"}?`,
87
- requestedSchema: { type: "object", properties: {} },
88
- });
89
- return res.action === "accept";
90
- }
91
- catch {
92
- return true;
93
- }
94
- }
95
- : undefined;
96
- const h = registerNoteHandlers(client, { confirmDelete, confirmBatchDelete });
75
+ // Every delete and trash asks the user first unless SN_DELETE_CONFIRM=off;
76
+ // see makeDeleteGuard.
77
+ const guardDelete = config.deleteConfirm === "off" ? undefined : makeDeleteGuard(server.server, config.deleteConfirm);
78
+ const h = registerNoteHandlers(client, { guardDelete });
97
79
  const t = registerTagHandlers(client);
98
80
  const sv = registerSmartViewHandlers(client);
99
81
  const d = registerDailyHandlers(client, config.periodicTag);
100
82
  const tk = registerTaskHandlers(client);
101
83
  const hist = registerHistoryHandlers(client);
102
84
  const lk = registerLinkHandlers(client);
103
- const tpl = registerTemplateHandlers(client, config.templatesTag);
85
+ const tpl = registerTemplateHandlers(client, {
86
+ templatesTag: config.templatesTag,
87
+ shared: config.sharedTemplates,
88
+ });
104
89
  // In read-only mode, write tools are not registered at all — they don't
105
90
  // appear in tools/list, so the agent never tries them.
106
91
  const WRITE_TOOLS = new Set([
@@ -113,7 +98,6 @@ export async function startServer() {
113
98
  "notes_delete",
114
99
  "notes_delete_many",
115
100
  "notes_frontmatter",
116
- "daily_append",
117
101
  "periodic_append",
118
102
  "notes_task_toggle",
119
103
  "notes_revision_restore",
@@ -134,7 +118,7 @@ export async function startServer() {
134
118
  try {
135
119
  const result = await fn(args);
136
120
  return {
137
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
121
+ content: [{ type: "text", text: compactResult(result) }],
138
122
  };
139
123
  }
140
124
  catch (err) {
@@ -150,7 +134,7 @@ export async function startServer() {
150
134
  reason: err.reason,
151
135
  message: err.message,
152
136
  recoveryHint: err.recoveryHint,
153
- }, null, 2),
137
+ }),
154
138
  },
155
139
  ],
156
140
  };
@@ -158,43 +142,41 @@ export async function startServer() {
158
142
  throw err;
159
143
  }
160
144
  };
161
- registerTool("notes_list", "Use this when the user asks what's in their notes, wants to browse a folder, or you need note uuids. Returns uuid/title/updatedAt/preview, most recently updated first. `tag` (UUID or title, e.g. \"work\") filters by folder; add includeDescendants=true to include child folders (SN sidebar behavior). Do NOT use to find notes by content — use notes_search.", listInput.shape, wrap(h.notes_list));
162
- registerTool("notes_stats", "Use this for \"how many notes do I have\", vault size, note-type breakdown, or sync-health questions (cache age, decrypt failures). Read-only.", statsInput.shape, wrap(h.notes_stats));
163
- registerTool("notes_search", "Use this whenever the user wants to FIND notes by content or keywords (\"find my notes about X\"). mode=text (default): every space-separated word must match title or body, small typos and similar titles are tolerated (fuzzy=false for exact words), best matches first (sort=updated for newest first); hits marked fuzzy matched only approximately; mode=regex: a single pattern, e.g. \"\\\\d{3}-\\\\d{4}\". Filters: tag, noteType, updatedAfter/updatedBefore (\"YYYY-MM-DD\" is interpreted in the user's timezone), includeTrashed. Returns snippet windows around each match, totalCount, and nextCursor — pass nextCursor back as `cursor` to page. Do NOT use to browse a folder — use notes_list with `tag`.", searchInput.shape, wrap(h.notes_search));
164
- registerTool("notes_get", "Use this when the user wants to READ a specific note. Find the uuid first with notes_search or notes_list. format=content (default): uuid/title/text/noteType. format=full: adds tags, timestamps, flags. format=outline: heading map without the body — use before section edits on long notes. format=section: one heading's body (requires `section`, e.g. \"Projects::Alpha\").", getInput.shape, wrap(h.notes_get));
165
- registerTool("notes_create", "Use this to create ONE new note (\"make a note about X\"). `title` and `text` required; `noteType` defaults to markdown on paid Standard Notes plans and plain-text on free ones (free accounts: other editor types are saved as plain text, super is refused); `tags` takes tag UUIDs from tags_list. Do NOT use for bulk import — use notes_create_many.", createInput.shape, wrap(h.notes_create));
166
- registerTool("notes_create_many", "Use this to create several notes in a single sync push (bulk import, up to 50). Same fields as notes_create per entry. Returns created uuid+title pairs.", createManyInput.shape, wrap(h.notes_create_many));
167
- registerTool("notes_update", "Use this to replace a note's whole body, rename it (`title`), change its type, replace its tag set (`tags`), archive/pin it, or restore it from trash (`trashed: false`). For small targeted edits — adding a line, fixing one string — do NOT resend the whole body; use notes_append or notes_replace_in instead. For the same change across many notes, use notes_update_many.", updateInput.shape, wrap(h.notes_update));
168
- registerTool("notes_update_many", "Use this to apply patches to up to 50 notes in one sync push (\"archive all of these\", \"tag these 20 notes as done\"). Each entry is a notes_update-style patch with a uuid. Per-note failures are reported without aborting the rest.", updateManyInput.shape, wrap(h.notes_update_many));
169
- registerTool("notes_delete_many", "Use this when the user asks to delete/trash several notes at once. Default moves to trash; permanent=true purges irreversibly — only when explicitly requested. Per-note failures reported without aborting the rest.", deleteManyInput.shape, wrap(h.notes_delete_many));
170
- registerTool("notes_append", "Use this whenever the user wants to ADD text to an existing note (\"add X to my log\", \"append this to the meeting notes\") without rewriting it. Optional `section` targets a markdown heading (\"Log\" or \"Parent::Child\"): position=append (default) lands at the end of the section, position=prepend right under the heading. Without `section`, inserts at the end/start of the note. Plain-text/markdown notes only.", appendInput.shape, wrap(h.notes_append));
171
- registerTool("notes_replace_in", "Use this to CHANGE or FIX existing text inside one note (\"fix the typo\", \"rename X to Y everywhere in that note\"). Literal match by default; useRegex=true for patterns; per-rule caseSensitive/replaceAll. Rules run in order and each reports its replacement count. Plain-text/markdown notes only. Do NOT use to add new content — use notes_append.", replaceInInput.shape, wrap(h.notes_replace_in));
172
- registerTool("notes_delete", "Use this when the user asks to delete or trash a note. Default moves to trash (recoverable via notes_update trashed=false). permanent=true purges irreversibly — only when the user explicitly asks for permanent deletion. Do NOT use to remove a note from a folder — use tags_detach.", deleteInput.shape, wrap(h.notes_delete));
173
- registerTool("tags_list", "Use this to see the folder/tag structure (\"what folders do I have\") or to find a tag's uuid. Returns uuid/title/noteCount/parentUuid for every tag.", tagsListInput.shape, wrap(t.tags_list));
174
- registerTool("tags_get", "Use this to inspect one tag or folder: its title, parent folder, and the uuids of the notes filed under it.", tagsGetInput.shape, wrap(t.tags_get));
175
- registerTool("tags_create", "Use this to create a folder/tag (\"make a folder for X\"). Pass `parent` (tag UUID) to nest it under another folder — nesting is a paid Standard Notes feature, refused on free accounts. Creating a tag does not file any notes — use tags_attach for that.", tagsCreateInput.shape, wrap(t.tags_create));
176
- registerTool("tags_update", "Use this to rename a tag or move it in the folder hierarchy. `parent`: tag UUID to re-parent under (paid Standard Notes feature), null to move to the top level, omit to leave unchanged.", tagsUpdateInput.shape, wrap(t.tags_update));
177
- registerTool("tags_delete", "Use this ONLY when the user explicitly asks to delete a tag/folder. PERMANENT — tags have no trash state. The notes filed under it are not deleted.", tagsDeleteInput.shape, wrap(t.tags_delete));
178
- registerTool("tags_attach", "Use this to file a note under a tag/folder (\"tag this note as work\"). Needs both uuids — find them with notes_search and tags_list.", tagsAttachInput.shape, wrap(t.tags_attach));
179
- registerTool("tags_detach", "Use this to remove a note from a tag/folder. The note itself is not deleted.", tagsDetachInput.shape, wrap(t.tags_detach));
180
- registerTool("sync", "Use this when results look stale — e.g. the user just edited notes in the Standard Notes app and doesn't see the changes — to force a full re-sync. Normally unnecessary: every write already syncs first.", syncInput.shape, wrap(t.sync));
181
- registerTool("notes_frontmatter", "Use this to read or change a note's YAML frontmatter (the --- block at the top of markdown notes) — the structured metadata used for AI governance and organization. operation=get (all keys, or one `key`), set (`key` + `value`: string/number/boolean/string array), delete (`key`). Writes touch only the target key's lines; the rest of the block is preserved byte-for-byte. Note: `ai: read-only` / `ai: no-access` frontmatter governs what the AI may do with a note.", frontmatterInput.shape, wrap(h.notes_frontmatter));
182
- registerTool("smartviews_list", "Use this when the user asks about their Smart Views / saved searches (\"what views do I have\"). Returns uuid/title plus a readable summary of each view's filter. Smart Views are a paid Standard Notes feature; free accounts only have views from a past subscription — use notes_query for ad-hoc filters.", smartviewsListInput.shape, wrap(sv.smartviews_list));
183
- registerTool("smartviews_notes", "Use this when the user wants the notes inside one of their Smart Views (\"show me my Action items view\"). `view` takes the view's uuid or title. The saved filter is evaluated locally against the decrypted vault. Returns matching note summaries with totalCount; page with limit/offset.", smartviewsNotesInput.shape, wrap(sv.smartviews_notes));
184
- registerTool("notes_query", "Use this for structured filtering that notes_search can't express — e.g. \"archived markdown notes\", \"untagged notes updated this month\", \"notes pinned or with 0 tags\". `predicate` is Standard Notes' Smart View predicate JSON: leaf {\"keypath\",\"operator\",\"value\"} or compound {\"operator\":\"and\"|\"or\",\"value\":[...]}. Keypaths: title, text, trashed, archived, pinned, noteType, tagsCount, plus frontmatter.<key> for YAML frontmatter properties (e.g. notes where frontmatter.status = \"active\", or frontmatter.tags includes \"client\"). Do NOT use for keyword search — use notes_search.", notesQueryInput.shape, wrap(sv.notes_query));
185
- registerTool("daily_list", "Use this for \"what did I write/journal on <date>\". Returns the notes created on that date (defaults to today in the user's timezone), grouped by creation date.", dailyListInput.shape, wrap(d.daily_list));
186
- registerTool("daily_append", "Use this whenever the user says \"add this to my journal\" or \"journal about X\". Appends to today's \"Journal YYYY-MM-DD\" note, creating it if needed. Works on every plan as a normal note (the SN app's Daily Notebook view itself is a paid Standard Notes feature). `date` targets a past day, but only if a journal note already exists for it.", dailyAppendInput.shape, wrap(d.daily_append));
187
- registerTool("periodic_list", "Use this for \"what did I write this week / this month\". Lists the notes created during the day, ISO week (Mon-Sun) or calendar month containing `date` (default today).", periodicListInput.shape, wrap(d.periodic_list));
188
- registerTool("periodic_append", "Use this for weekly or monthly notes (\"add this to my weekly note\", \"monthly goals\"). Appends to the period's note — \"Week 2026-W49\" or \"Month 2026-12\" (period=day gives the daily \"Journal YYYY-MM-DD\") — creating it for the current period if needed. A past period works only if its note already exists.", periodicAppendInput.shape, wrap(d.periodic_append));
189
- registerTool("notes_history", "Use this when the user asks about a note's history or past versions (\"what did this note say last week\", \"undo my last edit\"). Lists the server-kept revisions of one note that the account's Standard Notes plan may view, newest first (free plans see recent revisions only).", historyInput.shape, wrap(hist.notes_history));
190
- registerTool("notes_revision_get", "Use this to READ one past version of a note (from notes_history). Returns the decrypted title/text as of that revision. Read-only — to make it current again use notes_revision_restore.", revisionGetInput.shape, wrap(hist.notes_revision_get));
191
- registerTool("notes_revision_restore", "Use this to RESTORE a note to a past version (from notes_history). Replaces the current content with the revision's content; the current state is itself kept as a revision, so this is undoable.", revisionRestoreInput.shape, wrap(hist.notes_revision_restore));
192
- registerTool("notes_tasks", "Use this when the user asks about their to-dos (\"what's on my task list\", \"open tasks in the work folder\"). Finds markdown checkbox items (- [ ] / - [x]) across the vault, open tasks only by default. Each task carries its note uuid and line number — feed those to notes_task_toggle to check it off.", tasksInput.shape, wrap(tk.notes_tasks));
193
- registerTool("notes_task_toggle", "Use this to check off or uncheck a task found by notes_tasks. `uuid` and `line` come from the notes_tasks result. If it fails with task_not_found, re-run notes_tasks — the note changed since the listing.", taskToggleInput.shape, wrap(tk.notes_task_toggle));
194
- registerTool("notes_links", "Use this to see how a note connects to others (\"what links to this note\", \"related notes\", \"what does this note reference\"). Returns outgoing links, backlinks (notes linking here), unresolved [[wikilinks]] (no matching note) and ambiguous ones (several notes share the title). Covers [[Title]] wikilinks in plain-text/markdown notes (every plan) and native Standard Notes links made in the app.", linksInput.shape, wrap(lk.notes_links));
195
- registerTool("notes_link", "Use this to link one note to another (\"link this to my Project X note\"). Adds a [[Target Title]] wikilink to the source note (at the end, or under `section`), and on paid Standard Notes plans also a native note link that shows in the app's linked items. Both uuids required; skips links that already exist.", linkInput.shape, wrap(lk.notes_link));
196
- registerTool("templates_list", `Use this when the user mentions templates ("what templates do I have", "use my meeting template"). Lists the notes in the "${config.templatesTag}" folder, which act as templates.`, templatesListInput.shape, wrap(tpl.templates_list));
197
- registerTool("notes_create_from_template", `Use this to create a note from a template ("start today's standup from my template"). Fills {{date}}, {{time}}, {{datetime}}, {{title}}, {{week}}, {{month}}, {{year}} and any {{name}} given in \`vars\`; the note is filed in the template's folders (except "${config.templatesTag}") plus \`tags\`. Placeholders without a value are left as-is and listed in \`unfilled\`.`, createFromTemplateInput.shape, wrap(tpl.notes_create_from_template));
145
+ registerTool("notes_list", "Browse notes, newest first (\"what notes do I have\", \"show my work notes\"). Returns uuid, title, updatedAt, preview. `tag` (uuid or title) shows one tag's notes; includeDescendants adds child tags. To find notes by words in them, use notes_search instead.", listInput.shape, wrap(h.notes_list));
146
+ registerTool("notes_stats", "Counts and size of the vault (\"how many notes do I have\"), note types, and sync health (cache age, decrypt failures).", statsInput.shape, wrap(h.notes_stats));
147
+ registerTool("notes_search", "Find notes by words in them (\"find my notes about X\", \"which note mentions Y\"). Usually the first step before reading or editing: it returns each note's uuid. mode=text (default): every word must appear in the title or body; small typos are tolerated (fuzzy=false for exact words); best matches first (sort=updated for newest first). mode=regex: one regular expression. Filters: tag, noteType, updatedAfter/updatedBefore (YYYY-MM-DD), includeTrashed. Returns snippets, totalCount and nextCursor (pass back as `cursor` for more). To list a tag's notes, use notes_list.", searchInput.shape, wrap(h.notes_search));
148
+ registerTool("notes_get", "Read one note (\"open my meeting notes\"). Needs the uuid: get it from notes_search or notes_list first. format: content (default: title, text, type), full (adds tags, timestamps, flags), outline (headings only; use first on long notes before a section edit), section (one heading's body; needs `section`, e.g. \"Projects::Alpha\").", getInput.shape, wrap(h.notes_get));
149
+ registerTool("notes_create", "Create one new note (\"make a note about X\"). title and text required. noteType defaults to markdown on paid plans and plain-text on free ones (free: other types are saved as plain text, super is refused). `tags` takes tag uuids from tags_list, not tag names. For several notes at once, use notes_create_many.", createInput.shape, wrap(h.notes_create));
150
+ registerTool("notes_create_many", "Create up to 50 notes in one go (bulk import). Each entry has the same fields as notes_create.", createManyInput.shape, wrap(h.notes_create_many));
151
+ registerTool("notes_update", "Replace a whole note: body (`text`), `title`, type, or its tags; also archive, pin, trash, or restore from trash (trashed=false). Tags: addTags / removeTags add or remove some and leave the rest; `tags` replaces ALL of them and needs replaceTags=true. trashed=true asks the user first, like notes_delete. To add a line or fix a word, use notes_append or notes_replace_in instead of resending the whole body. For many notes, use notes_update_many.", updateInput.shape, wrap(h.notes_update));
152
+ registerTool("notes_update_many", "Apply notes_update-style changes to up to 50 notes at once (\"archive all of these\"). Each entry needs a uuid; same fields as notes_update (addTags / removeTags for tags). Trashing asks the user first, like notes_delete. Failures are reported per note without stopping the rest.", updateManyInput.shape, wrap(h.notes_update_many));
153
+ registerTool("notes_delete_many", "Delete several notes at once. Moves them to trash by default; permanent=true deletes forever and only when the user explicitly asks for permanent deletion. Asks the user first: see notes_delete. Failures are reported per note.", deleteManyInput.shape, wrap(h.notes_delete_many));
154
+ registerTool("notes_append", "Add text to an existing note without rewriting it (\"add X to my log\", \"append this to the meeting notes\"). Needs the note uuid; the text to add goes in `content` (not `text`). `section` adds it under a heading (\"Log\", or \"Parent::Child\" for a sub-heading); position=append (default) adds at the end, prepend at the top (right under the heading). Plain-text and markdown notes only. To change existing text, use notes_replace_in.", appendInput.shape, wrap(h.notes_append));
155
+ registerTool("notes_replace_in", "Change or fix existing text in one note (\"fix the typo\", \"rename X to Y in that note\"). Needs the note uuid. Each rule finds text and replaces it; rules run in order. Literal text by default; useRegex=true for patterns; caseSensitive and replaceAll per rule. Reports how many replacements each rule made. Plain-text and markdown notes only. To add new text, use notes_append.", replaceInInput.shape, wrap(h.notes_replace_in));
156
+ registerTool("notes_delete", "Delete one note (\"delete that note\"). Moves it to trash by default (restore with notes_update trashed=false); permanent=true deletes forever and only when the user explicitly asks for permanent deletion. The user must agree first: the app may show a prompt, or the call returns confirmationRequired with a question; ask it, and only on a clear yes call again with its confirmToken. To take a note out of a tag without deleting it, use tags_detach.", deleteInput.shape, wrap(h.notes_delete));
157
+ registerTool("tags_list", "List all tags (users may call them folders): uuid, title, noteCount, parentUuid. Use it to find a tag's uuid, which other tools need.", tagsListInput.shape, wrap(t.tags_list));
158
+ registerTool("tags_get", "One tag's details: title, parent, and the uuids of the notes that have it.", tagsGetInput.shape, wrap(t.tags_get));
159
+ registerTool("tags_create", "Create a new tag (\"make a folder for X\"). `parent` (tag uuid) nests it under another tag, on paid plans only. It doesn't add the tag to any note; use tags_attach for that.", tagsCreateInput.shape, wrap(t.tags_create));
160
+ registerTool("tags_update", "Rename a tag, or move it: `parent` = another tag's uuid (paid plans only), or null for the top level. Omit `parent` to leave it where it is.", tagsUpdateInput.shape, wrap(t.tags_update));
161
+ registerTool("tags_delete", "Delete a tag permanently (tags have no trash). Only when the user explicitly asks to delete the tag. Its notes are not deleted.", tagsDeleteInput.shape, wrap(t.tags_delete));
162
+ registerTool("tags_attach", "Add a tag to a note (\"tag this as work\", \"file this under Projects\"). Needs the note uuid (notes_search) and the tag uuid (tags_list).", tagsAttachInput.shape, wrap(t.tags_attach));
163
+ registerTool("tags_detach", "Remove a tag from a note (\"take this out of Projects\"). The note itself is kept.", tagsDetachInput.shape, wrap(t.tags_detach));
164
+ registerTool("sync", "Force a full re-sync when results look out of date, e.g. the user just edited notes in the Standard Notes app. Usually not needed: writes sync first.", syncInput.shape, wrap(t.sync));
165
+ registerTool("notes_frontmatter", "Read or change a note's YAML frontmatter (the block between --- lines at the top). operation=get (all keys, or one `key`), set (`key` + `value`: text, number, true/false, or a list of text), delete (`key`). Only that key's lines change. The keys `ai: read-only` and `ai: no-access` control what AIs may do with the note.", frontmatterInput.shape, wrap(h.notes_frontmatter));
166
+ registerTool("smartviews_list", "List the user's Smart Views (saved searches, \"what views do I have\") with a summary of each filter. Free accounts usually have none. For a one-off filter, use notes_query.", smartviewsListInput.shape, wrap(sv.smartviews_list));
167
+ registerTool("smartviews_notes", "Notes in one Smart View (\"show my Action items view\"). `view`: uuid or title. Returns notes and totalCount; page with limit/offset.", smartviewsNotesInput.shape, wrap(sv.smartviews_notes));
168
+ registerTool("notes_query", "Filter notes by properties notes_search can't express: \"archived markdown notes\", \"untagged notes from this month\", \"notes where frontmatter status is active\". Takes a Standard Notes predicate (syntax under `predicate`). Not for finding words in notes: use notes_search.", notesQueryInput.shape, wrap(sv.notes_query));
169
+ registerTool("periodic_list", "Notes created in a day, ISO week (Monday to Sunday) or calendar month (\"what did I write today\", \"my journal for Monday\", \"what did I write this week\"). period: day (default), week or month; `date` is any day in the period, default today.", periodicListInput.shape, wrap(d.periodic_list));
170
+ registerTool("periodic_append", "Add to the journal, weekly or monthly note (\"add this to my journal\", \"journal about X\", \"add this to my weekly note\", \"monthly goals\"). period=day (default): today's \"Journal YYYY-MM-DD\"; week: \"Week 2026-W49\"; month: \"Month 2026-12\". The text to add goes in `content` (not `text`). Creates the note for the current period if needed; a past `date` works only if its note exists.", periodicAppendInput.shape, wrap(d.periodic_append));
171
+ registerTool("notes_history", "List a note's past versions, newest first (\"what did this say last week\", \"undo my last edit\"). Free plans keep recent versions only.", historyInput.shape, wrap(hist.notes_history));
172
+ registerTool("notes_revision_get", "Read one past version of a note (revisionUuid from notes_history). Read-only; to bring it back, use notes_revision_restore.", revisionGetInput.shape, wrap(hist.notes_revision_get));
173
+ registerTool("notes_revision_restore", "Restore a note to a past version (revisionUuid from notes_history). The current text is saved as a version first, so this can be undone.", revisionRestoreInput.shape, wrap(hist.notes_revision_restore));
174
+ registerTool("notes_tasks", "Find to-do checkboxes (- [ ] and - [x]) across notes (\"what's on my task list\"). Open tasks only unless includeDone. Each task has its note uuid and line number: pass both to notes_task_toggle to check it off.", tasksInput.shape, wrap(tk.notes_tasks));
175
+ registerTool("notes_task_toggle", "Check off or uncheck one task from notes_tasks, using its uuid and line. If it fails with task_not_found, run notes_tasks again: the note changed.", taskToggleInput.shape, wrap(tk.notes_task_toggle));
176
+ registerTool("notes_links", "How a note connects to others (\"what links to this note\"): outgoing links, backlinks, [[wikilinks]] with no matching note or several matches, and native Standard Notes links.", linksInput.shape, wrap(lk.notes_links));
177
+ registerTool("notes_link", "Link one note to another (\"link this to my Project X note\"): adds a [[Target Title]] wikilink to the source note (at the end, or under `section`), plus a native link on paid plans. Needs both uuids. Skips links that already exist.", linkInput.shape, wrap(lk.notes_link));
178
+ registerTool("templates_list", `List the user's templates ("what templates do I have"): notes tagged "${config.templatesTag}"${config.sharedTemplates ? ", including ones outside this client's tag scope (read-only)" : ""}. Then use notes_create_from_template.`, templatesListInput.shape, wrap(tpl.templates_list));
179
+ registerTool("notes_create_from_template", `Create a new note from a template ("start today's standup from my template"). \`template\`: uuid or title from templates_list. Fills {{date}} {{time}} {{datetime}} {{title}} {{week}} {{month}} {{year}}, and any {{name}} from \`vars\` (e.g. {"client": "Acme"}); unfilled placeholders are listed. The note gets the template's visible tags (not "${config.templatesTag}") plus \`tags\`; with a tag scope and none of those, the scope tag.`, createFromTemplateInput.shape, wrap(tpl.notes_create_from_template));
198
180
  /** Shared by the server_status tool and the sn://status resource. */
199
181
  const statusPayload = async () => {
200
182
  const stats = await client.stats();
@@ -206,7 +188,12 @@ export async function startServer() {
206
188
  tagScope: config.scope.readTags !== null || config.scope.denyTags.length > 0
207
189
  ? config.scope
208
190
  : null,
209
- deleteElicitation: config.deleteElicitation,
191
+ // Which scope entries actually matched a tag, plus warnings for the
192
+ // ones that didn't (issue #18). Resolved per call, so renaming a
193
+ // folder in Standard Notes shows up here after the next sync.
194
+ tagScopeStatus: client.scopeReport(),
195
+ deleteConfirm: config.deleteConfirm,
196
+ sharedTemplates: config.sharedTemplates,
210
197
  };
211
198
  const ent = client.entitlement();
212
199
  return {
@@ -221,19 +208,19 @@ export async function startServer() {
221
208
  };
222
209
  // Many clients (Lumo, for one) expose tools but not resources, so the
223
210
  // sn://status data is also available as a tool.
224
- registerTool("server_status", "Use this when the user asks which Standard Notes plan they are on (free or paid), which features are limited on their plan, whether the server is read-only or scoped to some folders, or about sync health. No arguments. Same data as the sn://status resource.", {}, wrap(async () => statusPayload()));
211
+ registerTool("server_status", "Server and account status (\"am I on the free plan\", \"why can't you see my notes\"): plan and its limits, read-only mode, tag scope and whether each entry matched a tag, sync health. Same as sn://status.", {}, wrap(async () => statusPayload()));
225
212
  // vault_export writes DECRYPTED notes to disk — only registered when the
226
213
  // operator opted in with SN_ALLOW_EXPORT.
227
214
  if (config.allowExport) {
228
215
  const x = registerExportHandlers(client, config.exportDir);
229
216
  registerTool("vault_export", "Use this when the user asks for a backup or export of their notes as files. Writes decrypted notes as markdown files (plus index.json) into an absolute directory; `tag` limits it to one folder subtree. Protected notes are skipped. This writes PLAINTEXT to disk — confirm the destination with the user first.", exportInput.shape, wrap(x.vault_export));
230
217
  }
231
- server.resource("tags", "sn://tags", { description: "Every tag with its note count — uncapped snapshot of the folder structure" }, async (uri) => ({
218
+ server.resource("tags", "sn://tags", { description: "Every tag with its note count — uncapped snapshot of the tag structure" }, async (uri) => ({
232
219
  contents: [
233
220
  {
234
221
  uri: uri.href,
235
222
  mimeType: "application/json",
236
- text: JSON.stringify(await client.listTags(), null, 2),
223
+ text: JSON.stringify(await client.listTags()),
237
224
  },
238
225
  ],
239
226
  }));
@@ -242,7 +229,7 @@ export async function startServer() {
242
229
  {
243
230
  uri: uri.href,
244
231
  mimeType: "application/json",
245
- text: JSON.stringify(await statusPayload(), null, 2),
232
+ text: JSON.stringify(await statusPayload()),
246
233
  },
247
234
  ],
248
235
  }));
@@ -256,7 +243,7 @@ export async function startServer() {
256
243
  {
257
244
  uri: uri.href,
258
245
  mimeType: "application/json",
259
- text: JSON.stringify(note, null, 2),
246
+ text: JSON.stringify(note),
260
247
  },
261
248
  ],
262
249
  };
@@ -294,7 +281,7 @@ export async function startServer() {
294
281
  ],
295
282
  };
296
283
  });
297
- server.prompt("inbox-triage", "Find untagged notes and suggest which existing tags (folders) they belong in.", {}, async () => {
284
+ server.prompt("inbox-triage", "Find untagged notes and suggest which existing tags they belong in.", {}, async () => {
298
285
  const [notes, tags] = await Promise.all([
299
286
  client.listNotes({ limit: 200, offset: 0, includeTrashed: false }),
300
287
  client.listTags(),
@@ -322,6 +309,10 @@ export async function startServer() {
322
309
  ],
323
310
  };
324
311
  });
312
+ // Smaller tool list for the model's context window; see slimTools.ts.
313
+ if (!installSlimToolList(server)) {
314
+ logger.warn("Could not slim the tool list (MCP SDK internals changed); sending it unmodified");
315
+ }
325
316
  const transport = new StdioServerTransport();
326
317
  await server.connect(transport);
327
318
  logger.info("MCP StandardNotes ready on stdio");
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Shrinks the tool list sent to AI clients. Every tool definition is sent on
3
+ * every request in most clients, so its size comes straight out of the
4
+ * model's context window (it matters most for smaller windows, like Lumo's).
5
+ *
6
+ * Only what the model doesn't need is removed. Input validation is unchanged:
7
+ * the server still validates every call against the full zod schema.
8
+ * - `$schema` on every input schema (the draft URL; clients don't need it)
9
+ * - the ~180-character `pattern` zod emits next to `format: "uuid"`
10
+ * (32 copies across the tools); `format: "uuid"` stays
11
+ * - `execution: { taskSupport: "forbidden" }`, which is the default when
12
+ * absent
13
+ */
14
+ export function slimSchema(node) {
15
+ if (Array.isArray(node))
16
+ return node.map(slimSchema);
17
+ if (node === null || typeof node !== "object")
18
+ return node;
19
+ const out = {};
20
+ const obj = node;
21
+ for (const [k, v] of Object.entries(obj)) {
22
+ if (k === "$schema")
23
+ continue;
24
+ if (k === "pattern" && obj.format === "uuid")
25
+ continue;
26
+ out[k] = slimSchema(v);
27
+ }
28
+ return out;
29
+ }
30
+ export function slimTool(tool) {
31
+ const { execution, inputSchema, outputSchema, ...rest } = tool;
32
+ const out = { ...rest };
33
+ if (inputSchema !== undefined)
34
+ out.inputSchema = slimSchema(inputSchema);
35
+ if (outputSchema !== undefined)
36
+ out.outputSchema = slimSchema(outputSchema);
37
+ const taskSupport = execution?.taskSupport;
38
+ if (execution !== undefined && taskSupport !== "forbidden")
39
+ out.execution = execution;
40
+ return out;
41
+ }
42
+ /**
43
+ * Note flags that are almost always false. Left out of tool results when
44
+ * false (a missing flag means false), which saves ~70 characters per note
45
+ * in every list and search result. Only these names: other false values,
46
+ * like `ok` or `matched`, are kept.
47
+ */
48
+ const OMIT_WHEN_FALSE = new Set(["trashed", "protected", "locked", "archived", "pinned"]);
49
+ /** Tool results as compact JSON (no indentation), without false note flags. */
50
+ export function compactResult(value) {
51
+ return JSON.stringify(value, (key, v) => v === false && OMIT_WHEN_FALSE.has(key) ? undefined : v);
52
+ }
53
+ /**
54
+ * Wraps the SDK's tools/list handler with slimTool. Call after the tools are
55
+ * registered (the SDK installs the handler on the first registration). The
56
+ * handler map is SDK-internal, so this checks its shape and leaves the
57
+ * default list in place if a future SDK changes it. Returns whether it
58
+ * applied.
59
+ */
60
+ export function installSlimToolList(server) {
61
+ const handlers = server.server._requestHandlers;
62
+ if (!(handlers instanceof Map))
63
+ return false;
64
+ const original = handlers.get("tools/list");
65
+ if (typeof original !== "function")
66
+ return false;
67
+ handlers.set("tools/list", async (request, extra) => {
68
+ const res = (await original(request, extra));
69
+ if (!res || !Array.isArray(res.tools))
70
+ return res;
71
+ return {
72
+ ...res,
73
+ tools: res.tools.map((t) => t !== null && typeof t === "object" ? slimTool(t) : t),
74
+ };
75
+ });
76
+ return true;
77
+ }
78
+ //# sourceMappingURL=slimTools.js.map