standardnotes-mcp 3.0.0 → 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 +55 -0
- package/README.md +118 -55
- package/SECURITY.md +2 -1
- package/dist/cli/clients.js +124 -0
- package/dist/cli/folders.js +63 -0
- package/dist/cli/install.js +60 -18
- package/dist/cli/isMain.js +21 -0
- package/dist/cli/login.js +15 -12
- package/dist/cli/logout.js +1 -1
- package/dist/cli/setup.js +168 -72
- package/dist/config.js +30 -2
- package/dist/confirmDelete.js +88 -0
- package/dist/server.js +79 -86
- package/dist/slimTools.js +78 -0
- package/dist/sn/client.js +189 -44
- 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 +22 -4
- 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/dist/version.js +12 -0
- package/docs/self-hosted.md +7 -10
- package/docs/troubleshooting.md +97 -89
- package/package.json +6 -5
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/login.js.map +0 -1
- package/dist/cli/logout.js.map +0 -1
- package/dist/cli/setup.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/security/errors.js.map +0 -1
- package/dist/security/logger.js.map +0 -1
- package/dist/security/redact.js.map +0 -1
- package/dist/security/regex.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/sn/cache.js.map +0 -1
- package/dist/sn/client.js.map +0 -1
- package/dist/sn/crypto.js.map +0 -1
- package/dist/sn/dates.js.map +0 -1
- package/dist/sn/entitlement.js.map +0 -1
- package/dist/sn/frontmatter.js.map +0 -1
- package/dist/sn/governance.js.map +0 -1
- package/dist/sn/http.js.map +0 -1
- package/dist/sn/links.js.map +0 -1
- package/dist/sn/markdownSections.js.map +0 -1
- package/dist/sn/predicates.js.map +0 -1
- package/dist/sn/protocol004.js.map +0 -1
- package/dist/sn/scope.js.map +0 -1
- package/dist/sn/search.js.map +0 -1
- package/dist/sn/session.js.map +0 -1
- package/dist/sn/tagHierarchy.js.map +0 -1
- package/dist/sn/tasks.js.map +0 -1
- package/dist/sn/templates.js.map +0 -1
- package/dist/sn/types.js.map +0 -1
- package/dist/tools/daily.js.map +0 -1
- package/dist/tools/export.js.map +0 -1
- package/dist/tools/history.js.map +0 -1
- package/dist/tools/links.js.map +0 -1
- package/dist/tools/notes.js.map +0 -1
- package/dist/tools/smartviews.js.map +0 -1
- package/dist/tools/tags.js.map +0 -1
- package/dist/tools/tasks.js.map +0 -1
- package/dist/tools/templates.js.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { ToolError } from "./security/errors.js";
|
|
3
|
+
const TOKEN_TTL_MS = 10 * 60 * 1000;
|
|
4
|
+
function describe(req) {
|
|
5
|
+
const where = req.permanent ? "PERMANENTLY (cannot be undone)" : "to the trash";
|
|
6
|
+
if (req.notes.length === 1) {
|
|
7
|
+
const n = req.notes[0];
|
|
8
|
+
return `Delete note "${n.title}" ${where}?`;
|
|
9
|
+
}
|
|
10
|
+
const titles = req.notes.slice(0, 10).map((n) => `"${n.title}"`).join(", ");
|
|
11
|
+
const more = req.notes.length > 10 ? ` and ${req.notes.length - 10} more` : "";
|
|
12
|
+
return `Delete ${req.notes.length} notes ${where}: ${titles}${more}?`;
|
|
13
|
+
}
|
|
14
|
+
function keyOf(req) {
|
|
15
|
+
return `${req.permanent ? "P" : "T"}:${req.notes.map((n) => n.uuid).sort().join(",")}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds the delete guard. A delete goes ahead only after the user agrees:
|
|
19
|
+
*
|
|
20
|
+
* - App prompt (MCP elicitation): shown when the app supports it. Accept
|
|
21
|
+
* deletes; decline or dismiss cancels.
|
|
22
|
+
* - Chat confirmation (auto mode, apps without a prompt such as Lumo): the
|
|
23
|
+
* first call deletes nothing and returns a one-time `confirmToken` with the
|
|
24
|
+
* question to ask. The AI must ask the user, and only on a clear yes call
|
|
25
|
+
* again with the same arguments plus the token. A token is bound to exactly
|
|
26
|
+
* those notes and that trash/permanent choice, works once, and expires
|
|
27
|
+
* after 10 minutes.
|
|
28
|
+
* - prompt mode refuses (confirmation_unavailable) when the app can't show a
|
|
29
|
+
* prompt, rather than deleting unasked.
|
|
30
|
+
*/
|
|
31
|
+
export function makeDeleteGuard(server, mode, now = Date.now) {
|
|
32
|
+
const pending = new Map();
|
|
33
|
+
const cannotConfirm = () => new ToolError("confirmation_unavailable", "Deletes need the user's confirmation in the app's prompt (SN_DELETE_CONFIRM=prompt), but this AI app can't show one, so nothing was deleted.", "Tell the user to delete the note in Standard Notes, or to remove SN_DELETE_CONFIRM=prompt (or SN_DELETE_ELICITATION) for this app so the AI can ask in chat instead.");
|
|
34
|
+
const askInChat = (req, token) => {
|
|
35
|
+
const t = now();
|
|
36
|
+
for (const [k, v] of pending)
|
|
37
|
+
if (v.expires <= t)
|
|
38
|
+
pending.delete(k);
|
|
39
|
+
const key = keyOf(req);
|
|
40
|
+
if (token !== undefined) {
|
|
41
|
+
const entry = pending.get(token);
|
|
42
|
+
if (entry && entry.key === key) {
|
|
43
|
+
pending.delete(token);
|
|
44
|
+
return { proceed: true };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const fresh = randomBytes(9).toString("hex");
|
|
48
|
+
pending.set(fresh, { key, expires: t + TOKEN_TTL_MS });
|
|
49
|
+
const question = describe(req);
|
|
50
|
+
return {
|
|
51
|
+
proceed: false,
|
|
52
|
+
result: {
|
|
53
|
+
ok: false,
|
|
54
|
+
confirmationRequired: true,
|
|
55
|
+
...(token !== undefined
|
|
56
|
+
? { tokenProblem: "That confirmToken was expired, already used, or for different notes. Ask the user again." }
|
|
57
|
+
: {}),
|
|
58
|
+
question,
|
|
59
|
+
confirmToken: fresh,
|
|
60
|
+
instructions: `Nothing was deleted. Ask the user exactly: ${question} Only if they clearly say yes, call ${req.tool} again with the same arguments plus confirmToken "${fresh}". If they say no or don't answer, don't call it again.`,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
return async (req, token) => {
|
|
65
|
+
if (mode === "off" || req.notes.length === 0)
|
|
66
|
+
return { proceed: true };
|
|
67
|
+
if (server.getClientCapabilities()?.elicitation) {
|
|
68
|
+
try {
|
|
69
|
+
const res = await server.elicitInput({
|
|
70
|
+
message: `${describe(req)}${req.permanent ? "" : " Trash can be restored."}`,
|
|
71
|
+
requestedSchema: { type: "object", properties: {} },
|
|
72
|
+
});
|
|
73
|
+
return res.action === "accept"
|
|
74
|
+
? { proceed: true }
|
|
75
|
+
: { proceed: false, result: { ok: false, cancelled: true } };
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
if (mode === "prompt")
|
|
79
|
+
throw cannotConfirm();
|
|
80
|
+
return askInChat(req, token);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (mode === "prompt")
|
|
84
|
+
throw cannotConfirm();
|
|
85
|
+
return askInChat(req, token);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=confirmDelete.js.map
|
package/dist/server.js
CHANGED
|
@@ -3,13 +3,16 @@ 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";
|
|
9
|
+
import { VERSION } from "./version.js";
|
|
7
10
|
import { createClientFromSession } from "./sn/client.js";
|
|
8
11
|
import { degradedFeatures } from "./sn/entitlement.js";
|
|
9
12
|
import { appendInput, createInput, createManyInput, deleteInput, deleteManyInput, frontmatterInput, getInput, listInput, registerNoteHandlers, replaceInInput, searchInput, statsInput, updateInput, updateManyInput, } from "./tools/notes.js";
|
|
10
13
|
import { registerTagHandlers, syncInput, tagsAttachInput, tagsCreateInput, tagsDeleteInput, tagsDetachInput, tagsGetInput, tagsListInput, tagsUpdateInput, } from "./tools/tags.js";
|
|
11
14
|
import { notesQueryInput, registerSmartViewHandlers, smartviewsListInput, smartviewsNotesInput, } from "./tools/smartviews.js";
|
|
12
|
-
import {
|
|
15
|
+
import { periodicAppendInput, periodicListInput, registerDailyHandlers, } from "./tools/daily.js";
|
|
13
16
|
import { registerTaskHandlers, tasksInput, taskToggleInput, } from "./tools/tasks.js";
|
|
14
17
|
import { exportInput, registerExportHandlers } from "./tools/export.js";
|
|
15
18
|
import { historyInput, registerHistoryHandlers, revisionGetInput, revisionRestoreInput, } from "./tools/history.js";
|
|
@@ -34,72 +37,55 @@ export async function startServer() {
|
|
|
34
37
|
// wins; otherwise fall back to the name the client reports at initialize.
|
|
35
38
|
// Read lazily — the handshake name only exists after connect.
|
|
36
39
|
clientName: () => config.clientName ?? server.server.getClientVersion()?.name ?? null,
|
|
40
|
+
newNoteEditor: config.newNoteEditor,
|
|
37
41
|
});
|
|
38
42
|
const scoped = config.scope.readTags !== null || config.scope.denyTags.length > 0;
|
|
39
43
|
const plan = client.entitlement().plan;
|
|
40
44
|
const instructions = [
|
|
41
45
|
"Standard Notes MCP: end-to-end encrypted vault. All content is decrypted locally; the server only ever sees ciphertext.",
|
|
42
|
-
"
|
|
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.",
|
|
43
48
|
config.readOnly
|
|
44
49
|
? "READ-ONLY mode is active: write tools are not available."
|
|
45
50
|
: null,
|
|
46
51
|
scoped
|
|
47
52
|
? "A tag-based read scope is active: notes and tags outside the scope are hidden and appear as not found."
|
|
48
53
|
: null,
|
|
49
|
-
config.
|
|
50
|
-
?
|
|
51
|
-
:
|
|
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.`),
|
|
52
62
|
config.governance
|
|
53
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.'
|
|
54
64
|
: null,
|
|
55
65
|
plan === "paid"
|
|
56
66
|
? null
|
|
57
|
-
: "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.",
|
|
58
68
|
]
|
|
59
69
|
.filter((s) => s !== null)
|
|
60
70
|
.join(" ");
|
|
61
71
|
const server = new McpServer({
|
|
62
72
|
name: "StandardNotes-MCP",
|
|
63
|
-
version:
|
|
73
|
+
version: VERSION,
|
|
64
74
|
}, { instructions });
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
message: `Delete note "${note.title}" (${note.uuid})? Trash is recoverable; permanent delete is not.`,
|
|
70
|
-
requestedSchema: { type: "object", properties: {} },
|
|
71
|
-
});
|
|
72
|
-
return res.action === "accept";
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
// Client without elicitation support: fall back to immediate
|
|
76
|
-
// delete (documented behavior).
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
: undefined;
|
|
81
|
-
const confirmBatchDelete = config.deleteElicitation
|
|
82
|
-
? async (count, permanent) => {
|
|
83
|
-
try {
|
|
84
|
-
const res = await server.server.elicitInput({
|
|
85
|
-
message: `Delete ${count} note(s)${permanent ? " PERMANENTLY (irreversible)" : " (to trash)"}?`,
|
|
86
|
-
requestedSchema: { type: "object", properties: {} },
|
|
87
|
-
});
|
|
88
|
-
return res.action === "accept";
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
: undefined;
|
|
95
|
-
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 });
|
|
96
79
|
const t = registerTagHandlers(client);
|
|
97
80
|
const sv = registerSmartViewHandlers(client);
|
|
98
81
|
const d = registerDailyHandlers(client, config.periodicTag);
|
|
99
82
|
const tk = registerTaskHandlers(client);
|
|
100
83
|
const hist = registerHistoryHandlers(client);
|
|
101
84
|
const lk = registerLinkHandlers(client);
|
|
102
|
-
const tpl = registerTemplateHandlers(client,
|
|
85
|
+
const tpl = registerTemplateHandlers(client, {
|
|
86
|
+
templatesTag: config.templatesTag,
|
|
87
|
+
shared: config.sharedTemplates,
|
|
88
|
+
});
|
|
103
89
|
// In read-only mode, write tools are not registered at all — they don't
|
|
104
90
|
// appear in tools/list, so the agent never tries them.
|
|
105
91
|
const WRITE_TOOLS = new Set([
|
|
@@ -112,7 +98,6 @@ export async function startServer() {
|
|
|
112
98
|
"notes_delete",
|
|
113
99
|
"notes_delete_many",
|
|
114
100
|
"notes_frontmatter",
|
|
115
|
-
"daily_append",
|
|
116
101
|
"periodic_append",
|
|
117
102
|
"notes_task_toggle",
|
|
118
103
|
"notes_revision_restore",
|
|
@@ -133,7 +118,7 @@ export async function startServer() {
|
|
|
133
118
|
try {
|
|
134
119
|
const result = await fn(args);
|
|
135
120
|
return {
|
|
136
|
-
content: [{ type: "text", text:
|
|
121
|
+
content: [{ type: "text", text: compactResult(result) }],
|
|
137
122
|
};
|
|
138
123
|
}
|
|
139
124
|
catch (err) {
|
|
@@ -149,7 +134,7 @@ export async function startServer() {
|
|
|
149
134
|
reason: err.reason,
|
|
150
135
|
message: err.message,
|
|
151
136
|
recoveryHint: err.recoveryHint,
|
|
152
|
-
}
|
|
137
|
+
}),
|
|
153
138
|
},
|
|
154
139
|
],
|
|
155
140
|
};
|
|
@@ -157,43 +142,41 @@ export async function startServer() {
|
|
|
157
142
|
throw err;
|
|
158
143
|
}
|
|
159
144
|
};
|
|
160
|
-
registerTool("notes_list", "
|
|
161
|
-
registerTool("notes_stats", "
|
|
162
|
-
registerTool("notes_search", "
|
|
163
|
-
registerTool("notes_get", "
|
|
164
|
-
registerTool("notes_create", "
|
|
165
|
-
registerTool("notes_create_many", "
|
|
166
|
-
registerTool("notes_update", "
|
|
167
|
-
registerTool("notes_update_many", "
|
|
168
|
-
registerTool("notes_delete_many", "
|
|
169
|
-
registerTool("notes_append", "
|
|
170
|
-
registerTool("notes_replace_in", "
|
|
171
|
-
registerTool("notes_delete", "
|
|
172
|
-
registerTool("tags_list", "
|
|
173
|
-
registerTool("tags_get", "
|
|
174
|
-
registerTool("tags_create", "
|
|
175
|
-
registerTool("tags_update", "
|
|
176
|
-
registerTool("tags_delete", "
|
|
177
|
-
registerTool("tags_attach", "
|
|
178
|
-
registerTool("tags_detach", "
|
|
179
|
-
registerTool("sync", "
|
|
180
|
-
registerTool("notes_frontmatter", "
|
|
181
|
-
registerTool("smartviews_list", "
|
|
182
|
-
registerTool("smartviews_notes", "
|
|
183
|
-
registerTool("notes_query", "
|
|
184
|
-
registerTool("
|
|
185
|
-
registerTool("
|
|
186
|
-
registerTool("
|
|
187
|
-
registerTool("
|
|
188
|
-
registerTool("
|
|
189
|
-
registerTool("
|
|
190
|
-
registerTool("
|
|
191
|
-
registerTool("
|
|
192
|
-
registerTool("
|
|
193
|
-
registerTool("
|
|
194
|
-
registerTool("
|
|
195
|
-
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));
|
|
196
|
-
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));
|
|
197
180
|
/** Shared by the server_status tool and the sn://status resource. */
|
|
198
181
|
const statusPayload = async () => {
|
|
199
182
|
const stats = await client.stats();
|
|
@@ -205,10 +188,16 @@ export async function startServer() {
|
|
|
205
188
|
tagScope: config.scope.readTags !== null || config.scope.denyTags.length > 0
|
|
206
189
|
? config.scope
|
|
207
190
|
: null,
|
|
208
|
-
|
|
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,
|
|
209
197
|
};
|
|
210
198
|
const ent = client.entitlement();
|
|
211
199
|
return {
|
|
200
|
+
serverVersion: VERSION,
|
|
212
201
|
...stats,
|
|
213
202
|
policy,
|
|
214
203
|
plan: {
|
|
@@ -219,19 +208,19 @@ export async function startServer() {
|
|
|
219
208
|
};
|
|
220
209
|
// Many clients (Lumo, for one) expose tools but not resources, so the
|
|
221
210
|
// sn://status data is also available as a tool.
|
|
222
|
-
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()));
|
|
223
212
|
// vault_export writes DECRYPTED notes to disk — only registered when the
|
|
224
213
|
// operator opted in with SN_ALLOW_EXPORT.
|
|
225
214
|
if (config.allowExport) {
|
|
226
215
|
const x = registerExportHandlers(client, config.exportDir);
|
|
227
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));
|
|
228
217
|
}
|
|
229
|
-
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) => ({
|
|
230
219
|
contents: [
|
|
231
220
|
{
|
|
232
221
|
uri: uri.href,
|
|
233
222
|
mimeType: "application/json",
|
|
234
|
-
text: JSON.stringify(await client.listTags()
|
|
223
|
+
text: JSON.stringify(await client.listTags()),
|
|
235
224
|
},
|
|
236
225
|
],
|
|
237
226
|
}));
|
|
@@ -240,7 +229,7 @@ export async function startServer() {
|
|
|
240
229
|
{
|
|
241
230
|
uri: uri.href,
|
|
242
231
|
mimeType: "application/json",
|
|
243
|
-
text: JSON.stringify(await statusPayload()
|
|
232
|
+
text: JSON.stringify(await statusPayload()),
|
|
244
233
|
},
|
|
245
234
|
],
|
|
246
235
|
}));
|
|
@@ -254,7 +243,7 @@ export async function startServer() {
|
|
|
254
243
|
{
|
|
255
244
|
uri: uri.href,
|
|
256
245
|
mimeType: "application/json",
|
|
257
|
-
text: JSON.stringify(note
|
|
246
|
+
text: JSON.stringify(note),
|
|
258
247
|
},
|
|
259
248
|
],
|
|
260
249
|
};
|
|
@@ -292,7 +281,7 @@ export async function startServer() {
|
|
|
292
281
|
],
|
|
293
282
|
};
|
|
294
283
|
});
|
|
295
|
-
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 () => {
|
|
296
285
|
const [notes, tags] = await Promise.all([
|
|
297
286
|
client.listNotes({ limit: 200, offset: 0, includeTrashed: false }),
|
|
298
287
|
client.listTags(),
|
|
@@ -320,6 +309,10 @@ export async function startServer() {
|
|
|
320
309
|
],
|
|
321
310
|
};
|
|
322
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
|
+
}
|
|
323
316
|
const transport = new StdioServerTransport();
|
|
324
317
|
await server.connect(transport);
|
|
325
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
|