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/CHANGELOG.md +37 -0
- package/README.md +91 -44
- package/SECURITY.md +2 -1
- package/dist/cli/clients.js +124 -0
- package/dist/cli/folders.js +63 -0
- package/dist/cli/install.js +58 -9
- package/dist/cli/login.js +13 -1
- package/dist/cli/setup.js +163 -59
- package/dist/config.js +30 -2
- package/dist/confirmDelete.js +88 -0
- package/dist/server.js +76 -85
- package/dist/slimTools.js +78 -0
- package/dist/sn/client.js +185 -40
- package/dist/sn/entitlement.js +25 -6
- package/dist/sn/frontmatter.js +15 -4
- package/dist/sn/markdownSections.js +16 -1
- package/dist/sn/protocol004.js +11 -8
- package/dist/sn/scope.js +34 -0
- package/dist/sn/session.js +21 -3
- package/dist/tools/daily.js +7 -19
- package/dist/tools/history.js +1 -1
- package/dist/tools/links.js +2 -9
- package/dist/tools/notes.js +142 -42
- package/dist/tools/smartviews.js +5 -5
- package/dist/tools/tags.js +1 -1
- package/dist/tools/templates.js +42 -32
- package/docs/self-hosted.md +1 -1
- package/docs/troubleshooting.md +9 -1
- package/package.json +2 -2
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 {
|
|
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
|
-
"
|
|
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.
|
|
51
|
-
?
|
|
52
|
-
:
|
|
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
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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,
|
|
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:
|
|
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
|
-
}
|
|
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", "
|
|
162
|
-
registerTool("notes_stats", "
|
|
163
|
-
registerTool("notes_search", "
|
|
164
|
-
registerTool("notes_get", "
|
|
165
|
-
registerTool("notes_create", "
|
|
166
|
-
registerTool("notes_create_many", "
|
|
167
|
-
registerTool("notes_update", "
|
|
168
|
-
registerTool("notes_update_many", "
|
|
169
|
-
registerTool("notes_delete_many", "
|
|
170
|
-
registerTool("notes_append", "
|
|
171
|
-
registerTool("notes_replace_in", "
|
|
172
|
-
registerTool("notes_delete", "
|
|
173
|
-
registerTool("tags_list", "
|
|
174
|
-
registerTool("tags_get", "
|
|
175
|
-
registerTool("tags_create", "
|
|
176
|
-
registerTool("tags_update", "
|
|
177
|
-
registerTool("tags_delete", "
|
|
178
|
-
registerTool("tags_attach", "
|
|
179
|
-
registerTool("tags_detach", "
|
|
180
|
-
registerTool("sync", "
|
|
181
|
-
registerTool("notes_frontmatter", "
|
|
182
|
-
registerTool("smartviews_list", "
|
|
183
|
-
registerTool("smartviews_notes", "
|
|
184
|
-
registerTool("notes_query", "
|
|
185
|
-
registerTool("
|
|
186
|
-
registerTool("
|
|
187
|
-
registerTool("
|
|
188
|
-
registerTool("
|
|
189
|
-
registerTool("
|
|
190
|
-
registerTool("
|
|
191
|
-
registerTool("
|
|
192
|
-
registerTool("
|
|
193
|
-
registerTool("
|
|
194
|
-
registerTool("
|
|
195
|
-
registerTool("
|
|
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
|
-
|
|
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", "
|
|
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
|
|
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()
|
|
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()
|
|
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
|
|
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
|
|
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
|