standardnotes-mcp 0.0.0-stage → 3.0.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 +165 -0
- package/LICENSE +22 -0
- package/README.md +320 -3
- package/SECURITY.md +56 -0
- package/dist/cli/install.js +187 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/login.js +126 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/logout.js +22 -0
- package/dist/cli/logout.js.map +1 -0
- package/dist/cli/setup.js +200 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/security/errors.js +20 -0
- package/dist/security/errors.js.map +1 -0
- package/dist/security/logger.js +17 -0
- package/dist/security/logger.js.map +1 -0
- package/dist/security/redact.js +31 -0
- package/dist/security/redact.js.map +1 -0
- package/dist/security/regex.js +27 -0
- package/dist/security/regex.js.map +1 -0
- package/dist/server.js +327 -0
- package/dist/server.js.map +1 -0
- package/dist/sn/cache.js +53 -0
- package/dist/sn/cache.js.map +1 -0
- package/dist/sn/client.js +1999 -0
- package/dist/sn/client.js.map +1 -0
- package/dist/sn/crypto.js +63 -0
- package/dist/sn/crypto.js.map +1 -0
- package/dist/sn/dates.js +157 -0
- package/dist/sn/dates.js.map +1 -0
- package/dist/sn/entitlement.js +75 -0
- package/dist/sn/entitlement.js.map +1 -0
- package/dist/sn/frontmatter.js +171 -0
- package/dist/sn/frontmatter.js.map +1 -0
- package/dist/sn/governance.js +40 -0
- package/dist/sn/governance.js.map +1 -0
- package/dist/sn/http.js +289 -0
- package/dist/sn/http.js.map +1 -0
- package/dist/sn/links.js +78 -0
- package/dist/sn/links.js.map +1 -0
- package/dist/sn/markdownSections.js +141 -0
- package/dist/sn/markdownSections.js.map +1 -0
- package/dist/sn/predicates.js +135 -0
- package/dist/sn/predicates.js.map +1 -0
- package/dist/sn/protocol004.js +401 -0
- package/dist/sn/protocol004.js.map +1 -0
- package/dist/sn/scope.js +68 -0
- package/dist/sn/scope.js.map +1 -0
- package/dist/sn/search.js +260 -0
- package/dist/sn/search.js.map +1 -0
- package/dist/sn/session.js +55 -0
- package/dist/sn/session.js.map +1 -0
- package/dist/sn/tagHierarchy.js +105 -0
- package/dist/sn/tagHierarchy.js.map +1 -0
- package/dist/sn/tasks.js +32 -0
- package/dist/sn/tasks.js.map +1 -0
- package/dist/sn/templates.js +23 -0
- package/dist/sn/templates.js.map +1 -0
- package/dist/sn/types.js +12 -0
- package/dist/sn/types.js.map +1 -0
- package/dist/tools/daily.js +126 -0
- package/dist/tools/daily.js.map +1 -0
- package/dist/tools/export.js +96 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/history.js +41 -0
- package/dist/tools/history.js.map +1 -0
- package/dist/tools/links.js +51 -0
- package/dist/tools/links.js.map +1 -0
- package/dist/tools/notes.js +404 -0
- package/dist/tools/notes.js.map +1 -0
- package/dist/tools/smartviews.js +52 -0
- package/dist/tools/smartviews.js.map +1 -0
- package/dist/tools/tags.js +82 -0
- package/dist/tools/tags.js.map +1 -0
- package/dist/tools/tasks.js +43 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/templates.js +145 -0
- package/dist/tools/templates.js.map +1 -0
- package/docs/protocol-004.md +72 -0
- package/docs/self-hosted.md +123 -0
- package/docs/troubleshooting.md +89 -0
- package/package.json +85 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC1B,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;QAClC,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;KAC1D,CAAC,CAAC;IACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured tool errors. MCP clients (LLMs) recover far better from a
|
|
3
|
+
* machine-readable `reason` plus a `recoveryHint` than from a bare message
|
|
4
|
+
* string — the hint tells the agent what to do next (e.g. "run notes_search
|
|
5
|
+
* to find the uuid") instead of leaving it to guess.
|
|
6
|
+
*/
|
|
7
|
+
export class ToolError extends Error {
|
|
8
|
+
reason;
|
|
9
|
+
recoveryHint;
|
|
10
|
+
constructor(reason, message, recoveryHint) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "ToolError";
|
|
13
|
+
this.reason = reason;
|
|
14
|
+
this.recoveryHint = recoveryHint;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function isToolError(err) {
|
|
18
|
+
return err instanceof ToolError;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/security/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,CAAS;IACf,YAAY,CAAU;IAE/B,YAAY,MAAc,EAAE,OAAe,EAAE,YAAqB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,GAAG,YAAY,SAAS,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { redact, redactString } from "./redact.js";
|
|
2
|
+
function write(level, msg, meta) {
|
|
3
|
+
const line = meta === undefined
|
|
4
|
+
? `[${level}] ${redactString(msg)}`
|
|
5
|
+
: `[${level}] ${redactString(msg)} ${JSON.stringify(redact(meta))}`;
|
|
6
|
+
process.stderr.write(line + "\n");
|
|
7
|
+
}
|
|
8
|
+
export const logger = {
|
|
9
|
+
debug: (msg, meta) => {
|
|
10
|
+
if (process.env.DEBUG)
|
|
11
|
+
write("debug", msg, meta);
|
|
12
|
+
},
|
|
13
|
+
info: (msg, meta) => write("info", msg, meta),
|
|
14
|
+
warn: (msg, meta) => write("warn", msg, meta),
|
|
15
|
+
error: (msg, meta) => write("error", msg, meta),
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/security/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAInD,SAAS,KAAK,CAAC,KAAY,EAAE,GAAW,EAAE,IAAc;IACtD,MAAM,IAAI,GACR,IAAI,KAAK,SAAS;QAChB,CAAC,CAAC,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG,CAAC,EAAE;QACnC,CAAC,CAAC,IAAI,KAAK,KAAK,YAAY,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,GAAW,EAAE,IAAc,EAAE,EAAE;QACrC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK;YAAE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,EAAE,CAAC,GAAW,EAAE,IAAc,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/D,IAAI,EAAE,CAAC,GAAW,EAAE,IAAc,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;IAC/D,KAAK,EAAE,CAAC,GAAW,EAAE,IAAc,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;CAClE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const SENSITIVE_KEY_RE = /\b(password|pw|mk|ak|masterKey|rootKey|itemsKey|authKey|serverPassword|session|accessToken|refreshToken|jwt|authorization)\b/i;
|
|
2
|
+
const LONG_TOKEN_RE = /\b[A-Za-z0-9+/_-]{32,}={0,2}\b/g;
|
|
3
|
+
const MAX_DEPTH = 8;
|
|
4
|
+
export function redact(value, depth = 0) {
|
|
5
|
+
if (depth > MAX_DEPTH)
|
|
6
|
+
return "[depth-limit]";
|
|
7
|
+
if (value === null || value === undefined)
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
return value.replace(LONG_TOKEN_RE, "[REDACTED]");
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== "object")
|
|
13
|
+
return value;
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.map((v) => redact(v, depth + 1));
|
|
16
|
+
}
|
|
17
|
+
const out = {};
|
|
18
|
+
for (const [k, v] of Object.entries(value)) {
|
|
19
|
+
if (SENSITIVE_KEY_RE.test(k)) {
|
|
20
|
+
out[k] = "[REDACTED]";
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
out[k] = redact(v, depth + 1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
export function redactString(s) {
|
|
29
|
+
return s.replace(LONG_TOKEN_RE, "[REDACTED]");
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/security/redact.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GACpB,+HAA+H,CAAC;AAElI,MAAM,aAAa,GAAG,iCAAiC,CAAC;AAExD,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB,MAAM,UAAU,MAAM,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IAC9C,IAAI,KAAK,GAAG,SAAS;QAAE,OAAO,eAAe,CAAC;IAC9C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAExD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QACtE,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7B,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ToolError } from "../security/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Regex safety guard for user-supplied patterns in notes_replace_in.
|
|
4
|
+
* Two failure modes are rejected before the pattern ever runs:
|
|
5
|
+
* - oversized patterns (cap 1024 chars, same as the Obsidian MCP)
|
|
6
|
+
* - nested quantifiers like (a+)+ or (x*)* — catastrophic backtracking
|
|
7
|
+
* that can pin the event loop for minutes on a long note
|
|
8
|
+
* The nested-quantifier check is a heuristic (group containing a quantifier,
|
|
9
|
+
* itself quantified), not a full ReDoS analysis — conservative by design.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_REGEX_LENGTH = 1024;
|
|
12
|
+
const NESTED_QUANTIFIER = /\((?:[^()\\]|\\.)*[*+](?:[^()\\]|\\.)*\)\s*[*+{]|\)[*+]\s*[*+]|(?:^|[^\\])[*+]\s*[*+{]/;
|
|
13
|
+
export function assertSafeRegex(pattern) {
|
|
14
|
+
if (pattern.length > MAX_REGEX_LENGTH) {
|
|
15
|
+
throw new ToolError("regex_too_long", `Regex is ${pattern.length} chars; the limit is ${MAX_REGEX_LENGTH}.`, "Shorten the pattern or split the replacement into several simpler ones.");
|
|
16
|
+
}
|
|
17
|
+
if (NESTED_QUANTIFIER.test(pattern)) {
|
|
18
|
+
throw new ToolError("regex_unsafe", `Regex "${pattern}" contains nested quantifiers, which can hang the server (catastrophic backtracking).`, "Rewrite the pattern without a quantified group that itself contains + or *.");
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
new RegExp(pattern);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
throw new ToolError("regex_invalid", `Invalid regex: ${err instanceof Error ? err.message : String(err)}`, "Fix the pattern syntax and retry.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex.js","sourceRoot":"","sources":["../../src/security/regex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,iBAAiB,GACrB,wFAAwF,CAAC;AAE3F,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,OAAO,CAAC,MAAM,GAAG,gBAAgB,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CACjB,gBAAgB,EAChB,YAAY,OAAO,CAAC,MAAM,wBAAwB,gBAAgB,GAAG,EACrE,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,SAAS,CACjB,cAAc,EACd,UAAU,OAAO,uFAAuF,EACxG,6EAA6E,CAC9E,CAAC;IACJ,CAAC;IACD,IAAI,CAAC;QACH,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,SAAS,CACjB,eAAe,EACf,kBAAkB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EACpE,mCAAmC,CACpC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { logger } from "./security/logger.js";
|
|
5
|
+
import { isToolError } from "./security/errors.js";
|
|
6
|
+
import { loadConfig } from "./config.js";
|
|
7
|
+
import { createClientFromSession } from "./sn/client.js";
|
|
8
|
+
import { degradedFeatures } from "./sn/entitlement.js";
|
|
9
|
+
import { appendInput, createInput, createManyInput, deleteInput, deleteManyInput, frontmatterInput, getInput, listInput, registerNoteHandlers, replaceInInput, searchInput, statsInput, updateInput, updateManyInput, } from "./tools/notes.js";
|
|
10
|
+
import { registerTagHandlers, syncInput, tagsAttachInput, tagsCreateInput, tagsDeleteInput, tagsDetachInput, tagsGetInput, tagsListInput, tagsUpdateInput, } from "./tools/tags.js";
|
|
11
|
+
import { notesQueryInput, registerSmartViewHandlers, smartviewsListInput, smartviewsNotesInput, } from "./tools/smartviews.js";
|
|
12
|
+
import { dailyAppendInput, dailyListInput, periodicAppendInput, periodicListInput, registerDailyHandlers, } from "./tools/daily.js";
|
|
13
|
+
import { registerTaskHandlers, tasksInput, taskToggleInput, } from "./tools/tasks.js";
|
|
14
|
+
import { exportInput, registerExportHandlers } from "./tools/export.js";
|
|
15
|
+
import { historyInput, registerHistoryHandlers, revisionGetInput, revisionRestoreInput, } from "./tools/history.js";
|
|
16
|
+
import { linkInput, linksInput, registerLinkHandlers } from "./tools/links.js";
|
|
17
|
+
import { createFromTemplateInput, registerTemplateHandlers, templatesListInput, } from "./tools/templates.js";
|
|
18
|
+
function requiredEnv(name) {
|
|
19
|
+
const v = process.env[name];
|
|
20
|
+
if (!v)
|
|
21
|
+
throw new Error(`Missing required env var: ${name}`);
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
export async function startServer() {
|
|
25
|
+
const serverUrl = process.env.SN_SERVER_URL ?? "https://api.standardnotes.com";
|
|
26
|
+
const email = requiredEnv("SN_EMAIL");
|
|
27
|
+
const config = loadConfig();
|
|
28
|
+
const client = await createClientFromSession({
|
|
29
|
+
serverUrl,
|
|
30
|
+
email,
|
|
31
|
+
scope: config.scope,
|
|
32
|
+
governance: config.governance,
|
|
33
|
+
// Per-client governance identity: SN_CLIENT_NAME (operator-set, trusted)
|
|
34
|
+
// wins; otherwise fall back to the name the client reports at initialize.
|
|
35
|
+
// Read lazily — the handshake name only exists after connect.
|
|
36
|
+
clientName: () => config.clientName ?? server.server.getClientVersion()?.name ?? null,
|
|
37
|
+
});
|
|
38
|
+
const scoped = config.scope.readTags !== null || config.scope.denyTags.length > 0;
|
|
39
|
+
const plan = client.entitlement().plan;
|
|
40
|
+
const instructions = [
|
|
41
|
+
"Standard Notes MCP: end-to-end encrypted vault. All content is decrypted locally; the server only ever sees ciphertext.",
|
|
42
|
+
"Prefer notes_search to find notes before reading or editing; prefer notes_append / notes_replace_in over notes_update for targeted edits.",
|
|
43
|
+
config.readOnly
|
|
44
|
+
? "READ-ONLY mode is active: write tools are not available."
|
|
45
|
+
: null,
|
|
46
|
+
scoped
|
|
47
|
+
? "A tag-based read scope is active: notes and tags outside the scope are hidden and appear as not found."
|
|
48
|
+
: null,
|
|
49
|
+
config.deleteElicitation
|
|
50
|
+
? "Deletions require user confirmation via elicitation."
|
|
51
|
+
: null,
|
|
52
|
+
config.governance
|
|
53
|
+
? '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
|
+
: null,
|
|
55
|
+
plan === "paid"
|
|
56
|
+
? null
|
|
57
|
+
: "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.",
|
|
58
|
+
]
|
|
59
|
+
.filter((s) => s !== null)
|
|
60
|
+
.join(" ");
|
|
61
|
+
const server = new McpServer({
|
|
62
|
+
name: "StandardNotes-MCP",
|
|
63
|
+
version: "3.0.0",
|
|
64
|
+
}, { instructions });
|
|
65
|
+
const confirmDelete = config.deleteElicitation
|
|
66
|
+
? async (note) => {
|
|
67
|
+
try {
|
|
68
|
+
const res = await server.server.elicitInput({
|
|
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 });
|
|
96
|
+
const t = registerTagHandlers(client);
|
|
97
|
+
const sv = registerSmartViewHandlers(client);
|
|
98
|
+
const d = registerDailyHandlers(client, config.periodicTag);
|
|
99
|
+
const tk = registerTaskHandlers(client);
|
|
100
|
+
const hist = registerHistoryHandlers(client);
|
|
101
|
+
const lk = registerLinkHandlers(client);
|
|
102
|
+
const tpl = registerTemplateHandlers(client, config.templatesTag);
|
|
103
|
+
// In read-only mode, write tools are not registered at all — they don't
|
|
104
|
+
// appear in tools/list, so the agent never tries them.
|
|
105
|
+
const WRITE_TOOLS = new Set([
|
|
106
|
+
"notes_create",
|
|
107
|
+
"notes_create_many",
|
|
108
|
+
"notes_update",
|
|
109
|
+
"notes_update_many",
|
|
110
|
+
"notes_append",
|
|
111
|
+
"notes_replace_in",
|
|
112
|
+
"notes_delete",
|
|
113
|
+
"notes_delete_many",
|
|
114
|
+
"notes_frontmatter",
|
|
115
|
+
"daily_append",
|
|
116
|
+
"periodic_append",
|
|
117
|
+
"notes_task_toggle",
|
|
118
|
+
"notes_revision_restore",
|
|
119
|
+
"notes_link",
|
|
120
|
+
"notes_create_from_template",
|
|
121
|
+
"tags_create",
|
|
122
|
+
"tags_update",
|
|
123
|
+
"tags_delete",
|
|
124
|
+
"tags_attach",
|
|
125
|
+
"tags_detach",
|
|
126
|
+
]);
|
|
127
|
+
const registerTool = (name, description, shape, handler) => {
|
|
128
|
+
if (config.readOnly && WRITE_TOOLS.has(name))
|
|
129
|
+
return;
|
|
130
|
+
server.tool(name, description, shape, handler);
|
|
131
|
+
};
|
|
132
|
+
const wrap = (fn) => async (args) => {
|
|
133
|
+
try {
|
|
134
|
+
const result = await fn(args);
|
|
135
|
+
return {
|
|
136
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
// ToolErrors carry a machine-readable reason + recovery hint so the
|
|
141
|
+
// agent can self-correct instead of retrying the same call blindly.
|
|
142
|
+
if (isToolError(err)) {
|
|
143
|
+
return {
|
|
144
|
+
isError: true,
|
|
145
|
+
content: [
|
|
146
|
+
{
|
|
147
|
+
type: "text",
|
|
148
|
+
text: JSON.stringify({
|
|
149
|
+
reason: err.reason,
|
|
150
|
+
message: err.message,
|
|
151
|
+
recoveryHint: err.recoveryHint,
|
|
152
|
+
}, null, 2),
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
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));
|
|
161
|
+
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));
|
|
162
|
+
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));
|
|
163
|
+
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));
|
|
164
|
+
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));
|
|
165
|
+
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));
|
|
166
|
+
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));
|
|
167
|
+
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));
|
|
168
|
+
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));
|
|
169
|
+
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));
|
|
170
|
+
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));
|
|
171
|
+
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));
|
|
172
|
+
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));
|
|
173
|
+
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));
|
|
174
|
+
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));
|
|
175
|
+
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));
|
|
176
|
+
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));
|
|
177
|
+
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));
|
|
178
|
+
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));
|
|
179
|
+
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));
|
|
180
|
+
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));
|
|
181
|
+
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));
|
|
182
|
+
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));
|
|
183
|
+
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));
|
|
184
|
+
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));
|
|
185
|
+
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));
|
|
186
|
+
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));
|
|
187
|
+
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));
|
|
188
|
+
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));
|
|
189
|
+
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));
|
|
190
|
+
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));
|
|
191
|
+
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));
|
|
192
|
+
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));
|
|
193
|
+
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));
|
|
194
|
+
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));
|
|
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));
|
|
197
|
+
/** Shared by the server_status tool and the sn://status resource. */
|
|
198
|
+
const statusPayload = async () => {
|
|
199
|
+
const stats = await client.stats();
|
|
200
|
+
const policy = {
|
|
201
|
+
clientIdentity: config.clientName ??
|
|
202
|
+
server.server.getClientVersion()?.name ??
|
|
203
|
+
null,
|
|
204
|
+
readOnly: config.readOnly,
|
|
205
|
+
tagScope: config.scope.readTags !== null || config.scope.denyTags.length > 0
|
|
206
|
+
? config.scope
|
|
207
|
+
: null,
|
|
208
|
+
deleteElicitation: config.deleteElicitation,
|
|
209
|
+
};
|
|
210
|
+
const ent = client.entitlement();
|
|
211
|
+
return {
|
|
212
|
+
...stats,
|
|
213
|
+
policy,
|
|
214
|
+
plan: {
|
|
215
|
+
standardNotes: ent.plan,
|
|
216
|
+
degradedFeatures: degradedFeatures(ent),
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
// Many clients (Lumo, for one) expose tools but not resources, so the
|
|
221
|
+
// sn://status data is also available as a tool.
|
|
222
|
+
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()));
|
|
223
|
+
// vault_export writes DECRYPTED notes to disk — only registered when the
|
|
224
|
+
// operator opted in with SN_ALLOW_EXPORT.
|
|
225
|
+
if (config.allowExport) {
|
|
226
|
+
const x = registerExportHandlers(client, config.exportDir);
|
|
227
|
+
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
|
+
}
|
|
229
|
+
server.resource("tags", "sn://tags", { description: "Every tag with its note count — uncapped snapshot of the folder structure" }, async (uri) => ({
|
|
230
|
+
contents: [
|
|
231
|
+
{
|
|
232
|
+
uri: uri.href,
|
|
233
|
+
mimeType: "application/json",
|
|
234
|
+
text: JSON.stringify(await client.listTags(), null, 2),
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
}));
|
|
238
|
+
server.resource("status", "sn://status", { description: "Sync state, cache age, decrypt failures, and the active server policy" }, async (uri) => ({
|
|
239
|
+
contents: [
|
|
240
|
+
{
|
|
241
|
+
uri: uri.href,
|
|
242
|
+
mimeType: "application/json",
|
|
243
|
+
text: JSON.stringify(await statusPayload(), null, 2),
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
}));
|
|
247
|
+
server.resource("note", new ResourceTemplate("sn://notes/{uuid}", { list: undefined }), { description: "Full note by uuid (same shape as notes_get format=full)" }, async (uri, variables) => {
|
|
248
|
+
const uuid = String(variables.uuid);
|
|
249
|
+
const note = await client.getNote(uuid);
|
|
250
|
+
if (!note)
|
|
251
|
+
throw new Error(`Note ${uuid} not found`);
|
|
252
|
+
return {
|
|
253
|
+
contents: [
|
|
254
|
+
{
|
|
255
|
+
uri: uri.href,
|
|
256
|
+
mimeType: "application/json",
|
|
257
|
+
text: JSON.stringify(note, null, 2),
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
server.prompt("summarize-note", "Summarize one note concisely, main points and action items first. Arg: uuid of the note.", { uuid: z.string().uuid() }, ({ uuid }) => ({
|
|
263
|
+
messages: [
|
|
264
|
+
{
|
|
265
|
+
role: "user",
|
|
266
|
+
content: {
|
|
267
|
+
type: "text",
|
|
268
|
+
text: `Use the notes_get tool (format=full) to read the note with uuid ${uuid}, then give me a concise summary: main points first, then any action items it contains. Do not modify the note.`,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
}));
|
|
273
|
+
server.prompt("weekly-review", "Review the notes changed in the last 7 days and draft a weekly summary note.", {}, async () => {
|
|
274
|
+
const cutoff = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
|
275
|
+
const recent = (await client.listNotes({
|
|
276
|
+
limit: 200,
|
|
277
|
+
offset: 0,
|
|
278
|
+
includeTrashed: false,
|
|
279
|
+
})).filter((n) => Date.parse(n.updatedAt) >= cutoff);
|
|
280
|
+
const listing = recent
|
|
281
|
+
.map((n) => `- ${n.title} (${n.uuid}, updated ${n.updatedAt})`)
|
|
282
|
+
.join("\n") || "(no notes changed in the last 7 days)";
|
|
283
|
+
return {
|
|
284
|
+
messages: [
|
|
285
|
+
{
|
|
286
|
+
role: "user",
|
|
287
|
+
content: {
|
|
288
|
+
type: "text",
|
|
289
|
+
text: `These notes changed in the last 7 days:\n${listing}\n\nRead each one with notes_get, then create a new note titled "Weekly review — ${new Date().toISOString().slice(0, 10)}" summarizing the week, grouped by theme, referencing each source note by title.`,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
server.prompt("inbox-triage", "Find untagged notes and suggest which existing tags (folders) they belong in.", {}, async () => {
|
|
296
|
+
const [notes, tags] = await Promise.all([
|
|
297
|
+
client.listNotes({ limit: 200, offset: 0, includeTrashed: false }),
|
|
298
|
+
client.listTags(),
|
|
299
|
+
]);
|
|
300
|
+
const tagged = new Set();
|
|
301
|
+
for (const t of tags) {
|
|
302
|
+
const full = await client.getTag(t.uuid);
|
|
303
|
+
for (const id of full?.noteUuids ?? [])
|
|
304
|
+
tagged.add(id);
|
|
305
|
+
}
|
|
306
|
+
const untagged = notes.filter((n) => !tagged.has(n.uuid));
|
|
307
|
+
const listing = untagged
|
|
308
|
+
.map((n) => `- ${n.title} (${n.uuid}): ${n.preview.slice(0, 80)}`)
|
|
309
|
+
.join("\n") || "(every note is tagged)";
|
|
310
|
+
const tagNames = tags.map((t) => t.title).join(", ") || "(none yet)";
|
|
311
|
+
return {
|
|
312
|
+
messages: [
|
|
313
|
+
{
|
|
314
|
+
role: "user",
|
|
315
|
+
content: {
|
|
316
|
+
type: "text",
|
|
317
|
+
text: `Untagged notes:\n${listing}\n\nExisting tags: ${tagNames}.\n\nFor each untagged note, suggest which existing tag(s) fit — or propose a new tag name when none do. Show me the proposed mapping and wait for my confirmation before calling tags_attach for anything.`,
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
const transport = new StdioServerTransport();
|
|
324
|
+
await server.connect(transport);
|
|
325
|
+
logger.info("MCP StandardNotes ready on stdio");
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAA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AAE;gBACR;oBACE,IAAI,EAAE,MAAe;oBACrB,OAAO,EAAE;wBACP,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,oBAAoB,OAAO,sBAAsB,QAAQ,6MAA6M;qBAC7Q;iBACF;aACF;SACF,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/sn/cache.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local vault cache staleness policy.
|
|
3
|
+
*
|
|
4
|
+
* The SN client keeps decrypted notes/tags in memory and, historically,
|
|
5
|
+
* only did a fullSync at process startup. When two long-running instances
|
|
6
|
+
* of the server target the same account (e.g. a local CLI lane + a
|
|
7
|
+
* remote Hermes lane), each is blind to the other's writes and can even
|
|
8
|
+
* overwrite a newer revision with a stale one — see
|
|
9
|
+
* `intakes/mcp-standardnotes-cache-staleness.md`.
|
|
10
|
+
*
|
|
11
|
+
* `ensureFresh` is the single choke-point that decides "do I need to
|
|
12
|
+
* refresh the cache before serving this call?" — TTL for reads, forced
|
|
13
|
+
* for writes.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_CACHE_TTL_MS = 30_000;
|
|
16
|
+
/**
|
|
17
|
+
* TTL (ms) used by read-side ensureFresh calls. Overridable via
|
|
18
|
+
* `SN_CACHE_TTL_MS`. Special values:
|
|
19
|
+
* 0 → refresh before every read (strict, one extra roundtrip per call)
|
|
20
|
+
* -1 → never refresh (legacy "sync only at boot" behavior, kept as an
|
|
21
|
+
* emergency rollback lever)
|
|
22
|
+
*
|
|
23
|
+
* A non-numeric value falls back to the default rather than throwing,
|
|
24
|
+
* to keep boot resilient to a fat-fingered env var.
|
|
25
|
+
*/
|
|
26
|
+
export function cacheTtlMs() {
|
|
27
|
+
const raw = process.env.SN_CACHE_TTL_MS;
|
|
28
|
+
if (raw === undefined || raw === "")
|
|
29
|
+
return DEFAULT_CACHE_TTL_MS;
|
|
30
|
+
const n = Number(raw);
|
|
31
|
+
return Number.isFinite(n) ? n : DEFAULT_CACHE_TTL_MS;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Trigger `refresh()` if the cache is older than maxAgeMs. Semantics:
|
|
35
|
+
* maxAgeMs < 0 → never refresh (caller opt-out)
|
|
36
|
+
* maxAgeMs == 0 → always refresh (caller wants unconditional freshness,
|
|
37
|
+
* e.g. before a write)
|
|
38
|
+
* maxAgeMs > 0 → refresh only when `now - lastSyncAt > maxAgeMs`
|
|
39
|
+
*
|
|
40
|
+
* The function does NOT set `lastSyncAt` itself — that's `refresh()`'s
|
|
41
|
+
* job (it typically calls the full sync routine, which owns the state
|
|
42
|
+
* and updates it once the sync succeeds). This split keeps `ensureFresh`
|
|
43
|
+
* testable without pulling in the whole client machinery.
|
|
44
|
+
*/
|
|
45
|
+
export async function ensureFresh(state, maxAgeMs, refresh) {
|
|
46
|
+
if (maxAgeMs < 0)
|
|
47
|
+
return;
|
|
48
|
+
const ageMs = Date.now() - state.lastSyncAt;
|
|
49
|
+
if (maxAgeMs === 0 || ageMs > maxAgeMs) {
|
|
50
|
+
await refresh();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/sn/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IACxC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,oBAAoB,CAAC;IACjE,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACvD,CAAC;AAOD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAgB,EAChB,QAAgB,EAChB,OAA4B;IAE5B,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO;IACzB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC;IAC5C,IAAI,QAAQ,KAAK,CAAC,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;QACvC,MAAM,OAAO,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
|