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,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folder-scope answers in setup: turning what the user typed into the
|
|
3
|
+
* SN_READ_TAGS value written to an AI client's config. Kept free of I/O so
|
|
4
|
+
* it can be tested on its own.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @param input what the user typed
|
|
8
|
+
* @param known folder titles in the vault, or null when they couldn't
|
|
9
|
+
* be read (then names are accepted as typed)
|
|
10
|
+
* @param hasCurrent whether the client already has a folder scope, which
|
|
11
|
+
* makes Enter mean "keep it" instead of "whole vault"
|
|
12
|
+
*/
|
|
13
|
+
export function parseFolderAnswer(input, known, hasCurrent) {
|
|
14
|
+
const trimmed = input.trim();
|
|
15
|
+
if (trimmed === "")
|
|
16
|
+
return hasCurrent ? { kind: "keep" } : { kind: "all" };
|
|
17
|
+
if (trimmed.toLowerCase() === "all")
|
|
18
|
+
return { kind: "all" };
|
|
19
|
+
const names = trimmed
|
|
20
|
+
.split(",")
|
|
21
|
+
.map((s) => s.trim())
|
|
22
|
+
.filter((s) => s !== "");
|
|
23
|
+
if (names.length === 0)
|
|
24
|
+
return hasCurrent ? { kind: "keep" } : { kind: "all" };
|
|
25
|
+
if (known === null)
|
|
26
|
+
return { kind: "folders", folders: dedupe(names) };
|
|
27
|
+
const unknown = [];
|
|
28
|
+
const folders = [];
|
|
29
|
+
for (const name of names) {
|
|
30
|
+
// Same rule the server uses: case-insensitive title match.
|
|
31
|
+
const match = known.find((k) => k.toLowerCase() === name.toLowerCase());
|
|
32
|
+
if (match === undefined)
|
|
33
|
+
unknown.push(name);
|
|
34
|
+
else
|
|
35
|
+
folders.push(match);
|
|
36
|
+
}
|
|
37
|
+
if (unknown.length > 0)
|
|
38
|
+
return { kind: "unknown", names: unknown };
|
|
39
|
+
return { kind: "folders", folders: dedupe(folders) };
|
|
40
|
+
}
|
|
41
|
+
function dedupe(names) {
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
return names.filter((n) => {
|
|
44
|
+
const k = n.toLowerCase();
|
|
45
|
+
if (seen.has(k))
|
|
46
|
+
return false;
|
|
47
|
+
seen.add(k);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Folder titles to show as a hint, sorted and de-duplicated; titles with a
|
|
53
|
+
* comma are left out because SN_READ_TAGS is comma-separated and can't
|
|
54
|
+
* hold them. Long lists are cut to `max` with a count of the rest.
|
|
55
|
+
*/
|
|
56
|
+
export function folderHint(known, max = 40) {
|
|
57
|
+
const titles = [...new Set(known.filter((t) => t.trim() !== "" && !t.includes(",")))].sort((a, b) => a.localeCompare(b, undefined, { sensitivity: "base" }));
|
|
58
|
+
if (titles.length === 0)
|
|
59
|
+
return "(no tags yet)";
|
|
60
|
+
const shown = titles.slice(0, max).join(", ");
|
|
61
|
+
return titles.length > max ? `${shown} (+${titles.length - max} more)` : shown;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=folders.js.map
|
package/dist/cli/install.js
CHANGED
|
@@ -6,6 +6,8 @@ import { dirname, join, resolve } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import readline from "node:readline";
|
|
8
8
|
import { storedAccounts } from "../sn/session.js";
|
|
9
|
+
import { isMainModule } from "./isMain.js";
|
|
10
|
+
import { claudeCodeAddArgs, shellQuote } from "./clients.js";
|
|
9
11
|
/** Config key for this server in MCP client configs (renamed in 3.0.0). */
|
|
10
12
|
export const SERVER_KEY = "standardnotes-mcp";
|
|
11
13
|
const LEGACY_SERVER_KEY = "mcp-standardnotes";
|
|
@@ -83,11 +85,21 @@ export async function pickEmail() {
|
|
|
83
85
|
throw new Error(`Invalid selection: ${answer}`);
|
|
84
86
|
return choice;
|
|
85
87
|
}
|
|
86
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Env keys setup owns. On re-install these come only from the new entry
|
|
90
|
+
* (SN_READ_TAGS is removed when the new scope is the whole vault); every
|
|
91
|
+
* other key already in the client's config, such as a hand-added
|
|
92
|
+
* SN_DENY_TAGS or SN_READ_ONLY, is kept.
|
|
93
|
+
*/
|
|
94
|
+
export const MANAGED_ENV_KEYS = ["SN_EMAIL", "SN_CLIENT_NAME", "SN_READ_TAGS"];
|
|
95
|
+
export function buildEntry(paths, email, clientName, readTags) {
|
|
87
96
|
const env = { SN_EMAIL: email };
|
|
88
97
|
if (clientName !== undefined && clientName !== "") {
|
|
89
98
|
env.SN_CLIENT_NAME = clientName;
|
|
90
99
|
}
|
|
100
|
+
if (readTags !== undefined && readTags.length > 0) {
|
|
101
|
+
env.SN_READ_TAGS = readTags.join(",");
|
|
102
|
+
}
|
|
91
103
|
return {
|
|
92
104
|
command: paths.node,
|
|
93
105
|
args: [paths.server],
|
|
@@ -98,16 +110,56 @@ export function buildEntry(paths, email, clientName) {
|
|
|
98
110
|
export function cursorConfigPath() {
|
|
99
111
|
return join(homedir(), ".cursor", "mcp.json");
|
|
100
112
|
}
|
|
113
|
+
function envOf(entry) {
|
|
114
|
+
if (typeof entry !== "object" || entry === null)
|
|
115
|
+
return {};
|
|
116
|
+
const env = entry.env;
|
|
117
|
+
if (typeof env !== "object" || env === null)
|
|
118
|
+
return {};
|
|
119
|
+
const out = {};
|
|
120
|
+
for (const [k, v] of Object.entries(env)) {
|
|
121
|
+
if (typeof v === "string")
|
|
122
|
+
out[k] = v;
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The env of this server's existing entry in an mcpServers-style config
|
|
128
|
+
* (current key, else the pre-3.0.0 one), or null when there is none or the
|
|
129
|
+
* file can't be read. Used to offer the current folder scope as the default.
|
|
130
|
+
*/
|
|
131
|
+
export async function existingServerEnv(configPath) {
|
|
132
|
+
try {
|
|
133
|
+
const config = await readJsonOrEmpty(configPath);
|
|
134
|
+
const servers = config.mcpServers;
|
|
135
|
+
if (!servers)
|
|
136
|
+
return null;
|
|
137
|
+
const entry = servers[SERVER_KEY] ?? servers[LEGACY_SERVER_KEY];
|
|
138
|
+
return entry === undefined ? null : envOf(entry);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
101
144
|
/** Merge a server entry into any mcpServers-style JSON config file. */
|
|
102
145
|
export async function installJsonConfig(opts) {
|
|
103
146
|
await mkdir(dirname(opts.configPath), { recursive: true });
|
|
104
147
|
const backup = await backupOnce(opts.configPath);
|
|
105
148
|
const config = await readJsonOrEmpty(opts.configPath);
|
|
106
149
|
const servers = config.mcpServers ?? {};
|
|
150
|
+
const key = opts.serverKey ?? SERVER_KEY;
|
|
151
|
+
// Keep env settings setup doesn't manage (SN_DENY_TAGS, SN_READ_ONLY, ...)
|
|
152
|
+
// from the existing entry, so re-running setup never silently drops them.
|
|
153
|
+
const previousEnv = {
|
|
154
|
+
...(!opts.serverKey ? envOf(servers[LEGACY_SERVER_KEY]) : {}),
|
|
155
|
+
...envOf(servers[key]),
|
|
156
|
+
};
|
|
157
|
+
for (const k of MANAGED_ENV_KEYS)
|
|
158
|
+
delete previousEnv[k];
|
|
107
159
|
// Replace the pre-3.0.0 key rather than leaving a duplicate server.
|
|
108
160
|
if (!opts.serverKey)
|
|
109
161
|
delete servers[LEGACY_SERVER_KEY];
|
|
110
|
-
servers[opts.
|
|
162
|
+
servers[key] = { ...opts.entry, env: { ...previousEnv, ...opts.entry.env } };
|
|
111
163
|
config.mcpServers = servers;
|
|
112
164
|
await writeFile(opts.configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
113
165
|
return { configPath: opts.configPath, backup };
|
|
@@ -115,15 +167,13 @@ export async function installJsonConfig(opts) {
|
|
|
115
167
|
export async function installDesktop(opts) {
|
|
116
168
|
return installJsonConfig({
|
|
117
169
|
configPath: opts.configPath ?? desktopConfigPath(),
|
|
118
|
-
entry: buildEntry(opts.paths, opts.email, opts.clientName),
|
|
170
|
+
entry: buildEntry(opts.paths, opts.email, opts.clientName, opts.readTags),
|
|
119
171
|
});
|
|
120
172
|
}
|
|
121
|
-
export async function printCodeInstructions(paths, email, clientName) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
process.stdout.write("For Claude Code, run this command (it shells out to the `claude` CLI):\n\n");
|
|
126
|
-
process.stdout.write(` claude mcp add standardnotes-mcp "${paths.node}" "${paths.server}" --env SN_EMAIL=${email}${nameEnv}\n\n`);
|
|
173
|
+
export async function printCodeInstructions(paths, email, clientName, readTags) {
|
|
174
|
+
const args = claudeCodeAddArgs(paths, buildEntry(paths, email, clientName, readTags).env);
|
|
175
|
+
process.stdout.write("For Claude Code, run this command (it uses the `claude` CLI):\n\n");
|
|
176
|
+
process.stdout.write(` claude ${args.map(shellQuote).join(" ")}\n\n`);
|
|
127
177
|
process.stdout.write("If you don't have the `claude` CLI installed, add the same JSON entry manually to ~/.claude.json under `mcpServers`.\n");
|
|
128
178
|
}
|
|
129
179
|
function parseTargets(argv) {
|
|
@@ -170,15 +220,7 @@ async function main() {
|
|
|
170
220
|
}
|
|
171
221
|
}
|
|
172
222
|
// Don't auto-run when imported (e.g. from login.ts or tests).
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
return fileURLToPath(import.meta.url) === resolve(process.argv[1] ?? "");
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
})();
|
|
181
|
-
if (isMain) {
|
|
223
|
+
if (isMainModule(import.meta.url)) {
|
|
182
224
|
main().catch((err) => {
|
|
183
225
|
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
184
226
|
process.exit(1);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
/**
|
|
4
|
+
* True when the module at `metaUrl` is the script node was started with.
|
|
5
|
+
*
|
|
6
|
+
* Compares real paths, because npm installs global commands on macOS and
|
|
7
|
+
* Linux as symlinks named after the command (e.g. `standardnotes-mcp-login`
|
|
8
|
+
* -> dist/cli/login.js), so `process.argv[1]` is the link, not the file.
|
|
9
|
+
*/
|
|
10
|
+
export function isMainModule(metaUrl) {
|
|
11
|
+
const entry = process.argv[1];
|
|
12
|
+
if (!entry)
|
|
13
|
+
return false;
|
|
14
|
+
try {
|
|
15
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(metaUrl));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=isMain.js.map
|
package/dist/cli/login.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import readline from "node:readline";
|
|
3
3
|
import { logger } from "../security/logger.js";
|
|
4
4
|
import { createClientFromLogin } from "../sn/client.js";
|
|
5
|
+
import { isMainModule } from "./isMain.js";
|
|
5
6
|
const CTRL_C = "\u0003";
|
|
6
7
|
const DEL = "";
|
|
7
8
|
function promptVisible(question) {
|
|
@@ -104,18 +105,20 @@ export async function runLogin() {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
// Don't auto-run when imported (e.g. from setup.ts).
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
// Run directly, login continues into the guided setup (name each AI client,
|
|
109
|
+
// write or print its MCP settings), so a new install needs this one command.
|
|
110
|
+
// Skipped with --no-setup or when stdin isn't a terminal (scripts).
|
|
111
|
+
if (isMainModule(import.meta.url)) {
|
|
112
|
+
(async () => {
|
|
113
|
+
const email = await runLogin();
|
|
114
|
+
if (process.argv.includes("--no-setup") || process.stdin.isTTY !== true) {
|
|
115
|
+
process.stdout.write("Run `standardnotes-mcp-setup` to connect your AI clients.\n");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
process.stdout.write("\nNext: connect your AI clients.\n");
|
|
119
|
+
const { runSetup } = await import("./setup.js");
|
|
120
|
+
await runSetup({ email });
|
|
121
|
+
})().catch((err) => {
|
|
119
122
|
// "Login failed" was already logged with its cause chain above.
|
|
120
123
|
if (err instanceof Error && err.message !== "Login failed") {
|
|
121
124
|
process.stderr.write(`${err.message}\n`);
|
package/dist/cli/logout.js
CHANGED
|
@@ -3,7 +3,7 @@ import { deleteSession } from "../sn/session.js";
|
|
|
3
3
|
async function main() {
|
|
4
4
|
const email = process.env.SN_EMAIL ?? process.argv[2];
|
|
5
5
|
if (!email) {
|
|
6
|
-
console.error("Usage:
|
|
6
|
+
console.error("Usage: standardnotes-mcp-logout <email> (or set SN_EMAIL; from a source checkout: npm run logout -- <email>)");
|
|
7
7
|
process.exit(2);
|
|
8
8
|
}
|
|
9
9
|
const removed = await deleteSession(email);
|
package/dist/cli/setup.js
CHANGED
|
@@ -1,23 +1,81 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import readline from "node:readline";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
-
import { buildEntry, cursorConfigPath, installDesktop, installJsonConfig, pickEmail, printCodeInstructions, resolvePaths, storedSessionEmails, } from "./install.js";
|
|
4
|
+
import { buildEntry, cursorConfigPath, desktopConfigPath, existingServerEnv, installDesktop, installJsonConfig, pickEmail, printCodeInstructions, resolvePaths, storedSessionEmails, } from "./install.js";
|
|
5
5
|
import { runLogin } from "./login.js";
|
|
6
|
+
import { folderHint, parseFolderAnswer } from "./folders.js";
|
|
7
|
+
import { claudeCodeAddArgs, lumoFormText, detectInstalled, parseSelection, realProbes, runClaude, } from "./clients.js";
|
|
8
|
+
import { createClientFromSession } from "../sn/client.js";
|
|
9
|
+
import { isMainModule } from "./isMain.js";
|
|
6
10
|
const CHOICES = [
|
|
7
11
|
{ label: "Claude (Desktop app)", defaultName: "claude", wiring: "claude-desktop" },
|
|
8
12
|
{ label: "Claude Code (CLI)", defaultName: "claude", wiring: "claude-code" },
|
|
9
13
|
{ label: "ChatGPT", defaultName: "chatgpt", wiring: "manual" },
|
|
10
14
|
{ label: "Kimi Code (CLI)", defaultName: "kimi", wiring: "manual" },
|
|
11
|
-
{ label: "Lumo (Proton)", defaultName: "lumo", wiring: "
|
|
15
|
+
{ label: "Lumo (Proton)", defaultName: "lumo", wiring: "lumo" },
|
|
12
16
|
{ label: "Cursor", defaultName: "cursor", wiring: "cursor" },
|
|
13
17
|
{ label: "Other (enter a name)", defaultName: "", wiring: "manual" },
|
|
14
18
|
];
|
|
15
|
-
|
|
19
|
+
/** Config file setup writes for this client, when it writes one. */
|
|
20
|
+
function configFileFor(choice) {
|
|
21
|
+
try {
|
|
22
|
+
if (choice.wiring === "claude-desktop")
|
|
23
|
+
return desktopConfigPath();
|
|
24
|
+
if (choice.wiring === "cursor")
|
|
25
|
+
return cursorConfigPath();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Claude Desktop doesn't exist on this platform.
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Folder titles in the vault, for checking what the user types. Reads the
|
|
34
|
+
* vault with the stored session (the same full sync the server does at
|
|
35
|
+
* start). null when that fails; names are then accepted unchecked.
|
|
36
|
+
*/
|
|
37
|
+
async function loadFolderTitles(email) {
|
|
38
|
+
process.stdout.write("\nReading your tags from Standard Notes...\n");
|
|
39
|
+
try {
|
|
40
|
+
const client = await createClientFromSession({
|
|
41
|
+
serverUrl: process.env.SN_SERVER_URL ?? "https://api.standardnotes.com",
|
|
42
|
+
email,
|
|
43
|
+
});
|
|
44
|
+
return (await client.listTags()).map((t) => t.title);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
process.stdout.write(` Couldn't read your tags (${err instanceof Error ? err.message : String(err)}),\n` +
|
|
48
|
+
" so tag names you enter won't be checked. Type them exactly as in Standard Notes.\n");
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Adds the server to Claude Code with its own CLI, for every project
|
|
54
|
+
* (--scope user). An existing entry with this name is replaced, as setup
|
|
55
|
+
* does for Claude Desktop. Returns false when it couldn't, after saying why;
|
|
56
|
+
* the caller then prints the command to run by hand.
|
|
57
|
+
*/
|
|
58
|
+
function addToClaudeCode(paths, env) {
|
|
59
|
+
const args = claudeCodeAddArgs(paths, env);
|
|
60
|
+
let res = runClaude(args);
|
|
61
|
+
if (!res.ok && /already exists/i.test(res.output)) {
|
|
62
|
+
runClaude(["mcp", "remove", "--scope", "user", "standardnotes-mcp"]);
|
|
63
|
+
res = runClaude(args);
|
|
64
|
+
}
|
|
65
|
+
if (res.ok) {
|
|
66
|
+
process.stdout.write(" Added to Claude Code (all projects). Restart any open Claude Code sessions.\n");
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
process.stdout.write(` Couldn't add it automatically${res.output ? `: ${res.output}` : ""}\n`);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
async function wire(choice, clientName, email, paths, readTags) {
|
|
16
73
|
if (choice.wiring === "claude-desktop") {
|
|
17
74
|
const { configPath, backup } = await installDesktop({
|
|
18
75
|
email,
|
|
19
76
|
paths,
|
|
20
77
|
clientName,
|
|
78
|
+
readTags,
|
|
21
79
|
});
|
|
22
80
|
process.stdout.write(` Updated Claude Desktop config at ${configPath}\n`);
|
|
23
81
|
if (backup)
|
|
@@ -28,7 +86,7 @@ async function wire(choice, clientName, email, paths) {
|
|
|
28
86
|
if (choice.wiring === "cursor") {
|
|
29
87
|
const { configPath, backup } = await installJsonConfig({
|
|
30
88
|
configPath: cursorConfigPath(),
|
|
31
|
-
entry: buildEntry(paths, email, clientName),
|
|
89
|
+
entry: buildEntry(paths, email, clientName, readTags),
|
|
32
90
|
});
|
|
33
91
|
process.stdout.write(` Updated Cursor config at ${configPath}\n`);
|
|
34
92
|
if (backup)
|
|
@@ -37,29 +95,44 @@ async function wire(choice, clientName, email, paths) {
|
|
|
37
95
|
return;
|
|
38
96
|
}
|
|
39
97
|
if (choice.wiring === "claude-code") {
|
|
40
|
-
await printCodeInstructions(paths, email, clientName);
|
|
98
|
+
await printCodeInstructions(paths, email, clientName, readTags);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (choice.wiring === "lumo") {
|
|
102
|
+
// Lumo's settings are a form, not a JSON file: print field by field.
|
|
103
|
+
// Values start at the left edge so a copied value carries no indent.
|
|
104
|
+
process.stdout.write(lumoFormText(buildEntry(paths, email, clientName, readTags)));
|
|
41
105
|
return;
|
|
42
106
|
}
|
|
43
107
|
// manual: print a ready-to-paste snippet
|
|
44
108
|
process.stdout.write(` Add this to ${choice.label}'s MCP server config:\n\n`);
|
|
45
|
-
process.stdout.write(JSON.stringify({ mcpServers: { "standardnotes-mcp": buildEntry(paths, email, clientName) } }, null, 2) + "\n\n");
|
|
109
|
+
process.stdout.write(JSON.stringify({ mcpServers: { "standardnotes-mcp": buildEntry(paths, email, clientName, readTags) } }, null, 2) + "\n\n");
|
|
46
110
|
}
|
|
47
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Runs the guided setup. With `email` (just logged in by
|
|
113
|
+
* standardnotes-mcp-login) it skips the account step and goes straight to
|
|
114
|
+
* connecting AI clients.
|
|
115
|
+
*/
|
|
116
|
+
export async function runSetup(opts = {}) {
|
|
48
117
|
const paths = resolvePaths();
|
|
49
118
|
if (!existsSync(paths.server)) {
|
|
50
|
-
throw new Error(`Server entrypoint not found at ${paths.server}.
|
|
119
|
+
throw new Error(`Server entrypoint not found at ${paths.server}. ` +
|
|
120
|
+
"In a source checkout run `npm run build` first; otherwise reinstall: `npm install -g standardnotes-mcp`.");
|
|
51
121
|
}
|
|
52
122
|
if (process.stdin.isTTY !== true) {
|
|
53
123
|
process.stdout.write("Note: stdin is not a terminal, so line editing (backspace) may not work.\n" +
|
|
54
|
-
"For a fully interactive run
|
|
124
|
+
"For a fully interactive run, start `standardnotes-mcp-setup` directly in a terminal.\n\n");
|
|
55
125
|
}
|
|
56
126
|
// Resolve the account before opening the readline UI below: the login
|
|
57
127
|
// flow uses its own stdin handling, so it must run before this
|
|
58
128
|
// interface exists.
|
|
59
|
-
const stored = await storedSessionEmails();
|
|
129
|
+
const stored = opts.email !== undefined ? [] : await storedSessionEmails();
|
|
60
130
|
const envEmail = process.env.SN_EMAIL;
|
|
61
131
|
let email;
|
|
62
|
-
if (
|
|
132
|
+
if (opts.email !== undefined) {
|
|
133
|
+
email = opts.email;
|
|
134
|
+
}
|
|
135
|
+
else if (stored.length === 0 ||
|
|
63
136
|
(envEmail !== undefined && !stored.includes(envEmail))) {
|
|
64
137
|
process.stdout.write(stored.length === 0
|
|
65
138
|
? "No stored Standard Notes session — logging in first.\n\n"
|
|
@@ -107,92 +180,115 @@ async function main() {
|
|
|
107
180
|
});
|
|
108
181
|
};
|
|
109
182
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.map((
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
183
|
+
const found = detectInstalled(realProbes(desktopConfigPath));
|
|
184
|
+
const detected = CHOICES.flatMap((c, i) => c.wiring !== "lumo" && c.wiring !== "manual" && found.has(c.wiring) ? [i] : []);
|
|
185
|
+
process.stdout.write("\nWhich AI apps should use Standard Notes?\n");
|
|
186
|
+
CHOICES.forEach((c, i) => process.stdout.write(` [${i + 1}] ${c.label}${detected.includes(i) ? " (found on this computer)" : ""}\n`));
|
|
187
|
+
process.stdout.write(detected.length > 0
|
|
188
|
+
? `Enter numbers separated by commas, or press Enter for the apps found (${detected.map((i) => i + 1).join(", ")}). Type 0 to skip.\n`
|
|
189
|
+
: "Enter numbers separated by commas, e.g. 1,3, or press Enter to skip for now.\n");
|
|
190
|
+
let selected = [];
|
|
191
|
+
// eslint-disable-next-line no-constant-condition
|
|
192
|
+
while (true) {
|
|
193
|
+
const sel = parseSelection(await ask("Apps: "), CHOICES.length, detected);
|
|
194
|
+
if (sel.kind === "error") {
|
|
195
|
+
process.stdout.write(` ${sel.message}\n`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
selected = sel.indexes.map((i) => CHOICES[i]);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
if (selected.length === 0) {
|
|
202
|
+
process.stdout.write("\nNo clients connected. Run `standardnotes-mcp-setup` any time to connect one.\n");
|
|
203
|
+
return;
|
|
124
204
|
}
|
|
125
|
-
if (selected.length === 0)
|
|
126
|
-
throw new Error("No clients selected.");
|
|
127
205
|
const askNameFor = async () => {
|
|
128
206
|
// eslint-disable-next-line no-constant-condition
|
|
129
207
|
while (true) {
|
|
130
|
-
const name = await ask("
|
|
208
|
+
const name = await ask(" Name for this app (letters, digits, dashes): ");
|
|
131
209
|
if (/^[a-z0-9-]+$/i.test(name))
|
|
132
210
|
return name;
|
|
133
211
|
process.stdout.write(" Letters, digits, and dashes only — try again.\n");
|
|
134
212
|
}
|
|
135
213
|
};
|
|
214
|
+
// Folder list is read once, on first need (skipping clients costs nothing).
|
|
215
|
+
let folderTitles;
|
|
216
|
+
const askFolders = async (choice) => {
|
|
217
|
+
if (folderTitles === undefined)
|
|
218
|
+
folderTitles = await loadFolderTitles(email);
|
|
219
|
+
const configFile = configFileFor(choice);
|
|
220
|
+
const current = configFile !== null ? await existingServerEnv(configFile) : null;
|
|
221
|
+
const currentTags = (current?.SN_READ_TAGS ?? "")
|
|
222
|
+
.split(",")
|
|
223
|
+
.map((t) => t.trim())
|
|
224
|
+
.filter((t) => t !== "");
|
|
225
|
+
const hasCurrent = currentTags.length > 0;
|
|
226
|
+
process.stdout.write(`\nWhich tags should ${choice.label} be able to see?\n` +
|
|
227
|
+
" Enter tag names separated by commas. It will see only notes with those\n" +
|
|
228
|
+
" tags (or their child tags); everything else is hidden from it.\n" +
|
|
229
|
+
(hasCurrent
|
|
230
|
+
? ` Press Enter to keep the current setting (${currentTags.join(", ")}), or type "all" for the whole vault.\n`
|
|
231
|
+
: " Press Enter to let it see your whole vault.\n") +
|
|
232
|
+
(folderTitles !== null ? ` Your tags: ${folderHint(folderTitles)}\n` : ""));
|
|
233
|
+
// eslint-disable-next-line no-constant-condition
|
|
234
|
+
while (true) {
|
|
235
|
+
const ans = parseFolderAnswer(await ask("Tags: "), folderTitles, hasCurrent);
|
|
236
|
+
if (ans.kind === "keep")
|
|
237
|
+
return currentTags;
|
|
238
|
+
if (ans.kind === "all")
|
|
239
|
+
return [];
|
|
240
|
+
if (ans.kind === "folders")
|
|
241
|
+
return ans.folders;
|
|
242
|
+
process.stdout.write(` No tag named ${ans.names.map((n) => `"${n}"`).join(", ")}. Check the spelling against the list above.\n`);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
136
245
|
const wired = [];
|
|
137
246
|
for (const choice of selected) {
|
|
138
247
|
process.stdout.write(`\n── ${choice.label} ──\n`);
|
|
248
|
+
// The app's name (SN_CLIENT_NAME) is what per-note rules like
|
|
249
|
+
// "ai-lumo: no-access" match. Not asked: keep the name already in the
|
|
250
|
+
// app's config, else use the app's default. Only "Other" has none.
|
|
251
|
+
const configFile = configFileFor(choice);
|
|
252
|
+
const currentName = configFile !== null ? (await existingServerEnv(configFile))?.SN_CLIENT_NAME : undefined;
|
|
139
253
|
let clientName;
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
`config — the AI itself cannot change it.\n`);
|
|
146
|
-
const ans = (await ask(`Use the name "${d}" for ${choice.label}? [Y/n]: `)).toLowerCase();
|
|
147
|
-
if (ans === "" || ans === "y" || ans === "yes") {
|
|
148
|
-
clientName = d;
|
|
149
|
-
}
|
|
150
|
-
else if (ans === "n" || ans === "no") {
|
|
151
|
-
clientName = await askNameFor();
|
|
152
|
-
}
|
|
153
|
-
else if (/^[a-z0-9-]+$/i.test(ans)) {
|
|
154
|
-
// Typed a name directly instead of y/n — accept it.
|
|
155
|
-
clientName = ans;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
clientName = await askNameFor();
|
|
159
|
-
}
|
|
254
|
+
if (currentName !== undefined && /^[a-z0-9-]+$/i.test(currentName)) {
|
|
255
|
+
clientName = currentName;
|
|
256
|
+
}
|
|
257
|
+
else if (choice.defaultName !== "") {
|
|
258
|
+
clientName = choice.defaultName;
|
|
160
259
|
}
|
|
161
260
|
else {
|
|
162
|
-
process.stdout.write(`Pick a governance name for this client. Notes with frontmatter\n` +
|
|
163
|
-
`"ai-<name>: <rule>" will apply to it (e.g. "ai-workai: no-access").\n`);
|
|
164
261
|
clientName = await askNameFor();
|
|
165
262
|
}
|
|
166
|
-
await
|
|
167
|
-
|
|
263
|
+
const readTags = await askFolders(choice);
|
|
264
|
+
if (choice.wiring === "claude-code" && found.has("claude-code")) {
|
|
265
|
+
const yes = (await ask("Add it to Claude Code now (runs `claude mcp add`)? [Y/n]: ")).toLowerCase();
|
|
266
|
+
if (yes === "" || yes === "y" || yes === "yes") {
|
|
267
|
+
if (!addToClaudeCode(paths, buildEntry(paths, email, clientName, readTags).env)) {
|
|
268
|
+
await wire(choice, clientName, email, paths, readTags);
|
|
269
|
+
}
|
|
270
|
+
wired.push({ label: choice.label, name: clientName, readTags });
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
await wire(choice, clientName, email, paths, readTags);
|
|
275
|
+
wired.push({ label: choice.label, name: clientName, readTags });
|
|
168
276
|
}
|
|
169
|
-
process.stdout.write("\nDone
|
|
277
|
+
process.stdout.write("\nDone.\n");
|
|
170
278
|
for (const w of wired) {
|
|
171
|
-
process.stdout.write(` ${w.label}
|
|
279
|
+
process.stdout.write(` ${w.label}: sees ${w.readTags.length > 0 ? `only ${w.readTags.join(", ")}` : "the whole vault"}; name "${w.name}"\n`);
|
|
172
280
|
}
|
|
173
|
-
process.stdout.write("\
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
"
|
|
177
|
-
"of exposing it. Verify any time via the sn://status resource, which\n" +
|
|
178
|
-
"reports the active client identity.\n");
|
|
281
|
+
process.stdout.write("\nThe name is what per-note rules match: a note with \"ai-" +
|
|
282
|
+
`${wired[0]?.name ?? "lumo"}: no-access" in its frontmatter is hidden from that app.\n` +
|
|
283
|
+
"To use a different name, change SN_CLIENT_NAME in the app's MCP settings.\n" +
|
|
284
|
+
"More in the README: Per-note rules, and Limiting an AI to tags.\n");
|
|
179
285
|
}
|
|
180
286
|
finally {
|
|
181
287
|
rl.close();
|
|
182
288
|
}
|
|
183
289
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return (import.meta.url === new URL(`file://${process.argv[1]}`).href ||
|
|
187
|
-
process.argv[1]?.endsWith("setup.ts") === true ||
|
|
188
|
-
process.argv[1]?.endsWith("setup.js") === true);
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
})();
|
|
194
|
-
if (isMain) {
|
|
195
|
-
main().catch((err) => {
|
|
290
|
+
if (isMainModule(import.meta.url)) {
|
|
291
|
+
runSetup().catch((err) => {
|
|
196
292
|
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
197
293
|
process.exit(1);
|
|
198
294
|
});
|
package/dist/config.js
CHANGED
|
@@ -8,6 +8,30 @@ function parseBool(raw) {
|
|
|
8
8
|
const v = raw.trim().toLowerCase();
|
|
9
9
|
return v === "true" || v === "1" || v === "yes" || v === "on";
|
|
10
10
|
}
|
|
11
|
+
function parseDeleteConfirm(env) {
|
|
12
|
+
const raw = (env.SN_DELETE_CONFIRM ?? "").trim().toLowerCase();
|
|
13
|
+
if (["off", "false", "0", "no", "none"].includes(raw))
|
|
14
|
+
return "off";
|
|
15
|
+
if (raw === "prompt")
|
|
16
|
+
return "prompt";
|
|
17
|
+
if (raw === "" && parseBool(env.SN_DELETE_ELICITATION))
|
|
18
|
+
return "prompt";
|
|
19
|
+
if (raw !== "" && raw !== "auto" && !["on", "true", "1", "yes"].includes(raw)) {
|
|
20
|
+
logger.warn(`SN_DELETE_CONFIRM "${raw}" not recognised; using auto (auto, prompt or off)`);
|
|
21
|
+
}
|
|
22
|
+
return "auto";
|
|
23
|
+
}
|
|
24
|
+
/** An editor identifier like com.example.editor; anything else is ignored with a warning. */
|
|
25
|
+
function parseEditorId(raw) {
|
|
26
|
+
const v = trimmedOrNull(raw);
|
|
27
|
+
if (v === null)
|
|
28
|
+
return null;
|
|
29
|
+
if (!/^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/.test(v)) {
|
|
30
|
+
logger.warn(`SN_NEW_NOTE_EDITOR "${v}" is not an editor identifier (like com.example.editor); ignored`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
11
35
|
function parseTagList(raw) {
|
|
12
36
|
if (raw === undefined || raw.trim() === "")
|
|
13
37
|
return [];
|
|
@@ -26,7 +50,7 @@ export function loadConfig(env = process.env) {
|
|
|
26
50
|
readTags: readTags.length > 0 ? readTags : null,
|
|
27
51
|
denyTags,
|
|
28
52
|
},
|
|
29
|
-
|
|
53
|
+
deleteConfirm: parseDeleteConfirm(env),
|
|
30
54
|
governance: !(govRaw === "off" || govRaw === "false" || govRaw === "0"),
|
|
31
55
|
allowExport: parseBool(env.SN_ALLOW_EXPORT),
|
|
32
56
|
exportDir: env.SN_EXPORT_DIR !== undefined && env.SN_EXPORT_DIR.trim() !== ""
|
|
@@ -36,7 +60,9 @@ export function loadConfig(env = process.env) {
|
|
|
36
60
|
? env.SN_CLIENT_NAME.trim()
|
|
37
61
|
: null,
|
|
38
62
|
templatesTag: trimmedOrNull(env.SN_TEMPLATES_TAG) ?? "Templates",
|
|
63
|
+
sharedTemplates: parseBool(env.SN_SHARED_TEMPLATES),
|
|
39
64
|
periodicTag: trimmedOrNull(env.SN_PERIODIC_TAG),
|
|
65
|
+
newNoteEditor: parseEditorId(env.SN_NEW_NOTE_EDITOR),
|
|
40
66
|
};
|
|
41
67
|
const scoped = config.scope.readTags !== null || config.scope.denyTags.length > 0;
|
|
42
68
|
logger.info("Server policy", {
|
|
@@ -47,13 +73,15 @@ export function loadConfig(env = process.env) {
|
|
|
47
73
|
denyTags: config.scope.denyTags,
|
|
48
74
|
}
|
|
49
75
|
: "none",
|
|
50
|
-
|
|
76
|
+
deleteConfirm: config.deleteConfirm,
|
|
51
77
|
governance: config.governance,
|
|
52
78
|
allowExport: config.allowExport,
|
|
53
79
|
exportDir: config.exportDir,
|
|
54
80
|
clientName: config.clientName,
|
|
55
81
|
templatesTag: config.templatesTag,
|
|
82
|
+
sharedTemplates: config.sharedTemplates,
|
|
56
83
|
periodicTag: config.periodicTag,
|
|
84
|
+
newNoteEditor: config.newNoteEditor,
|
|
57
85
|
});
|
|
58
86
|
return config;
|
|
59
87
|
}
|