@mnemocyte/mcp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +225 -162
- package/dist/cli.mjs.map +1 -1
- package/dist/server-only.cjs +2 -0
- package/package.json +4 -3
package/dist/cli.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import { isMnemocyteError } from "mnemocyte";
|
|
|
6
6
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
7
7
|
import { Console } from "node:console";
|
|
8
8
|
import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
9
|
-
import { parseArgs } from "node:util";
|
|
10
9
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
|
+
import { parseArgs } from "node:util";
|
|
11
11
|
// src/cli/console.ts
|
|
12
12
|
const STDOUT_METHODS = [
|
|
13
13
|
"log",
|
|
@@ -43,118 +43,70 @@ function redirectConsoleToStderr() {
|
|
|
43
43
|
enumerable: true
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
// src/
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Scope:
|
|
56
|
-
--entity-id <id> The user or entity whose memories the tools use. Required.
|
|
57
|
-
--namespace <name> Defaults to the memory file's createMemory({ namespace }).
|
|
58
|
-
--agent-id <id> Narrow the scope to one agent.
|
|
59
|
-
--session-id <id> Narrow the scope to one session.
|
|
60
|
-
|
|
61
|
-
Memory file:
|
|
62
|
-
--project <dir> The app's folder. --config, --env-file and the lookup
|
|
63
|
-
are relative to it. Default: the working directory.
|
|
64
|
-
--config <file> The app's memory file. Default: the first of memory.ts,
|
|
65
|
-
memory.mts, memory.js, memory.mjs in ., lib, src, src/lib.
|
|
66
|
-
--env-file <file> Load this file into the environment first. Default: .env
|
|
67
|
-
in the app's folder when it exists.
|
|
68
|
-
|
|
69
|
-
Tools:
|
|
70
|
-
--allow-forget Also list forgetMemory, which deletes for good.
|
|
71
|
-
--read-only List searchMemories only.
|
|
72
|
-
|
|
73
|
-
-h, --help Show this help.
|
|
74
|
-
-v, --version Show the version.
|
|
75
|
-
`;
|
|
76
|
-
const SCOPE_FLAGS = [
|
|
77
|
-
["namespace", "namespace"],
|
|
78
|
-
["entity-id", "entityId"],
|
|
79
|
-
["agent-id", "agentId"],
|
|
80
|
-
["session-id", "sessionId"]
|
|
81
|
-
];
|
|
82
|
-
function nonEmpty(flag, value) {
|
|
83
|
-
if (value !== void 0 && value.trim() === "") throw new UsageError(`--${flag} cannot be empty.`);
|
|
84
|
-
return value;
|
|
46
|
+
// ../loader/src/env-files.ts
|
|
47
|
+
/**
|
|
48
|
+
* The environment files read from the project, in order: Next.js's order
|
|
49
|
+
* for these two (ARCHITECTURE decision 78). The `.env.$(NODE_ENV)` files
|
|
50
|
+
* are left out, since the bins run outside a mode.
|
|
51
|
+
*/
|
|
52
|
+
const ENV_FILE_NAMES = [".env.local", ".env"];
|
|
53
|
+
function isFile$4(path) {
|
|
54
|
+
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
85
55
|
}
|
|
86
56
|
/**
|
|
87
|
-
*
|
|
57
|
+
* Load `.env.local`, then `.env`, from the project into `process.env`, each
|
|
58
|
+
* when it exists. `.env.local` is skipped when `NODE_ENV` is `test`, as in
|
|
59
|
+
* Next.js, so tests do not depend on one machine's overrides; only the real
|
|
60
|
+
* environment's `NODE_ENV` counts, since no file is read before the check.
|
|
61
|
+
* `process.loadEnvFile` keeps a variable that is already set, so the real
|
|
62
|
+
* environment wins over both files and `.env.local` over `.env`.
|
|
88
63
|
*
|
|
89
|
-
* @
|
|
90
|
-
* or empty `--entity-id`, an empty value, or `--read-only` with
|
|
91
|
-
* `--allow-forget`.
|
|
64
|
+
* @returns The names of the files that were read, in order.
|
|
92
65
|
*/
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (positionals.length > 0) throw new UsageError(`Unexpected argument ${positionals[0]}.`);
|
|
104
|
-
const scope = {};
|
|
105
|
-
for (const [flag, field] of SCOPE_FLAGS) {
|
|
106
|
-
const value = nonEmpty(flag, values[flag]);
|
|
107
|
-
if (value !== void 0) scope[field] = value;
|
|
66
|
+
function loadEnvFiles(input) {
|
|
67
|
+
const skipLocal = process.env.NODE_ENV === "test";
|
|
68
|
+
const loaded = [];
|
|
69
|
+
for (const name of ENV_FILE_NAMES) {
|
|
70
|
+
if (skipLocal && name === ".env.local") continue;
|
|
71
|
+
const path = join(input.directory, name);
|
|
72
|
+
if (isFile$4(path)) {
|
|
73
|
+
process.loadEnvFile(path);
|
|
74
|
+
loaded.push(name);
|
|
75
|
+
}
|
|
108
76
|
}
|
|
109
|
-
|
|
110
|
-
if (entityId === void 0) throw new UsageError("--entity-id is required: the server serves one entity's memories.");
|
|
111
|
-
const allowForget = values["allow-forget"] === true;
|
|
112
|
-
const readOnly = values["read-only"] === true;
|
|
113
|
-
if (allowForget && readOnly) throw new UsageError("--read-only and --allow-forget cannot be combined.");
|
|
114
|
-
return {
|
|
115
|
-
command: "serve",
|
|
116
|
-
scope: {
|
|
117
|
-
...scope,
|
|
118
|
-
entityId
|
|
119
|
-
},
|
|
120
|
-
project: nonEmpty("project", values.project),
|
|
121
|
-
config: nonEmpty("config", values.config),
|
|
122
|
-
envFile: nonEmpty("env-file", values["env-file"]),
|
|
123
|
-
allowForget,
|
|
124
|
-
readOnly
|
|
125
|
-
};
|
|
77
|
+
return loaded;
|
|
126
78
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
79
|
+
// ../loader/src/memory-file.ts
|
|
80
|
+
/** Folders searched for a memory file, in order, relative to the project. */
|
|
81
|
+
const MEMORY_FILE_DIRECTORIES = [
|
|
82
|
+
"",
|
|
83
|
+
"lib",
|
|
84
|
+
"src",
|
|
85
|
+
"src/lib"
|
|
86
|
+
];
|
|
87
|
+
/** File names tried in each folder, in order. */
|
|
88
|
+
const MEMORY_FILE_NAMES = [
|
|
89
|
+
"memory.ts",
|
|
90
|
+
"memory.mts",
|
|
91
|
+
"memory.js",
|
|
92
|
+
"memory.mjs"
|
|
93
|
+
];
|
|
94
|
+
function isFile$3(path) {
|
|
95
|
+
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
96
|
+
}
|
|
97
|
+
/** The first memory file in the project, or null. */
|
|
98
|
+
function findMemoryFile(cwd) {
|
|
99
|
+
for (const directory of MEMORY_FILE_DIRECTORIES) for (const name of MEMORY_FILE_NAMES) {
|
|
100
|
+
const candidate = join(cwd, directory, name);
|
|
101
|
+
if (isFile$3(candidate)) return candidate;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
152
104
|
}
|
|
153
|
-
// src/
|
|
105
|
+
// ../loader/src/tsconfig.ts
|
|
154
106
|
function isRecord$1(value) {
|
|
155
107
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
156
108
|
}
|
|
157
|
-
function isFile$
|
|
109
|
+
function isFile$2(path) {
|
|
158
110
|
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
159
111
|
}
|
|
160
112
|
/** Index just past the string literal that starts at `start`. */
|
|
@@ -213,7 +165,7 @@ function parseJsonc(text) {
|
|
|
213
165
|
function resolveExtends(entry, from) {
|
|
214
166
|
if (entry.startsWith("./") || entry.startsWith("../") || isAbsolute(entry)) {
|
|
215
167
|
const path = resolve(dirname(from), entry);
|
|
216
|
-
return [path, `${path}.json`].find(isFile$
|
|
168
|
+
return [path, `${path}.json`].find(isFile$2) ?? null;
|
|
217
169
|
}
|
|
218
170
|
const require = createRequire(from);
|
|
219
171
|
for (const specifier of [
|
|
@@ -275,6 +227,10 @@ function readOptions(file, seen) {
|
|
|
275
227
|
options.paths = toPatterns(compilerOptions.paths);
|
|
276
228
|
options.pathsDirectory = dirname(file);
|
|
277
229
|
}
|
|
230
|
+
for (const key of ["module", "moduleResolution"]) {
|
|
231
|
+
const value = compilerOptions[key];
|
|
232
|
+
if (typeof value === "string") options[key] = value.toLowerCase();
|
|
233
|
+
}
|
|
278
234
|
}
|
|
279
235
|
return options;
|
|
280
236
|
}
|
|
@@ -295,7 +251,7 @@ function loadPathMapping(tsconfigPath) {
|
|
|
295
251
|
function findTsconfig(directory) {
|
|
296
252
|
for (let current = directory;;) {
|
|
297
253
|
const candidate = join(current, "tsconfig.json");
|
|
298
|
-
if (isFile$
|
|
254
|
+
if (isFile$2(candidate)) return candidate;
|
|
299
255
|
const parent = dirname(current);
|
|
300
256
|
if (parent === current) return null;
|
|
301
257
|
current = parent;
|
|
@@ -326,7 +282,7 @@ function mapSpecifier(specifier, mapping) {
|
|
|
326
282
|
if (best === void 0) return [];
|
|
327
283
|
return best.targets.map((target) => resolve(mapping.base, target.replace("*", matched)));
|
|
328
284
|
}
|
|
329
|
-
// src/
|
|
285
|
+
// ../loader/src/resolve-hook.ts
|
|
330
286
|
/** The TypeScript source a JavaScript extension in an import stands for. */
|
|
331
287
|
const SOURCE_EXTENSION = {
|
|
332
288
|
".js": ".ts",
|
|
@@ -347,7 +303,7 @@ const INDEX_FILES = [
|
|
|
347
303
|
"index.js",
|
|
348
304
|
"index.mjs"
|
|
349
305
|
];
|
|
350
|
-
function isFile$
|
|
306
|
+
function isFile$1(path) {
|
|
351
307
|
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
352
308
|
}
|
|
353
309
|
/**
|
|
@@ -392,66 +348,176 @@ function resolveAppImport(specifier, importer) {
|
|
|
392
348
|
targets = mapping === null ? [] : mapSpecifier(specifier, mapping);
|
|
393
349
|
}
|
|
394
350
|
for (const target of targets) {
|
|
395
|
-
const found = importCandidates(target).find(isFile$
|
|
351
|
+
const found = importCandidates(target).find(isFile$1);
|
|
396
352
|
if (found !== void 0) return found;
|
|
397
353
|
}
|
|
398
354
|
return null;
|
|
399
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* The file `server-only` resolves to, next to the bundled loader: each
|
|
358
|
+
* bin's build writes an empty `dist/server-only.cjs` (the
|
|
359
|
+
* `server-only-stub` plugin in its `tsdown.config.ts`). React's marker
|
|
360
|
+
* package throws at import outside the `react-server` condition, and an
|
|
361
|
+
* app's memory file may import it (Next.js's convention for server code).
|
|
362
|
+
* The bins are server code, so it loads as nothing instead (decisions 81
|
|
363
|
+
* and 97). A real file, because Node 22.18 skips resolve hooks for
|
|
364
|
+
* `require()` in CommonJS loaded by `import` once any load hook is
|
|
365
|
+
* registered, and `require()` cannot load a `data:` URL.
|
|
366
|
+
*/
|
|
367
|
+
const SERVER_ONLY_FILE = "server-only.cjs";
|
|
368
|
+
/**
|
|
369
|
+
* The resolve hook. `server-only`, the exact bare specifier, maps to
|
|
370
|
+
* {@link SERVER_ONLY_FILE} before Node resolves it, from any importer, so
|
|
371
|
+
* an installed copy is not loaded either. Everything else asks Node first
|
|
372
|
+
* and looks further only when Node fails, for an importer that is a file
|
|
373
|
+
* outside `node_modules`.
|
|
374
|
+
*/
|
|
375
|
+
const resolveHook = (specifier, context, nextResolve) => {
|
|
376
|
+
if (specifier === "server-only") return {
|
|
377
|
+
url: new URL(SERVER_ONLY_FILE, import.meta.url).href,
|
|
378
|
+
shortCircuit: true
|
|
379
|
+
};
|
|
380
|
+
try {
|
|
381
|
+
return nextResolve(specifier, context);
|
|
382
|
+
} catch (error) {
|
|
383
|
+
const parent = context.parentURL;
|
|
384
|
+
if (parent === void 0 || !parent.startsWith("file:")) throw error;
|
|
385
|
+
const importer = fileURLToPath(parent);
|
|
386
|
+
if (importer.split(/[\\/]/).includes("node_modules")) throw error;
|
|
387
|
+
const found = resolveAppImport(specifier, importer);
|
|
388
|
+
if (found === null) throw error;
|
|
389
|
+
return nextResolve(pathToFileURL(found).href, context);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
400
392
|
let registered = false;
|
|
401
393
|
/**
|
|
402
394
|
* Teach this process the imports a TypeScript app writes that Node's type
|
|
403
395
|
* stripping does not resolve: extensionless and `.js`-for-`.ts` relative
|
|
404
|
-
* imports, and tsconfig `paths
|
|
396
|
+
* imports, and tsconfig `paths`; and load `server-only` as an empty module.
|
|
405
397
|
*
|
|
406
398
|
* `module.registerHooks` installs a synchronous resolve hook on the current
|
|
407
399
|
* thread, for `import` and `require` alike (`module.register`, the
|
|
408
|
-
* asynchronous one, is deprecated from Node 26).
|
|
409
|
-
* and only looks further when Node fails,
|
|
410
|
-
* package included, is untouched.
|
|
411
|
-
*
|
|
400
|
+
* asynchronous one, is deprecated from Node 26). Apart from `server-only`,
|
|
401
|
+
* the resolve hook asks Node first and only looks further when Node fails,
|
|
402
|
+
* so anything Node resolves, every other package included, is untouched.
|
|
403
|
+
* Registering twice does nothing.
|
|
412
404
|
*/
|
|
413
405
|
function registerAppResolver() {
|
|
414
406
|
if (registered) return;
|
|
415
407
|
registered = true;
|
|
416
|
-
registerHooks({ resolve
|
|
417
|
-
try {
|
|
418
|
-
return nextResolve(specifier, context);
|
|
419
|
-
} catch (error) {
|
|
420
|
-
const parent = context.parentURL;
|
|
421
|
-
if (parent === void 0 || !parent.startsWith("file:")) throw error;
|
|
422
|
-
const importer = fileURLToPath(parent);
|
|
423
|
-
if (importer.split(/[\\/]/).includes("node_modules")) throw error;
|
|
424
|
-
const found = resolveAppImport(specifier, importer);
|
|
425
|
-
if (found === null) throw error;
|
|
426
|
-
return nextResolve(pathToFileURL(found).href, context);
|
|
427
|
-
}
|
|
428
|
-
} });
|
|
408
|
+
registerHooks({ resolve: resolveHook });
|
|
429
409
|
}
|
|
430
|
-
// src/cli/
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
""
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
410
|
+
// src/cli/args.ts
|
|
411
|
+
/** A usage error: bad flags. The bin prints it with the usage and exits 2. */
|
|
412
|
+
var UsageError = class extends Error {
|
|
413
|
+
name = "UsageError";
|
|
414
|
+
};
|
|
415
|
+
const USAGE = `Usage: mnemocyte-mcp --entity-id <id> [options]
|
|
416
|
+
|
|
417
|
+
Serves Mnemocyte memory over MCP on stdio, for one scope fixed here.
|
|
418
|
+
|
|
419
|
+
Scope:
|
|
420
|
+
--entity-id <id> The user or entity whose memories the tools use. Required.
|
|
421
|
+
--namespace <name> Defaults to the memory file's createMemory({ namespace }).
|
|
422
|
+
--agent-id <id> Narrow the scope to one agent.
|
|
423
|
+
--session-id <id> Narrow the scope to one session.
|
|
424
|
+
|
|
425
|
+
Memory file:
|
|
426
|
+
--project <dir> The app's folder. --config, --env-file and the lookup
|
|
427
|
+
are relative to it. Default: the working directory.
|
|
428
|
+
--config <file> The app's memory file. Default: the first of memory.ts,
|
|
429
|
+
memory.mts, memory.js, memory.mjs in ., lib, src, src/lib.
|
|
430
|
+
--env-file <file> Load this file into the environment first. Default:
|
|
431
|
+
.env.local, then .env, in the app's folder, each when
|
|
432
|
+
it exists (no .env.local when NODE_ENV is test).
|
|
433
|
+
|
|
434
|
+
Tools:
|
|
435
|
+
--allow-forget Also list forgetMemory, which deletes for good.
|
|
436
|
+
--read-only List searchMemories only.
|
|
437
|
+
|
|
438
|
+
-h, --help Show this help.
|
|
439
|
+
-v, --version Show the version.
|
|
440
|
+
`;
|
|
441
|
+
const SCOPE_FLAGS = [
|
|
442
|
+
["namespace", "namespace"],
|
|
443
|
+
["entity-id", "entityId"],
|
|
444
|
+
["agent-id", "agentId"],
|
|
445
|
+
["session-id", "sessionId"]
|
|
444
446
|
];
|
|
445
|
-
function
|
|
446
|
-
|
|
447
|
+
function nonEmpty(flag, value) {
|
|
448
|
+
if (value !== void 0 && value.trim() === "") throw new UsageError(`--${flag} cannot be empty.`);
|
|
449
|
+
return value;
|
|
447
450
|
}
|
|
448
|
-
/**
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
451
|
+
/**
|
|
452
|
+
* Parse the bin's arguments.
|
|
453
|
+
*
|
|
454
|
+
* @throws {UsageError} For an unknown flag, a positional argument, a missing
|
|
455
|
+
* or empty `--entity-id`, an empty value, or `--read-only` with
|
|
456
|
+
* `--allow-forget`.
|
|
457
|
+
*/
|
|
458
|
+
function parseCliArgs(argv) {
|
|
459
|
+
let parsed;
|
|
460
|
+
try {
|
|
461
|
+
parsed = parse(argv);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
453
464
|
}
|
|
454
|
-
|
|
465
|
+
const { values, positionals } = parsed;
|
|
466
|
+
if (values.help === true) return { command: "help" };
|
|
467
|
+
if (values.version === true) return { command: "version" };
|
|
468
|
+
if (positionals.length > 0) throw new UsageError(`Unexpected argument ${positionals[0]}.`);
|
|
469
|
+
const scope = {};
|
|
470
|
+
for (const [flag, field] of SCOPE_FLAGS) {
|
|
471
|
+
const value = nonEmpty(flag, values[flag]);
|
|
472
|
+
if (value !== void 0) scope[field] = value;
|
|
473
|
+
}
|
|
474
|
+
const entityId = scope.entityId;
|
|
475
|
+
if (entityId === void 0) throw new UsageError("--entity-id is required: the server serves one entity's memories.");
|
|
476
|
+
const allowForget = values["allow-forget"] === true;
|
|
477
|
+
const readOnly = values["read-only"] === true;
|
|
478
|
+
if (allowForget && readOnly) throw new UsageError("--read-only and --allow-forget cannot be combined.");
|
|
479
|
+
return {
|
|
480
|
+
command: "serve",
|
|
481
|
+
scope: {
|
|
482
|
+
...scope,
|
|
483
|
+
entityId
|
|
484
|
+
},
|
|
485
|
+
project: nonEmpty("project", values.project),
|
|
486
|
+
config: nonEmpty("config", values.config),
|
|
487
|
+
envFile: nonEmpty("env-file", values["env-file"]),
|
|
488
|
+
allowForget,
|
|
489
|
+
readOnly
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function parse(argv) {
|
|
493
|
+
return parseArgs({
|
|
494
|
+
args: [...argv],
|
|
495
|
+
allowPositionals: true,
|
|
496
|
+
strict: true,
|
|
497
|
+
options: {
|
|
498
|
+
namespace: { type: "string" },
|
|
499
|
+
"entity-id": { type: "string" },
|
|
500
|
+
"agent-id": { type: "string" },
|
|
501
|
+
"session-id": { type: "string" },
|
|
502
|
+
project: { type: "string" },
|
|
503
|
+
config: { type: "string" },
|
|
504
|
+
"env-file": { type: "string" },
|
|
505
|
+
"allow-forget": { type: "boolean" },
|
|
506
|
+
"read-only": { type: "boolean" },
|
|
507
|
+
help: {
|
|
508
|
+
type: "boolean",
|
|
509
|
+
short: "h"
|
|
510
|
+
},
|
|
511
|
+
version: {
|
|
512
|
+
type: "boolean",
|
|
513
|
+
short: "v"
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
// src/cli/memory-file.ts
|
|
519
|
+
function isFile(path) {
|
|
520
|
+
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
455
521
|
}
|
|
456
522
|
/**
|
|
457
523
|
* The memory file to load: `--config` when given, which must exist,
|
|
@@ -462,7 +528,7 @@ function findMemoryFile(cwd) {
|
|
|
462
528
|
function locateMemoryFile(cwd, config) {
|
|
463
529
|
if (config !== void 0) {
|
|
464
530
|
const file = resolve(cwd, config);
|
|
465
|
-
if (!isFile
|
|
531
|
+
if (!isFile(file)) throw new UsageError(`--config: ${config} is not a file.`);
|
|
466
532
|
return file;
|
|
467
533
|
}
|
|
468
534
|
const found = findMemoryFile(cwd);
|
|
@@ -499,8 +565,8 @@ function isBoundClient(value) {
|
|
|
499
565
|
* Import the app's memory file and return its client: the `memory` export,
|
|
500
566
|
* else the default export's `memory`, else the default export, as the
|
|
501
567
|
* `mnemocyte` CLI reads it. A `.ts` file loads through Node's type stripping
|
|
502
|
-
* with the
|
|
503
|
-
* tsconfig `paths` imports.
|
|
568
|
+
* with the shared resolve hook (`@mnemocyte/loader`) for extensionless,
|
|
569
|
+
* `.js`-for-`.ts` and tsconfig `paths` imports.
|
|
504
570
|
*
|
|
505
571
|
* @throws {UsageError} When the file does not load, or exports a bound
|
|
506
572
|
* client or no client.
|
|
@@ -525,24 +591,21 @@ async function loadMemoryClient(file, cwd) {
|
|
|
525
591
|
if (candidates.some(isBoundClient)) throw new UsageError(`${name} exports a bound client from memory.for(...). Export the client from createMemory() itself; mnemocyte-mcp binds it to the scope in its flags.`);
|
|
526
592
|
throw new UsageError(`${name} does not export a memory client. Export the result of createMemory() as "memory": export const memory = createMemory({ ... });`);
|
|
527
593
|
}
|
|
528
|
-
function isFile(path) {
|
|
529
|
-
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
530
|
-
}
|
|
531
594
|
/**
|
|
532
|
-
* `--env-file` when given, else `.env` in the app's
|
|
595
|
+
* `--env-file` when given, else `.env.local` and then `.env` in the app's
|
|
596
|
+
* folder, each when it exists (`.env.local` not when `NODE_ENV` is `test`),
|
|
533
597
|
* as the `mnemocyte` CLI does. A variable that is already set is kept.
|
|
598
|
+
*
|
|
599
|
+
* @returns The files that were read, for the startup line.
|
|
534
600
|
*/
|
|
535
601
|
function loadEnvironment(cwd, envFile) {
|
|
536
|
-
if (envFile === void 0) {
|
|
537
|
-
const path = join(cwd, ".env");
|
|
538
|
-
if (isFile(path)) process.loadEnvFile(path);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
602
|
+
if (envFile === void 0) return loadEnvFiles({ directory: cwd });
|
|
541
603
|
try {
|
|
542
604
|
process.loadEnvFile(resolve(cwd, envFile));
|
|
543
605
|
} catch (error) {
|
|
544
606
|
throw new UsageError(`--env-file: could not read ${envFile}.`, { cause: error });
|
|
545
607
|
}
|
|
608
|
+
return [envFile];
|
|
546
609
|
}
|
|
547
610
|
/**
|
|
548
611
|
* The app's folder: `--project` resolved against the working directory, or
|
|
@@ -596,7 +659,7 @@ async function prepare(argv, io, version) {
|
|
|
596
659
|
}
|
|
597
660
|
try {
|
|
598
661
|
const project = projectFolder(io.cwd, args.project);
|
|
599
|
-
loadEnvironment(project, args.envFile);
|
|
662
|
+
const envFiles = loadEnvironment(project, args.envFile);
|
|
600
663
|
const file = locateMemoryFile(project, args.config);
|
|
601
664
|
const memory = bind(await loadMemoryClient(file, project), args.scope);
|
|
602
665
|
const { allowForget, readOnly } = args;
|
|
@@ -609,7 +672,7 @@ async function prepare(argv, io, version) {
|
|
|
609
672
|
io.error(`mnemocyte-mcp ${version}: ${label}, scope ${describeScope(memory.scope)}, tools ${toolNames({
|
|
610
673
|
allowForget,
|
|
611
674
|
readOnly
|
|
612
|
-
}).join(", ")}\n`);
|
|
675
|
+
}).join(", ")}, env ${envFiles.length === 0 ? "none" : envFiles.join(", ")}\n`);
|
|
613
676
|
return {
|
|
614
677
|
kind: "serve",
|
|
615
678
|
createServer: () => createMemoryMcpServer({
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["isRecord","isFile","isFile","isFile"],"sources":["../src/cli/console.ts","../src/cli/args.ts","../src/loader/tsconfig.ts","../src/loader/resolve-hook.ts","../src/cli/memory-file.ts","../src/cli/main.ts","../src/cli.ts"],"sourcesContent":["import { Console } from \"node:console\";\n\n// The console methods that write to standard output.\nconst STDOUT_METHODS = [\n\t\"log\",\n\t\"info\",\n\t\"debug\",\n\t\"dir\",\n\t\"dirxml\",\n\t\"table\",\n\t\"group\",\n\t\"groupCollapsed\",\n\t\"groupEnd\",\n\t\"count\",\n\t\"countReset\",\n\t\"time\",\n\t\"timeEnd\",\n\t\"timeLog\",\n] as const;\n\n/**\n * Send everything `console` would print to standard output to standard\n * error instead. On stdio, standard output carries only MCP messages, so a\n * `console.log` in the app's memory file or a module it imports would\n * corrupt the stream. Writes to `process.stdout` itself are not caught.\n */\nexport function redirectConsoleToStderr(): void {\n\tconst toStderr = new Console({\n\t\tstdout: process.stderr,\n\t\tstderr: process.stderr,\n\t});\n\tfor (const method of STDOUT_METHODS) {\n\t\t// Console binds its methods to the instance, so they can move.\n\t\tObject.defineProperty(console, method, {\n\t\t\tvalue: toStderr[method],\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t});\n\t}\n}\n","import { parseArgs } from \"node:util\";\n\n/** What the bin was asked to do. */\nexport type CliArgs =\n\t| { readonly command: \"help\" }\n\t| { readonly command: \"version\" }\n\t| {\n\t\t\treadonly command: \"serve\";\n\t\t\treadonly scope: ServeScope;\n\t\t\treadonly project: string | undefined;\n\t\t\treadonly config: string | undefined;\n\t\t\treadonly envFile: string | undefined;\n\t\t\treadonly allowForget: boolean;\n\t\t\treadonly readOnly: boolean;\n\t };\n\n/** The scope from the flags. `namespace` may come from the memory file. */\nexport interface ServeScope {\n\treadonly namespace?: string;\n\treadonly entityId: string;\n\treadonly agentId?: string;\n\treadonly sessionId?: string;\n}\n\n/** A usage error: bad flags. The bin prints it with the usage and exits 2. */\nexport class UsageError extends Error {\n\toverride readonly name = \"UsageError\";\n}\n\nexport const USAGE: string = `Usage: mnemocyte-mcp --entity-id <id> [options]\n\nServes Mnemocyte memory over MCP on stdio, for one scope fixed here.\n\nScope:\n --entity-id <id> The user or entity whose memories the tools use. Required.\n --namespace <name> Defaults to the memory file's createMemory({ namespace }).\n --agent-id <id> Narrow the scope to one agent.\n --session-id <id> Narrow the scope to one session.\n\nMemory file:\n --project <dir> The app's folder. --config, --env-file and the lookup\n are relative to it. Default: the working directory.\n --config <file> The app's memory file. Default: the first of memory.ts,\n memory.mts, memory.js, memory.mjs in ., lib, src, src/lib.\n --env-file <file> Load this file into the environment first. Default: .env\n in the app's folder when it exists.\n\nTools:\n --allow-forget Also list forgetMemory, which deletes for good.\n --read-only List searchMemories only.\n\n -h, --help Show this help.\n -v, --version Show the version.\n`;\n\nconst SCOPE_FLAGS = [\n\t[\"namespace\", \"namespace\"],\n\t[\"entity-id\", \"entityId\"],\n\t[\"agent-id\", \"agentId\"],\n\t[\"session-id\", \"sessionId\"],\n] as const;\n\nfunction nonEmpty(flag: string, value: string | undefined): string | undefined {\n\tif (value !== undefined && value.trim() === \"\") {\n\t\tthrow new UsageError(`--${flag} cannot be empty.`);\n\t}\n\treturn value;\n}\n\n/**\n * Parse the bin's arguments.\n *\n * @throws {UsageError} For an unknown flag, a positional argument, a missing\n * or empty `--entity-id`, an empty value, or `--read-only` with\n * `--allow-forget`.\n */\nexport function parseCliArgs(argv: readonly string[]): CliArgs {\n\tlet parsed: ReturnType<typeof parse>;\n\ttry {\n\t\tparsed = parse(argv);\n\t} catch (error) {\n\t\tthrow new UsageError(\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t);\n\t}\n\tconst { values, positionals } = parsed;\n\tif (values.help === true) {\n\t\treturn { command: \"help\" };\n\t}\n\tif (values.version === true) {\n\t\treturn { command: \"version\" };\n\t}\n\tif (positionals.length > 0) {\n\t\tthrow new UsageError(`Unexpected argument ${positionals[0]}.`);\n\t}\n\n\tconst scope: Record<string, string> = {};\n\tfor (const [flag, field] of SCOPE_FLAGS) {\n\t\tconst value = nonEmpty(flag, values[flag]);\n\t\tif (value !== undefined) {\n\t\t\tscope[field] = value;\n\t\t}\n\t}\n\tconst entityId = scope.entityId;\n\tif (entityId === undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"--entity-id is required: the server serves one entity's memories.\",\n\t\t);\n\t}\n\tconst allowForget = values[\"allow-forget\"] === true;\n\tconst readOnly = values[\"read-only\"] === true;\n\tif (allowForget && readOnly) {\n\t\tthrow new UsageError(\"--read-only and --allow-forget cannot be combined.\");\n\t}\n\treturn {\n\t\tcommand: \"serve\",\n\t\tscope: { ...scope, entityId },\n\t\tproject: nonEmpty(\"project\", values.project),\n\t\tconfig: nonEmpty(\"config\", values.config),\n\t\tenvFile: nonEmpty(\"env-file\", values[\"env-file\"]),\n\t\tallowForget,\n\t\treadOnly,\n\t};\n}\n\nfunction parse(argv: readonly string[]) {\n\treturn parseArgs({\n\t\targs: [...argv],\n\t\tallowPositionals: true,\n\t\tstrict: true,\n\t\toptions: {\n\t\t\tnamespace: { type: \"string\" },\n\t\t\t\"entity-id\": { type: \"string\" },\n\t\t\t\"agent-id\": { type: \"string\" },\n\t\t\t\"session-id\": { type: \"string\" },\n\t\t\tproject: { type: \"string\" },\n\t\t\tconfig: { type: \"string\" },\n\t\t\t\"env-file\": { type: \"string\" },\n\t\t\t\"allow-forget\": { type: \"boolean\" },\n\t\t\t\"read-only\": { type: \"boolean\" },\n\t\t\thelp: { type: \"boolean\", short: \"h\" },\n\t\t\tversion: { type: \"boolean\", short: \"v\" },\n\t\t},\n\t});\n}\n","import { readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\n\n/** One `compilerOptions.paths` entry: `prefix*suffix`, or an exact name. */\ninterface PathPattern {\n\treadonly prefix: string;\n\t/** `null` for a pattern without `*`, which must match exactly. */\n\treadonly suffix: string | null;\n\treadonly targets: readonly string[];\n}\n\n/** The `paths` of a tsconfig and the folder its targets are relative to. */\nexport interface PathMapping {\n\treadonly base: string;\n\treadonly patterns: readonly PathPattern[];\n}\n\ninterface RawOptions {\n\tbaseUrl?: string;\n\tpaths?: PathPattern[];\n\tpathsDirectory?: string;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/** Index just past the string literal that starts at `start`. */\nfunction stringEnd(text: string, start: number): number {\n\tlet index = start + 1;\n\twhile (index < text.length) {\n\t\tif (text[index] === \"\\\\\") {\n\t\t\tindex += 2;\n\t\t} else if (text[index] === '\"') {\n\t\t\treturn index + 1;\n\t\t} else {\n\t\t\tindex += 1;\n\t\t}\n\t}\n\treturn text.length;\n}\n\nconst BEFORE_CLOSING_BRACKET = /\\s*[}\\]]/y;\n\n/**\n * Parse JSON with comments and trailing commas, which `tsconfig.json`\n * allows and `JSON.parse` rejects. String literals are copied untouched, so\n * a `//` or a comma inside one survives.\n *\n * @throws {SyntaxError} When what is left is not JSON.\n */\nexport function parseJsonc(text: string): unknown {\n\tlet withoutComments = \"\";\n\tfor (let index = 0; index < text.length; ) {\n\t\tif (text[index] === '\"') {\n\t\t\tconst end = stringEnd(text, index);\n\t\t\twithoutComments += text.slice(index, end);\n\t\t\tindex = end;\n\t\t} else if (text.startsWith(\"//\", index)) {\n\t\t\tconst newline = text.indexOf(\"\\n\", index);\n\t\t\tindex = newline === -1 ? text.length : newline;\n\t\t} else if (text.startsWith(\"/*\", index)) {\n\t\t\tconst close = text.indexOf(\"*/\", index + 2);\n\t\t\tindex = close === -1 ? text.length : close + 2;\n\t\t} else {\n\t\t\twithoutComments += text[index];\n\t\t\tindex += 1;\n\t\t}\n\t}\n\n\tlet json = \"\";\n\tfor (let index = 0; index < withoutComments.length; ) {\n\t\tif (withoutComments[index] === '\"') {\n\t\t\tconst end = stringEnd(withoutComments, index);\n\t\t\tjson += withoutComments.slice(index, end);\n\t\t\tindex = end;\n\t\t\tcontinue;\n\t\t}\n\t\tif (withoutComments[index] === \",\") {\n\t\t\tBEFORE_CLOSING_BRACKET.lastIndex = index + 1;\n\t\t\tif (BEFORE_CLOSING_BRACKET.test(withoutComments)) {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tjson += withoutComments[index];\n\t\tindex += 1;\n\t}\n\t// A UTF-8 byte order mark is not JSON either.\n\treturn JSON.parse(json.replace(/^/, \"\"));\n}\n\n/** The file an `extends` entry names, or null when it cannot be found. */\nfunction resolveExtends(entry: string, from: string): string | null {\n\tif (entry.startsWith(\"./\") || entry.startsWith(\"../\") || isAbsolute(entry)) {\n\t\tconst path = resolve(dirname(from), entry);\n\t\t// \"./tsconfig.base\" means tsconfig.base.json: a name's last dot is not\n\t\t// necessarily an extension, so both spellings are tried.\n\t\treturn [path, `${path}.json`].find(isFile) ?? null;\n\t}\n\t// A package, such as \"@tsconfig/node22/tsconfig.json\".\n\tconst require = createRequire(from);\n\tfor (const specifier of [entry, `${entry}.json`, `${entry}/tsconfig.json`]) {\n\t\ttry {\n\t\t\treturn require.resolve(specifier);\n\t\t} catch {\n\t\t\t// Try the next spelling.\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction toPatterns(paths: Record<string, unknown>): PathPattern[] {\n\tconst patterns: PathPattern[] = [];\n\tfor (const [key, value] of Object.entries(paths)) {\n\t\tif (!Array.isArray(value)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst targets = value.filter(\n\t\t\t(target): target is string => typeof target === \"string\",\n\t\t);\n\t\tconst star = key.indexOf(\"*\");\n\t\tpatterns.push(\n\t\t\tstar === -1\n\t\t\t\t? { prefix: key, suffix: null, targets }\n\t\t\t\t: { prefix: key.slice(0, star), suffix: key.slice(star + 1), targets },\n\t\t);\n\t}\n\treturn patterns;\n}\n\n/**\n * `baseUrl` and `paths` of a tsconfig, with what it `extends` underneath.\n * As in TypeScript, a config's own value replaces the inherited one whole.\n * A file that cannot be read or parsed contributes nothing: the CLI then\n * resolves no aliases, and Node reports the import it could not find.\n */\nfunction readOptions(file: string, seen: Set<string>): RawOptions {\n\tif (seen.has(file)) {\n\t\treturn {};\n\t}\n\tseen.add(file);\n\tlet config: unknown;\n\ttry {\n\t\tconfig = parseJsonc(readFileSync(file, \"utf8\"));\n\t} catch {\n\t\treturn {};\n\t}\n\tif (!isRecord(config)) {\n\t\treturn {};\n\t}\n\n\tlet options: RawOptions = {};\n\tconst parents =\n\t\ttypeof config.extends === \"string\"\n\t\t\t? [config.extends]\n\t\t\t: Array.isArray(config.extends)\n\t\t\t\t? config.extends.filter(\n\t\t\t\t\t\t(entry): entry is string => typeof entry === \"string\",\n\t\t\t\t\t)\n\t\t\t\t: [];\n\tfor (const entry of parents) {\n\t\tconst parent = resolveExtends(entry, file);\n\t\tif (parent !== null) {\n\t\t\toptions = { ...options, ...readOptions(parent, seen) };\n\t\t}\n\t}\n\n\tconst compilerOptions = config.compilerOptions;\n\tif (isRecord(compilerOptions)) {\n\t\tif (typeof compilerOptions.baseUrl === \"string\") {\n\t\t\toptions.baseUrl = resolve(dirname(file), compilerOptions.baseUrl);\n\t\t}\n\t\tif (isRecord(compilerOptions.paths)) {\n\t\t\toptions.paths = toPatterns(compilerOptions.paths);\n\t\t\toptions.pathsDirectory = dirname(file);\n\t\t}\n\t}\n\treturn options;\n}\n\n/**\n * The `paths` mapping of a tsconfig file, or null when it (and what it\n * extends) defines none. Targets are relative to `baseUrl` when one is set,\n * otherwise to the folder of the config that defines `paths`.\n */\nexport function loadPathMapping(tsconfigPath: string): PathMapping | null {\n\tconst options = readOptions(tsconfigPath, new Set());\n\tif (options.paths === undefined || options.pathsDirectory === undefined) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tbase: options.baseUrl ?? options.pathsDirectory,\n\t\tpatterns: options.paths,\n\t};\n}\n\n/** The nearest `tsconfig.json` in `directory` or a folder above it. */\nexport function findTsconfig(directory: string): string | null {\n\tfor (let current = directory; ; ) {\n\t\tconst candidate = join(current, \"tsconfig.json\");\n\t\tif (isFile(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrent = parent;\n\t}\n}\n\n/**\n * The absolute paths `specifier` maps to, in order, or none when no pattern\n * matches. An exact pattern wins; among wildcard patterns the longest\n * prefix wins, as in TypeScript.\n */\nexport function mapSpecifier(\n\tspecifier: string,\n\tmapping: PathMapping,\n): string[] {\n\tlet best: PathPattern | undefined;\n\tlet matched = \"\";\n\tfor (const pattern of mapping.patterns) {\n\t\tif (pattern.suffix === null) {\n\t\t\tif (pattern.prefix === specifier) {\n\t\t\t\tbest = pattern;\n\t\t\t\tmatched = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tspecifier.length >= pattern.prefix.length + pattern.suffix.length &&\n\t\t\tspecifier.startsWith(pattern.prefix) &&\n\t\t\tspecifier.endsWith(pattern.suffix) &&\n\t\t\t(best === undefined || pattern.prefix.length > best.prefix.length)\n\t\t) {\n\t\t\tbest = pattern;\n\t\t\tmatched = specifier.slice(\n\t\t\t\tpattern.prefix.length,\n\t\t\t\tspecifier.length - pattern.suffix.length,\n\t\t\t);\n\t\t}\n\t}\n\tif (best === undefined) {\n\t\treturn [];\n\t}\n\treturn best.targets.map((target) =>\n\t\tresolve(mapping.base, target.replace(\"*\", matched)),\n\t);\n}\n","import { statSync } from \"node:fs\";\nimport { registerHooks } from \"node:module\";\nimport { dirname, extname, join, resolve } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport {\n\tfindTsconfig,\n\tloadPathMapping,\n\tmapSpecifier,\n\ttype PathMapping,\n} from \"./tsconfig.js\";\n\n/** The TypeScript source a JavaScript extension in an import stands for. */\nconst SOURCE_EXTENSION: Readonly<Record<string, string>> = {\n\t\".js\": \".ts\",\n\t\".mjs\": \".mts\",\n\t\".cjs\": \".cts\",\n};\n\nconst APPENDED_EXTENSIONS = [\".ts\", \".mts\", \".cts\", \".js\", \".mjs\", \".cjs\"];\nconst INDEX_FILES = [\"index.ts\", \"index.mts\", \"index.js\", \"index.mjs\"];\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/**\n * The files an import of `path` can mean, in the order tried: the path\n * itself, the `.ts` behind a `.js` name (how TypeScript projects with\n * `module: nodenext` write imports), then an added extension and a folder's\n * index file for an extensionless import.\n */\nexport function importCandidates(path: string): string[] {\n\tconst extension = extname(path);\n\tconst source = SOURCE_EXTENSION[extension];\n\tif (source !== undefined) {\n\t\treturn [path, `${path.slice(0, -extension.length)}${source}`];\n\t}\n\treturn [\n\t\tpath,\n\t\t...APPENDED_EXTENSIONS.map((appended) => `${path}${appended}`),\n\t\t...INDEX_FILES.map((index) => join(path, index)),\n\t];\n}\n\n// Keyed by the importing file's folder. `null` is a folder without a\n// tsconfig, or with one that has no `paths`.\nconst mappings = new Map<string, PathMapping | null>();\n\nfunction pathMappingFor(directory: string): PathMapping | null {\n\tlet mapping = mappings.get(directory);\n\tif (mapping === undefined) {\n\t\tconst tsconfig = findTsconfig(directory);\n\t\tmapping = tsconfig === null ? null : loadPathMapping(tsconfig);\n\t\tmappings.set(directory, mapping);\n\t}\n\treturn mapping;\n}\n\n/**\n * The file an import in `importer` means when Node's own resolution found\n * nothing, or null. Relative imports get the candidates of\n * {@link importCandidates}; any other specifier goes through the `paths` of\n * the nearest `tsconfig.json`.\n */\nexport function resolveAppImport(\n\tspecifier: string,\n\timporter: string,\n): string | null {\n\tconst directory = dirname(importer);\n\tlet targets: string[];\n\tif (specifier.startsWith(\"./\") || specifier.startsWith(\"../\")) {\n\t\ttargets = [resolve(directory, specifier)];\n\t} else if (specifier.startsWith(\"node:\")) {\n\t\treturn null;\n\t} else {\n\t\tconst mapping = pathMappingFor(directory);\n\t\ttargets = mapping === null ? [] : mapSpecifier(specifier, mapping);\n\t}\n\tfor (const target of targets) {\n\t\tconst found = importCandidates(target).find(isFile);\n\t\tif (found !== undefined) {\n\t\t\treturn found;\n\t\t}\n\t}\n\treturn null;\n}\n\nlet registered = false;\n\n/**\n * Teach this process the imports a TypeScript app writes that Node's type\n * stripping does not resolve: extensionless and `.js`-for-`.ts` relative\n * imports, and tsconfig `paths`.\n *\n * `module.registerHooks` installs a synchronous resolve hook on the current\n * thread, for `import` and `require` alike (`module.register`, the\n * asynchronous one, is deprecated from Node 26). The hook asks Node first\n * and only looks further when Node fails, so anything Node resolves, every\n * package included, is untouched. It ignores imports made from inside\n * `node_modules`. Registering twice does nothing.\n */\nexport function registerAppResolver(): void {\n\tif (registered) {\n\t\treturn;\n\t}\n\tregistered = true;\n\tregisterHooks({\n\t\tresolve(specifier, context, nextResolve) {\n\t\t\ttry {\n\t\t\t\treturn nextResolve(specifier, context);\n\t\t\t} catch (error) {\n\t\t\t\tconst parent = context.parentURL;\n\t\t\t\tif (parent === undefined || !parent.startsWith(\"file:\")) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst importer = fileURLToPath(parent);\n\t\t\t\tif (importer.split(/[\\\\/]/).includes(\"node_modules\")) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst found = resolveAppImport(specifier, importer);\n\t\t\t\tif (found === null) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\treturn nextResolve(pathToFileURL(found).href, context);\n\t\t\t}\n\t\t},\n\t});\n}\n","import { statSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { MemoryClient } from \"mnemocyte\";\nimport { registerAppResolver } from \"../loader/resolve-hook.js\";\nimport { UsageError } from \"./args.js\";\n\n// The lookup is the `mnemocyte` CLI's (src/cli/memory-file.ts there), so\n// both bins find the same file; a test compares the lists. Reading the\n// client uses only the public API: the CLI's symbol for the store and\n// embedder is not needed to call `for`.\n\n/** Folders searched for a memory file, in order, relative to the project. */\nexport const MEMORY_FILE_DIRECTORIES: readonly string[] = [\n\t\"\",\n\t\"lib\",\n\t\"src\",\n\t\"src/lib\",\n];\n\n/** File names tried in each folder, in order. */\nexport const MEMORY_FILE_NAMES: readonly string[] = [\n\t\"memory.ts\",\n\t\"memory.mts\",\n\t\"memory.js\",\n\t\"memory.mjs\",\n];\n\n/** An unbound client, as `createMemory` returns it. */\nexport type UnboundMemoryClient = MemoryClient<boolean>;\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/** The first memory file in the project, or null. */\nexport function findMemoryFile(cwd: string): string | null {\n\tfor (const directory of MEMORY_FILE_DIRECTORIES) {\n\t\tfor (const name of MEMORY_FILE_NAMES) {\n\t\t\tconst candidate = join(cwd, directory, name);\n\t\t\tif (isFile(candidate)) {\n\t\t\t\treturn candidate;\n\t\t\t}\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * The memory file to load: `--config` when given, which must exist,\n * otherwise the first one found.\n *\n * @throws {UsageError} When `--config` names no file or no file is found.\n */\nexport function locateMemoryFile(\n\tcwd: string,\n\tconfig: string | undefined,\n): string {\n\tif (config !== undefined) {\n\t\tconst file = resolve(cwd, config);\n\t\tif (!isFile(file)) {\n\t\t\tthrow new UsageError(`--config: ${config} is not a file.`);\n\t\t}\n\t\treturn file;\n\t}\n\tconst found = findMemoryFile(cwd);\n\tif (found === null) {\n\t\tthrow new UsageError(\n\t\t\t`No memory file found in ${cwd}. Pass --config <file> with the file that exports createMemory()'s client.`,\n\t\t);\n\t}\n\treturn found;\n}\n\nfunction errorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) {\n\t\treturn undefined;\n\t}\n\treturn typeof error.code === \"string\" ? error.code : undefined;\n}\n\nfunction firstLine(error: unknown): string {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn message.split(\"\\n\")[0]?.trim() ?? \"\";\n}\n\nconst BUILD_HINT = \"Build the file and pass --config <built .js>.\";\n\nfunction loadError(name: string, error: unknown): UsageError {\n\tconst detail = firstLine(error);\n\tswitch (errorCode(error)) {\n\t\tcase \"ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX\":\n\t\t\treturn new UsageError(\n\t\t\t\t`${name} uses TypeScript syntax Node cannot run (${detail}). Node loads TypeScript by removing the types, so enums, namespaces with code and parameter properties do not load. ${BUILD_HINT}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tcase \"ERR_UNKNOWN_FILE_EXTENSION\":\n\t\t\treturn new UsageError(\n\t\t\t\t`Node cannot load ${name} (${detail}). .tsx files are not supported, and neither is a Node started with type stripping turned off. ${BUILD_HINT}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tcase \"ERR_MODULE_NOT_FOUND\":\n\t\t\treturn new UsageError(\n\t\t\t\t`${name} imports a module that was not found (${detail}). Relative imports resolve without an extension or with \".js\" for a \".ts\" file, and through tsconfig \"paths\"; for other aliases, build the file and pass --config <built .js>.`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tdefault:\n\t\t\treturn new UsageError(`Loading ${name} failed: ${detail}`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isUnboundClient(value: unknown): value is UnboundMemoryClient {\n\treturn (\n\t\tisRecord(value) &&\n\t\ttypeof value.for === \"function\" &&\n\t\ttypeof value.search === \"function\" &&\n\t\ttypeof value.add === \"function\" &&\n\t\ttypeof value.delete === \"function\"\n\t);\n}\n\nfunction isBoundClient(value: unknown): boolean {\n\treturn (\n\t\tisRecord(value) &&\n\t\tisRecord(value.scope) &&\n\t\ttypeof value.search === \"function\" &&\n\t\t!(\"for\" in value)\n\t);\n}\n\n/**\n * Import the app's memory file and return its client: the `memory` export,\n * else the default export's `memory`, else the default export, as the\n * `mnemocyte` CLI reads it. A `.ts` file loads through Node's type stripping\n * with the CLI's resolve hook for extensionless, `.js`-for-`.ts` and\n * tsconfig `paths` imports.\n *\n * @throws {UsageError} When the file does not load, or exports a bound\n * client or no client.\n */\nexport async function loadMemoryClient(\n\tfile: string,\n\tcwd: string,\n): Promise<UnboundMemoryClient> {\n\tconst name = relative(cwd, file).replaceAll(\"\\\\\", \"/\") || file;\n\tregisterAppResolver();\n\tlet exports: Record<string, unknown>;\n\ttry {\n\t\texports = (await import(pathToFileURL(file).href)) as Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>;\n\t} catch (error) {\n\t\tthrow loadError(name, error);\n\t}\n\n\tconst fallback = exports.default;\n\tconst candidates = [\n\t\texports.memory,\n\t\tisRecord(fallback) && \"memory\" in fallback ? fallback.memory : undefined,\n\t\tfallback,\n\t].filter((candidate) => candidate !== undefined);\n\tconst client = candidates.find(isUnboundClient);\n\tif (client !== undefined) {\n\t\treturn client;\n\t}\n\tif (candidates.some(isBoundClient)) {\n\t\tthrow new UsageError(\n\t\t\t`${name} exports a bound client from memory.for(...). Export the client from createMemory() itself; mnemocyte-mcp binds it to the scope in its flags.`,\n\t\t);\n\t}\n\tthrow new UsageError(\n\t\t`${name} does not export a memory client. Export the result of createMemory() as \"memory\": export const memory = createMemory({ ... });`,\n\t);\n}\n","import { statSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BoundMemoryClient } from \"mnemocyte\";\nimport { isMnemocyteError } from \"mnemocyte\";\nimport { createMemoryMcpServer, toolNames } from \"../server.js\";\nimport { parseCliArgs, type ServeScope, USAGE, UsageError } from \"./args.js\";\nimport { loadMemoryClient, locateMemoryFile } from \"./memory-file.js\";\n\n/** Where the bin reads and writes. Tests pass a recording one. */\nexport interface CliIo {\n\treadonly cwd: string;\n\t/** Standard output: help and version only. */\n\twrite(text: string): void;\n\t/** Standard error: errors and the startup line. */\n\terror(text: string): void;\n}\n\n/** What the bin does after {@link prepare}. */\nexport type Prepared =\n\t| { readonly kind: \"exit\"; readonly code: number }\n\t| {\n\t\t\treadonly kind: \"serve\";\n\t\t\t/** A new server for each connection. */\n\t\t\treadonly createServer: () => McpServer;\n\t };\n\n/** Exit code for bad flags or a memory file that cannot be used. */\nexport const EXIT_USAGE = 2;\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/**\n * `--env-file` when given, else `.env` in the app's folder when it exists,\n * as the `mnemocyte` CLI does. A variable that is already set is kept.\n */\nexport function loadEnvironment(\n\tcwd: string,\n\tenvFile: string | undefined,\n): void {\n\tif (envFile === undefined) {\n\t\tconst path = join(cwd, \".env\");\n\t\tif (isFile(path)) {\n\t\t\tprocess.loadEnvFile(path);\n\t\t}\n\t\treturn;\n\t}\n\ttry {\n\t\tprocess.loadEnvFile(resolve(cwd, envFile));\n\t} catch (error) {\n\t\tthrow new UsageError(`--env-file: could not read ${envFile}.`, {\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n\n/**\n * The app's folder: `--project` resolved against the working directory, or\n * the working directory itself. MCP clients do not all say which folder\n * they start a server in.\n *\n * @throws {UsageError} When `--project` is not a folder.\n */\nexport function projectFolder(\n\tcwd: string,\n\tproject: string | undefined,\n): string {\n\tif (project === undefined) {\n\t\treturn cwd;\n\t}\n\tconst folder = resolve(cwd, project);\n\tif (statSync(folder, { throwIfNoEntry: false })?.isDirectory() !== true) {\n\t\tthrow new UsageError(`--project: ${project} is not a folder.`);\n\t}\n\treturn folder;\n}\n\nfunction describeError(error: unknown): string {\n\treturn `mnemocyte-mcp: ${error instanceof Error ? error.message : String(error)}\\n`;\n}\n\nfunction describeScope(scope: Readonly<Record<string, unknown>>): string {\n\treturn Object.entries(scope)\n\t\t.filter(([, value]) => value !== undefined)\n\t\t.map(([field, value]) => `${field}=${String(value)}`)\n\t\t.join(\" \");\n}\n\n/**\n * Parse the arguments, load the memory file and bind its client to the\n * scope in the flags. Resolves with what to do next; never rejects. Errors\n * are written to `io.error`: bad flags and an unusable memory file exit 2,\n * anything else 1.\n */\nexport async function prepare(\n\targv: readonly string[],\n\tio: CliIo,\n\tversion: string,\n): Promise<Prepared> {\n\tlet args: ReturnType<typeof parseCliArgs>;\n\ttry {\n\t\targs = parseCliArgs(argv);\n\t} catch (error) {\n\t\tio.error(`${describeError(error)}\\n${USAGE}`);\n\t\treturn { kind: \"exit\", code: EXIT_USAGE };\n\t}\n\tif (args.command === \"help\") {\n\t\tio.write(USAGE);\n\t\treturn { kind: \"exit\", code: 0 };\n\t}\n\tif (args.command === \"version\") {\n\t\tio.write(`${version}\\n`);\n\t\treturn { kind: \"exit\", code: 0 };\n\t}\n\n\ttry {\n\t\tconst project = projectFolder(io.cwd, args.project);\n\t\tloadEnvironment(project, args.envFile);\n\t\tconst file = locateMemoryFile(project, args.config);\n\t\tconst client = await loadMemoryClient(file, project);\n\t\tconst memory = bind(client, args.scope);\n\t\tconst { allowForget, readOnly } = args;\n\t\t// Built once here so a bad option fails at startup, not on connect.\n\t\tcreateMemoryMcpServer({ memory, allowForget, readOnly });\n\t\tconst label = relative(project, file).replaceAll(\"\\\\\", \"/\") || file;\n\t\tio.error(\n\t\t\t`mnemocyte-mcp ${version}: ${label}, scope ${describeScope(memory.scope)}, tools ${toolNames({ allowForget, readOnly }).join(\", \")}\\n`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"serve\",\n\t\t\tcreateServer: () =>\n\t\t\t\tcreateMemoryMcpServer({ memory, allowForget, readOnly }),\n\t\t};\n\t} catch (error) {\n\t\tio.error(describeError(error));\n\t\treturn {\n\t\t\tkind: \"exit\",\n\t\t\tcode:\n\t\t\t\terror instanceof UsageError ||\n\t\t\t\t(isMnemocyteError(error) &&\n\t\t\t\t\t(error.code === \"VALIDATION\" || error.code === \"CONFIG\"))\n\t\t\t\t\t? EXIT_USAGE\n\t\t\t\t\t: 1,\n\t\t};\n\t}\n}\n\nfunction bind(\n\tclient: { for(scope: ServeScope): BoundMemoryClient },\n\tscope: ServeScope,\n): BoundMemoryClient {\n\ttry {\n\t\treturn client.for(scope);\n\t} catch (error) {\n\t\tif (isMnemocyteError(error) && error.code === \"VALIDATION\") {\n\t\t\tconst hint =\n\t\t\t\tscope.namespace === undefined\n\t\t\t\t\t? \" Pass --namespace, or set namespace in the memory file's createMemory().\"\n\t\t\t\t\t: \"\";\n\t\t\tthrow new UsageError(\n\t\t\t\t`The scope in the flags is not valid: ${error.message}${hint}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n","#!/usr/bin/env node\n// The `mnemocyte-mcp` bin. Not an export of the package: `package.json`\n// lists it under `bin` only.\nimport { serveStdio } from \"@modelcontextprotocol/server/stdio\";\nimport { redirectConsoleToStderr } from \"./cli/console.js\";\nimport { type CliIo, prepare } from \"./cli/main.js\";\nimport { SERVER_INFO } from \"./server.js\";\n\nconst io: CliIo = {\n\tcwd: process.cwd(),\n\twrite: (text) => process.stdout.write(text),\n\terror: (text) => process.stderr.write(text),\n};\n\n// Each stream's empty write is queued behind the output, so its callback\n// runs once that is flushed (pipes are asynchronous on Windows).\nfunction exit(code: number): void {\n\tprocess.stdout.write(\"\", () => {\n\t\tprocess.stderr.write(\"\", () => process.exit(code));\n\t});\n}\n\n// Before the memory file is imported, so nothing it logs reaches stdout.\nredirectConsoleToStderr();\n\n// No top-level await, like the rest of dist/.\nvoid prepare(process.argv.slice(2), io, SERVER_INFO.version).then(\n\t(prepared) => {\n\t\tif (prepared.kind === \"exit\") {\n\t\t\texit(prepared.code);\n\t\t\treturn;\n\t\t}\n\t\tserveStdio(prepared.createServer, {\n\t\t\tonerror: (error) => io.error(`mnemocyte-mcp: ${error.message}\\n`),\n\t\t});\n\t\t// The client ends the session by closing stdin. The app's database\n\t\t// client, which the bin does not own and cannot close, would keep the\n\t\t// process alive, so it exits here.\n\t\tlet ended = false;\n\t\tconst end = () => {\n\t\t\tif (!ended) {\n\t\t\t\tended = true;\n\t\t\t\texit(0);\n\t\t\t}\n\t\t};\n\t\tprocess.stdin.once(\"end\", end);\n\t\tprocess.stdin.once(\"close\", end);\n\t},\n);\n"],"mappings":";;;;;;;;;;;AAGA,MAAM,iBAAiB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AAQA,SAAgB,0BAAgC;CAC/C,MAAM,WAAW,IAAI,QAAQ;EAC5B,QAAQ,QAAQ;EAChB,QAAQ,QAAQ;CACjB,CAAC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AK,SAAS,GAAG;AAChC,CACD"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["isFile","isFile","isRecord","isFile","isFile"],"sources":["../src/cli/console.ts","../../loader/src/env-files.ts","../../loader/src/memory-file.ts","../../loader/src/tsconfig.ts","../../loader/src/resolve-hook.ts","../src/cli/args.ts","../src/cli/memory-file.ts","../src/cli/main.ts","../src/cli.ts"],"sourcesContent":["import { Console } from \"node:console\";\n\n// The console methods that write to standard output.\nconst STDOUT_METHODS = [\n\t\"log\",\n\t\"info\",\n\t\"debug\",\n\t\"dir\",\n\t\"dirxml\",\n\t\"table\",\n\t\"group\",\n\t\"groupCollapsed\",\n\t\"groupEnd\",\n\t\"count\",\n\t\"countReset\",\n\t\"time\",\n\t\"timeEnd\",\n\t\"timeLog\",\n] as const;\n\n/**\n * Send everything `console` would print to standard output to standard\n * error instead. On stdio, standard output carries only MCP messages, so a\n * `console.log` in the app's memory file or a module it imports would\n * corrupt the stream. Writes to `process.stdout` itself are not caught.\n */\nexport function redirectConsoleToStderr(): void {\n\tconst toStderr = new Console({\n\t\tstdout: process.stderr,\n\t\tstderr: process.stderr,\n\t});\n\tfor (const method of STDOUT_METHODS) {\n\t\t// Console binds its methods to the instance, so they can move.\n\t\tObject.defineProperty(console, method, {\n\t\t\tvalue: toStderr[method],\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t});\n\t}\n}\n","import { statSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/**\n * The environment files read from the project, in order: Next.js's order\n * for these two (ARCHITECTURE decision 78). The `.env.$(NODE_ENV)` files\n * are left out, since the bins run outside a mode.\n */\nexport const ENV_FILE_NAMES: readonly string[] = [\".env.local\", \".env\"];\n\n/** Input of {@link loadEnvFiles}. */\nexport interface LoadEnvFilesInput {\n\t/** The project folder the files are read from. */\n\treadonly directory: string;\n}\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/**\n * Load `.env.local`, then `.env`, from the project into `process.env`, each\n * when it exists. `.env.local` is skipped when `NODE_ENV` is `test`, as in\n * Next.js, so tests do not depend on one machine's overrides; only the real\n * environment's `NODE_ENV` counts, since no file is read before the check.\n * `process.loadEnvFile` keeps a variable that is already set, so the real\n * environment wins over both files and `.env.local` over `.env`.\n *\n * @returns The names of the files that were read, in order.\n */\nexport function loadEnvFiles(input: LoadEnvFilesInput): string[] {\n\tconst skipLocal = process.env.NODE_ENV === \"test\";\n\tconst loaded: string[] = [];\n\tfor (const name of ENV_FILE_NAMES) {\n\t\tif (skipLocal && name === \".env.local\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst path = join(input.directory, name);\n\t\tif (isFile(path)) {\n\t\t\tprocess.loadEnvFile(path);\n\t\t\tloaded.push(name);\n\t\t}\n\t}\n\treturn loaded;\n}\n","import { statSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/** Folders searched for a memory file, in order, relative to the project. */\nexport const MEMORY_FILE_DIRECTORIES: readonly string[] = [\n\t\"\",\n\t\"lib\",\n\t\"src\",\n\t\"src/lib\",\n];\n\n/** File names tried in each folder, in order. */\nexport const MEMORY_FILE_NAMES: readonly string[] = [\n\t\"memory.ts\",\n\t\"memory.mts\",\n\t\"memory.js\",\n\t\"memory.mjs\",\n];\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/** The first memory file in the project, or null. */\nexport function findMemoryFile(cwd: string): string | null {\n\tfor (const directory of MEMORY_FILE_DIRECTORIES) {\n\t\tfor (const name of MEMORY_FILE_NAMES) {\n\t\t\tconst candidate = join(cwd, directory, name);\n\t\t\tif (isFile(candidate)) {\n\t\t\t\treturn candidate;\n\t\t\t}\n\t\t}\n\t}\n\treturn null;\n}\n","import { readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\n\n/** One `compilerOptions.paths` entry: `prefix*suffix`, or an exact name. */\ninterface PathPattern {\n\treadonly prefix: string;\n\t/** `null` for a pattern without `*`, which must match exactly. */\n\treadonly suffix: string | null;\n\treadonly targets: readonly string[];\n}\n\n/** The `paths` of a tsconfig and the folder its targets are relative to. */\nexport interface PathMapping {\n\treadonly base: string;\n\treadonly patterns: readonly PathPattern[];\n}\n\ninterface RawOptions {\n\tbaseUrl?: string;\n\tpaths?: PathPattern[];\n\tpathsDirectory?: string;\n\tmodule?: string;\n\tmoduleResolution?: string;\n}\n\n/** `compilerOptions.module` and `moduleResolution`, in lower case. */\nexport interface ModuleOptions {\n\treadonly module?: string;\n\treadonly moduleResolution?: string;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/** Index just past the string literal that starts at `start`. */\nfunction stringEnd(text: string, start: number): number {\n\tlet index = start + 1;\n\twhile (index < text.length) {\n\t\tif (text[index] === \"\\\\\") {\n\t\t\tindex += 2;\n\t\t} else if (text[index] === '\"') {\n\t\t\treturn index + 1;\n\t\t} else {\n\t\t\tindex += 1;\n\t\t}\n\t}\n\treturn text.length;\n}\n\nconst BEFORE_CLOSING_BRACKET = /\\s*[}\\]]/y;\n\n/**\n * Parse JSON with comments and trailing commas, which `tsconfig.json`\n * allows and `JSON.parse` rejects. String literals are copied untouched, so\n * a `//` or a comma inside one survives.\n *\n * @throws {SyntaxError} When what is left is not JSON.\n */\nexport function parseJsonc(text: string): unknown {\n\tlet withoutComments = \"\";\n\tfor (let index = 0; index < text.length; ) {\n\t\tif (text[index] === '\"') {\n\t\t\tconst end = stringEnd(text, index);\n\t\t\twithoutComments += text.slice(index, end);\n\t\t\tindex = end;\n\t\t} else if (text.startsWith(\"//\", index)) {\n\t\t\tconst newline = text.indexOf(\"\\n\", index);\n\t\t\tindex = newline === -1 ? text.length : newline;\n\t\t} else if (text.startsWith(\"/*\", index)) {\n\t\t\tconst close = text.indexOf(\"*/\", index + 2);\n\t\t\tindex = close === -1 ? text.length : close + 2;\n\t\t} else {\n\t\t\twithoutComments += text[index];\n\t\t\tindex += 1;\n\t\t}\n\t}\n\n\tlet json = \"\";\n\tfor (let index = 0; index < withoutComments.length; ) {\n\t\tif (withoutComments[index] === '\"') {\n\t\t\tconst end = stringEnd(withoutComments, index);\n\t\t\tjson += withoutComments.slice(index, end);\n\t\t\tindex = end;\n\t\t\tcontinue;\n\t\t}\n\t\tif (withoutComments[index] === \",\") {\n\t\t\tBEFORE_CLOSING_BRACKET.lastIndex = index + 1;\n\t\t\tif (BEFORE_CLOSING_BRACKET.test(withoutComments)) {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tjson += withoutComments[index];\n\t\tindex += 1;\n\t}\n\t// A UTF-8 byte order mark is not JSON either.\n\treturn JSON.parse(json.replace(/^/, \"\"));\n}\n\n/** The file an `extends` entry names, or null when it cannot be found. */\nfunction resolveExtends(entry: string, from: string): string | null {\n\tif (entry.startsWith(\"./\") || entry.startsWith(\"../\") || isAbsolute(entry)) {\n\t\tconst path = resolve(dirname(from), entry);\n\t\t// \"./tsconfig.base\" means tsconfig.base.json: a name's last dot is not\n\t\t// necessarily an extension, so both spellings are tried.\n\t\treturn [path, `${path}.json`].find(isFile) ?? null;\n\t}\n\t// A package, such as \"@tsconfig/node22/tsconfig.json\".\n\tconst require = createRequire(from);\n\tfor (const specifier of [entry, `${entry}.json`, `${entry}/tsconfig.json`]) {\n\t\ttry {\n\t\t\treturn require.resolve(specifier);\n\t\t} catch {\n\t\t\t// Try the next spelling.\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction toPatterns(paths: Record<string, unknown>): PathPattern[] {\n\tconst patterns: PathPattern[] = [];\n\tfor (const [key, value] of Object.entries(paths)) {\n\t\tif (!Array.isArray(value)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst targets = value.filter(\n\t\t\t(target): target is string => typeof target === \"string\",\n\t\t);\n\t\tconst star = key.indexOf(\"*\");\n\t\tpatterns.push(\n\t\t\tstar === -1\n\t\t\t\t? { prefix: key, suffix: null, targets }\n\t\t\t\t: { prefix: key.slice(0, star), suffix: key.slice(star + 1), targets },\n\t\t);\n\t}\n\treturn patterns;\n}\n\n/**\n * `baseUrl` and `paths` of a tsconfig, with what it `extends` underneath.\n * As in TypeScript, a config's own value replaces the inherited one whole.\n * A file that cannot be read or parsed contributes nothing: the CLI then\n * resolves no aliases, and Node reports the import it could not find.\n */\nfunction readOptions(file: string, seen: Set<string>): RawOptions {\n\tif (seen.has(file)) {\n\t\treturn {};\n\t}\n\tseen.add(file);\n\tlet config: unknown;\n\ttry {\n\t\tconfig = parseJsonc(readFileSync(file, \"utf8\"));\n\t} catch {\n\t\treturn {};\n\t}\n\tif (!isRecord(config)) {\n\t\treturn {};\n\t}\n\n\tlet options: RawOptions = {};\n\tconst parents =\n\t\ttypeof config.extends === \"string\"\n\t\t\t? [config.extends]\n\t\t\t: Array.isArray(config.extends)\n\t\t\t\t? config.extends.filter(\n\t\t\t\t\t\t(entry): entry is string => typeof entry === \"string\",\n\t\t\t\t\t)\n\t\t\t\t: [];\n\tfor (const entry of parents) {\n\t\tconst parent = resolveExtends(entry, file);\n\t\tif (parent !== null) {\n\t\t\toptions = { ...options, ...readOptions(parent, seen) };\n\t\t}\n\t}\n\n\tconst compilerOptions = config.compilerOptions;\n\tif (isRecord(compilerOptions)) {\n\t\tif (typeof compilerOptions.baseUrl === \"string\") {\n\t\t\toptions.baseUrl = resolve(dirname(file), compilerOptions.baseUrl);\n\t\t}\n\t\tif (isRecord(compilerOptions.paths)) {\n\t\t\toptions.paths = toPatterns(compilerOptions.paths);\n\t\t\toptions.pathsDirectory = dirname(file);\n\t\t}\n\t\tfor (const key of [\"module\", \"moduleResolution\"] as const) {\n\t\t\tconst value = compilerOptions[key];\n\t\t\tif (typeof value === \"string\") {\n\t\t\t\toptions[key] = value.toLowerCase();\n\t\t\t}\n\t\t}\n\t}\n\treturn options;\n}\n\n/**\n * The `paths` mapping of a tsconfig file, or null when it (and what it\n * extends) defines none. Targets are relative to `baseUrl` when one is set,\n * otherwise to the folder of the config that defines `paths`.\n */\nexport function loadPathMapping(tsconfigPath: string): PathMapping | null {\n\tconst options = readOptions(tsconfigPath, new Set());\n\tif (options.paths === undefined || options.pathsDirectory === undefined) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tbase: options.baseUrl ?? options.pathsDirectory,\n\t\tpatterns: options.paths,\n\t};\n}\n\n/**\n * `module` and `moduleResolution` of a tsconfig file, with what it extends\n * underneath, as `mnemocyte init` needs them to spell an import. A file\n * that cannot be read contributes nothing.\n */\nexport function loadModuleOptions(tsconfigPath: string): ModuleOptions {\n\tconst options = readOptions(tsconfigPath, new Set());\n\treturn {\n\t\t...(options.module === undefined ? {} : { module: options.module }),\n\t\t...(options.moduleResolution === undefined\n\t\t\t? {}\n\t\t\t: { moduleResolution: options.moduleResolution }),\n\t};\n}\n\n/** The nearest `tsconfig.json` in `directory` or a folder above it. */\nexport function findTsconfig(directory: string): string | null {\n\tfor (let current = directory; ; ) {\n\t\tconst candidate = join(current, \"tsconfig.json\");\n\t\tif (isFile(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrent = parent;\n\t}\n}\n\n/**\n * The absolute paths `specifier` maps to, in order, or none when no pattern\n * matches. An exact pattern wins; among wildcard patterns the longest\n * prefix wins, as in TypeScript.\n */\nexport function mapSpecifier(\n\tspecifier: string,\n\tmapping: PathMapping,\n): string[] {\n\tlet best: PathPattern | undefined;\n\tlet matched = \"\";\n\tfor (const pattern of mapping.patterns) {\n\t\tif (pattern.suffix === null) {\n\t\t\tif (pattern.prefix === specifier) {\n\t\t\t\tbest = pattern;\n\t\t\t\tmatched = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (\n\t\t\tspecifier.length >= pattern.prefix.length + pattern.suffix.length &&\n\t\t\tspecifier.startsWith(pattern.prefix) &&\n\t\t\tspecifier.endsWith(pattern.suffix) &&\n\t\t\t(best === undefined || pattern.prefix.length > best.prefix.length)\n\t\t) {\n\t\t\tbest = pattern;\n\t\t\tmatched = specifier.slice(\n\t\t\t\tpattern.prefix.length,\n\t\t\t\tspecifier.length - pattern.suffix.length,\n\t\t\t);\n\t\t}\n\t}\n\tif (best === undefined) {\n\t\treturn [];\n\t}\n\treturn best.targets.map((target) =>\n\t\tresolve(mapping.base, target.replace(\"*\", matched)),\n\t);\n}\n","import { statSync } from \"node:fs\";\nimport { type ResolveHookSync, registerHooks } from \"node:module\";\nimport { dirname, extname, join, resolve } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport {\n\tfindTsconfig,\n\tloadPathMapping,\n\tmapSpecifier,\n\ttype PathMapping,\n} from \"./tsconfig.js\";\n\n/** The TypeScript source a JavaScript extension in an import stands for. */\nconst SOURCE_EXTENSION: Readonly<Record<string, string>> = {\n\t\".js\": \".ts\",\n\t\".mjs\": \".mts\",\n\t\".cjs\": \".cts\",\n};\n\nconst APPENDED_EXTENSIONS = [\".ts\", \".mts\", \".cts\", \".js\", \".mjs\", \".cjs\"];\nconst INDEX_FILES = [\"index.ts\", \"index.mts\", \"index.js\", \"index.mjs\"];\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/**\n * The files an import of `path` can mean, in the order tried: the path\n * itself, the `.ts` behind a `.js` name (how TypeScript projects with\n * `module: nodenext` write imports), then an added extension and a folder's\n * index file for an extensionless import.\n */\nexport function importCandidates(path: string): string[] {\n\tconst extension = extname(path);\n\tconst source = SOURCE_EXTENSION[extension];\n\tif (source !== undefined) {\n\t\treturn [path, `${path.slice(0, -extension.length)}${source}`];\n\t}\n\treturn [\n\t\tpath,\n\t\t...APPENDED_EXTENSIONS.map((appended) => `${path}${appended}`),\n\t\t...INDEX_FILES.map((index) => join(path, index)),\n\t];\n}\n\n// Keyed by the importing file's folder. `null` is a folder without a\n// tsconfig, or with one that has no `paths`.\nconst mappings = new Map<string, PathMapping | null>();\n\nfunction pathMappingFor(directory: string): PathMapping | null {\n\tlet mapping = mappings.get(directory);\n\tif (mapping === undefined) {\n\t\tconst tsconfig = findTsconfig(directory);\n\t\tmapping = tsconfig === null ? null : loadPathMapping(tsconfig);\n\t\tmappings.set(directory, mapping);\n\t}\n\treturn mapping;\n}\n\n/**\n * The file an import in `importer` means when Node's own resolution found\n * nothing, or null. Relative imports get the candidates of\n * {@link importCandidates}; any other specifier goes through the `paths` of\n * the nearest `tsconfig.json`.\n */\nexport function resolveAppImport(\n\tspecifier: string,\n\timporter: string,\n): string | null {\n\tconst directory = dirname(importer);\n\tlet targets: string[];\n\tif (specifier.startsWith(\"./\") || specifier.startsWith(\"../\")) {\n\t\ttargets = [resolve(directory, specifier)];\n\t} else if (specifier.startsWith(\"node:\")) {\n\t\treturn null;\n\t} else {\n\t\tconst mapping = pathMappingFor(directory);\n\t\ttargets = mapping === null ? [] : mapSpecifier(specifier, mapping);\n\t}\n\tfor (const target of targets) {\n\t\tconst found = importCandidates(target).find(isFile);\n\t\tif (found !== undefined) {\n\t\t\treturn found;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n * The file `server-only` resolves to, next to the bundled loader: each\n * bin's build writes an empty `dist/server-only.cjs` (the\n * `server-only-stub` plugin in its `tsdown.config.ts`). React's marker\n * package throws at import outside the `react-server` condition, and an\n * app's memory file may import it (Next.js's convention for server code).\n * The bins are server code, so it loads as nothing instead (decisions 81\n * and 97). A real file, because Node 22.18 skips resolve hooks for\n * `require()` in CommonJS loaded by `import` once any load hook is\n * registered, and `require()` cannot load a `data:` URL.\n */\nexport const SERVER_ONLY_FILE = \"server-only.cjs\";\n\n/**\n * The resolve hook. `server-only`, the exact bare specifier, maps to\n * {@link SERVER_ONLY_FILE} before Node resolves it, from any importer, so\n * an installed copy is not loaded either. Everything else asks Node first\n * and looks further only when Node fails, for an importer that is a file\n * outside `node_modules`.\n */\nexport const resolveHook: ResolveHookSync = (\n\tspecifier,\n\tcontext,\n\tnextResolve,\n) => {\n\tif (specifier === \"server-only\") {\n\t\tconst url = new URL(SERVER_ONLY_FILE, import.meta.url).href;\n\t\treturn { url, shortCircuit: true };\n\t}\n\ttry {\n\t\treturn nextResolve(specifier, context);\n\t} catch (error) {\n\t\tconst parent = context.parentURL;\n\t\tif (parent === undefined || !parent.startsWith(\"file:\")) {\n\t\t\tthrow error;\n\t\t}\n\t\tconst importer = fileURLToPath(parent);\n\t\tif (importer.split(/[\\\\/]/).includes(\"node_modules\")) {\n\t\t\tthrow error;\n\t\t}\n\t\tconst found = resolveAppImport(specifier, importer);\n\t\tif (found === null) {\n\t\t\tthrow error;\n\t\t}\n\t\treturn nextResolve(pathToFileURL(found).href, context);\n\t}\n};\n\nlet registered = false;\n\n/**\n * Teach this process the imports a TypeScript app writes that Node's type\n * stripping does not resolve: extensionless and `.js`-for-`.ts` relative\n * imports, and tsconfig `paths`; and load `server-only` as an empty module.\n *\n * `module.registerHooks` installs a synchronous resolve hook on the current\n * thread, for `import` and `require` alike (`module.register`, the\n * asynchronous one, is deprecated from Node 26). Apart from `server-only`,\n * the resolve hook asks Node first and only looks further when Node fails,\n * so anything Node resolves, every other package included, is untouched.\n * Registering twice does nothing.\n */\nexport function registerAppResolver(): void {\n\tif (registered) {\n\t\treturn;\n\t}\n\tregistered = true;\n\tregisterHooks({ resolve: resolveHook });\n}\n","import { parseArgs } from \"node:util\";\n\n/** What the bin was asked to do. */\nexport type CliArgs =\n\t| { readonly command: \"help\" }\n\t| { readonly command: \"version\" }\n\t| {\n\t\t\treadonly command: \"serve\";\n\t\t\treadonly scope: ServeScope;\n\t\t\treadonly project: string | undefined;\n\t\t\treadonly config: string | undefined;\n\t\t\treadonly envFile: string | undefined;\n\t\t\treadonly allowForget: boolean;\n\t\t\treadonly readOnly: boolean;\n\t };\n\n/** The scope from the flags. `namespace` may come from the memory file. */\nexport interface ServeScope {\n\treadonly namespace?: string;\n\treadonly entityId: string;\n\treadonly agentId?: string;\n\treadonly sessionId?: string;\n}\n\n/** A usage error: bad flags. The bin prints it with the usage and exits 2. */\nexport class UsageError extends Error {\n\toverride readonly name = \"UsageError\";\n}\n\nexport const USAGE: string = `Usage: mnemocyte-mcp --entity-id <id> [options]\n\nServes Mnemocyte memory over MCP on stdio, for one scope fixed here.\n\nScope:\n --entity-id <id> The user or entity whose memories the tools use. Required.\n --namespace <name> Defaults to the memory file's createMemory({ namespace }).\n --agent-id <id> Narrow the scope to one agent.\n --session-id <id> Narrow the scope to one session.\n\nMemory file:\n --project <dir> The app's folder. --config, --env-file and the lookup\n are relative to it. Default: the working directory.\n --config <file> The app's memory file. Default: the first of memory.ts,\n memory.mts, memory.js, memory.mjs in ., lib, src, src/lib.\n --env-file <file> Load this file into the environment first. Default:\n .env.local, then .env, in the app's folder, each when\n it exists (no .env.local when NODE_ENV is test).\n\nTools:\n --allow-forget Also list forgetMemory, which deletes for good.\n --read-only List searchMemories only.\n\n -h, --help Show this help.\n -v, --version Show the version.\n`;\n\nconst SCOPE_FLAGS = [\n\t[\"namespace\", \"namespace\"],\n\t[\"entity-id\", \"entityId\"],\n\t[\"agent-id\", \"agentId\"],\n\t[\"session-id\", \"sessionId\"],\n] as const;\n\nfunction nonEmpty(flag: string, value: string | undefined): string | undefined {\n\tif (value !== undefined && value.trim() === \"\") {\n\t\tthrow new UsageError(`--${flag} cannot be empty.`);\n\t}\n\treturn value;\n}\n\n/**\n * Parse the bin's arguments.\n *\n * @throws {UsageError} For an unknown flag, a positional argument, a missing\n * or empty `--entity-id`, an empty value, or `--read-only` with\n * `--allow-forget`.\n */\nexport function parseCliArgs(argv: readonly string[]): CliArgs {\n\tlet parsed: ReturnType<typeof parse>;\n\ttry {\n\t\tparsed = parse(argv);\n\t} catch (error) {\n\t\tthrow new UsageError(\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t);\n\t}\n\tconst { values, positionals } = parsed;\n\tif (values.help === true) {\n\t\treturn { command: \"help\" };\n\t}\n\tif (values.version === true) {\n\t\treturn { command: \"version\" };\n\t}\n\tif (positionals.length > 0) {\n\t\tthrow new UsageError(`Unexpected argument ${positionals[0]}.`);\n\t}\n\n\tconst scope: Record<string, string> = {};\n\tfor (const [flag, field] of SCOPE_FLAGS) {\n\t\tconst value = nonEmpty(flag, values[flag]);\n\t\tif (value !== undefined) {\n\t\t\tscope[field] = value;\n\t\t}\n\t}\n\tconst entityId = scope.entityId;\n\tif (entityId === undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"--entity-id is required: the server serves one entity's memories.\",\n\t\t);\n\t}\n\tconst allowForget = values[\"allow-forget\"] === true;\n\tconst readOnly = values[\"read-only\"] === true;\n\tif (allowForget && readOnly) {\n\t\tthrow new UsageError(\"--read-only and --allow-forget cannot be combined.\");\n\t}\n\treturn {\n\t\tcommand: \"serve\",\n\t\tscope: { ...scope, entityId },\n\t\tproject: nonEmpty(\"project\", values.project),\n\t\tconfig: nonEmpty(\"config\", values.config),\n\t\tenvFile: nonEmpty(\"env-file\", values[\"env-file\"]),\n\t\tallowForget,\n\t\treadOnly,\n\t};\n}\n\nfunction parse(argv: readonly string[]) {\n\treturn parseArgs({\n\t\targs: [...argv],\n\t\tallowPositionals: true,\n\t\tstrict: true,\n\t\toptions: {\n\t\t\tnamespace: { type: \"string\" },\n\t\t\t\"entity-id\": { type: \"string\" },\n\t\t\t\"agent-id\": { type: \"string\" },\n\t\t\t\"session-id\": { type: \"string\" },\n\t\t\tproject: { type: \"string\" },\n\t\t\tconfig: { type: \"string\" },\n\t\t\t\"env-file\": { type: \"string\" },\n\t\t\t\"allow-forget\": { type: \"boolean\" },\n\t\t\t\"read-only\": { type: \"boolean\" },\n\t\t\thelp: { type: \"boolean\", short: \"h\" },\n\t\t\tversion: { type: \"boolean\", short: \"v\" },\n\t\t},\n\t});\n}\n","import { statSync } from \"node:fs\";\nimport { relative, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { findMemoryFile, registerAppResolver } from \"@mnemocyte/loader\";\nimport type { MemoryClient } from \"mnemocyte\";\nimport { UsageError } from \"./args.js\";\n\n// The lookup and the resolve hook come from @mnemocyte/loader, the private\n// package the `mnemocyte` CLI bundles too, so both bins find and load the\n// same file. Reading the client uses only the public API: the CLI's symbol\n// for the store and embedder is not needed to call `for`.\n\n/** An unbound client, as `createMemory` returns it. */\nexport type UnboundMemoryClient = MemoryClient<boolean>;\n\nfunction isFile(path: string): boolean {\n\treturn statSync(path, { throwIfNoEntry: false })?.isFile() === true;\n}\n\n/**\n * The memory file to load: `--config` when given, which must exist,\n * otherwise the first one found.\n *\n * @throws {UsageError} When `--config` names no file or no file is found.\n */\nexport function locateMemoryFile(\n\tcwd: string,\n\tconfig: string | undefined,\n): string {\n\tif (config !== undefined) {\n\t\tconst file = resolve(cwd, config);\n\t\tif (!isFile(file)) {\n\t\t\tthrow new UsageError(`--config: ${config} is not a file.`);\n\t\t}\n\t\treturn file;\n\t}\n\tconst found = findMemoryFile(cwd);\n\tif (found === null) {\n\t\tthrow new UsageError(\n\t\t\t`No memory file found in ${cwd}. Pass --config <file> with the file that exports createMemory()'s client.`,\n\t\t);\n\t}\n\treturn found;\n}\n\nfunction errorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) {\n\t\treturn undefined;\n\t}\n\treturn typeof error.code === \"string\" ? error.code : undefined;\n}\n\nfunction firstLine(error: unknown): string {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn message.split(\"\\n\")[0]?.trim() ?? \"\";\n}\n\nconst BUILD_HINT = \"Build the file and pass --config <built .js>.\";\n\nfunction loadError(name: string, error: unknown): UsageError {\n\tconst detail = firstLine(error);\n\tswitch (errorCode(error)) {\n\t\tcase \"ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX\":\n\t\t\treturn new UsageError(\n\t\t\t\t`${name} uses TypeScript syntax Node cannot run (${detail}). Node loads TypeScript by removing the types, so enums, namespaces with code and parameter properties do not load. ${BUILD_HINT}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tcase \"ERR_UNKNOWN_FILE_EXTENSION\":\n\t\t\treturn new UsageError(\n\t\t\t\t`Node cannot load ${name} (${detail}). .tsx files are not supported, and neither is a Node started with type stripping turned off. ${BUILD_HINT}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tcase \"ERR_MODULE_NOT_FOUND\":\n\t\t\treturn new UsageError(\n\t\t\t\t`${name} imports a module that was not found (${detail}). Relative imports resolve without an extension or with \".js\" for a \".ts\" file, and through tsconfig \"paths\"; for other aliases, build the file and pass --config <built .js>.`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\tdefault:\n\t\t\treturn new UsageError(`Loading ${name} failed: ${detail}`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isUnboundClient(value: unknown): value is UnboundMemoryClient {\n\treturn (\n\t\tisRecord(value) &&\n\t\ttypeof value.for === \"function\" &&\n\t\ttypeof value.search === \"function\" &&\n\t\ttypeof value.add === \"function\" &&\n\t\ttypeof value.delete === \"function\"\n\t);\n}\n\nfunction isBoundClient(value: unknown): boolean {\n\treturn (\n\t\tisRecord(value) &&\n\t\tisRecord(value.scope) &&\n\t\ttypeof value.search === \"function\" &&\n\t\t!(\"for\" in value)\n\t);\n}\n\n/**\n * Import the app's memory file and return its client: the `memory` export,\n * else the default export's `memory`, else the default export, as the\n * `mnemocyte` CLI reads it. A `.ts` file loads through Node's type stripping\n * with the shared resolve hook (`@mnemocyte/loader`) for extensionless,\n * `.js`-for-`.ts` and tsconfig `paths` imports.\n *\n * @throws {UsageError} When the file does not load, or exports a bound\n * client or no client.\n */\nexport async function loadMemoryClient(\n\tfile: string,\n\tcwd: string,\n): Promise<UnboundMemoryClient> {\n\tconst name = relative(cwd, file).replaceAll(\"\\\\\", \"/\") || file;\n\tregisterAppResolver();\n\tlet exports: Record<string, unknown>;\n\ttry {\n\t\texports = (await import(pathToFileURL(file).href)) as Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>;\n\t} catch (error) {\n\t\tthrow loadError(name, error);\n\t}\n\n\tconst fallback = exports.default;\n\tconst candidates = [\n\t\texports.memory,\n\t\tisRecord(fallback) && \"memory\" in fallback ? fallback.memory : undefined,\n\t\tfallback,\n\t].filter((candidate) => candidate !== undefined);\n\tconst client = candidates.find(isUnboundClient);\n\tif (client !== undefined) {\n\t\treturn client;\n\t}\n\tif (candidates.some(isBoundClient)) {\n\t\tthrow new UsageError(\n\t\t\t`${name} exports a bound client from memory.for(...). Export the client from createMemory() itself; mnemocyte-mcp binds it to the scope in its flags.`,\n\t\t);\n\t}\n\tthrow new UsageError(\n\t\t`${name} does not export a memory client. Export the result of createMemory() as \"memory\": export const memory = createMemory({ ... });`,\n\t);\n}\n","import { statSync } from \"node:fs\";\nimport { relative, resolve } from \"node:path\";\nimport { loadEnvFiles } from \"@mnemocyte/loader\";\nimport type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BoundMemoryClient } from \"mnemocyte\";\nimport { isMnemocyteError } from \"mnemocyte\";\nimport { createMemoryMcpServer, toolNames } from \"../server.js\";\nimport { parseCliArgs, type ServeScope, USAGE, UsageError } from \"./args.js\";\nimport { loadMemoryClient, locateMemoryFile } from \"./memory-file.js\";\n\n/** Where the bin reads and writes. Tests pass a recording one. */\nexport interface CliIo {\n\treadonly cwd: string;\n\t/** Standard output: help and version only. */\n\twrite(text: string): void;\n\t/** Standard error: errors and the startup line. */\n\terror(text: string): void;\n}\n\n/** What the bin does after {@link prepare}. */\nexport type Prepared =\n\t| { readonly kind: \"exit\"; readonly code: number }\n\t| {\n\t\t\treadonly kind: \"serve\";\n\t\t\t/** A new server for each connection. */\n\t\t\treadonly createServer: () => McpServer;\n\t };\n\n/** Exit code for bad flags or a memory file that cannot be used. */\nexport const EXIT_USAGE = 2;\n\n/**\n * `--env-file` when given, else `.env.local` and then `.env` in the app's\n * folder, each when it exists (`.env.local` not when `NODE_ENV` is `test`),\n * as the `mnemocyte` CLI does. A variable that is already set is kept.\n *\n * @returns The files that were read, for the startup line.\n */\nexport function loadEnvironment(\n\tcwd: string,\n\tenvFile: string | undefined,\n): string[] {\n\tif (envFile === undefined) {\n\t\treturn loadEnvFiles({ directory: cwd });\n\t}\n\ttry {\n\t\tprocess.loadEnvFile(resolve(cwd, envFile));\n\t} catch (error) {\n\t\tthrow new UsageError(`--env-file: could not read ${envFile}.`, {\n\t\t\tcause: error,\n\t\t});\n\t}\n\treturn [envFile];\n}\n\n/**\n * The app's folder: `--project` resolved against the working directory, or\n * the working directory itself. MCP clients do not all say which folder\n * they start a server in.\n *\n * @throws {UsageError} When `--project` is not a folder.\n */\nexport function projectFolder(\n\tcwd: string,\n\tproject: string | undefined,\n): string {\n\tif (project === undefined) {\n\t\treturn cwd;\n\t}\n\tconst folder = resolve(cwd, project);\n\tif (statSync(folder, { throwIfNoEntry: false })?.isDirectory() !== true) {\n\t\tthrow new UsageError(`--project: ${project} is not a folder.`);\n\t}\n\treturn folder;\n}\n\nfunction describeError(error: unknown): string {\n\treturn `mnemocyte-mcp: ${error instanceof Error ? error.message : String(error)}\\n`;\n}\n\nfunction describeScope(scope: Readonly<Record<string, unknown>>): string {\n\treturn Object.entries(scope)\n\t\t.filter(([, value]) => value !== undefined)\n\t\t.map(([field, value]) => `${field}=${String(value)}`)\n\t\t.join(\" \");\n}\n\n/**\n * Parse the arguments, load the memory file and bind its client to the\n * scope in the flags. Resolves with what to do next; never rejects. Errors\n * are written to `io.error`: bad flags and an unusable memory file exit 2,\n * anything else 1.\n */\nexport async function prepare(\n\targv: readonly string[],\n\tio: CliIo,\n\tversion: string,\n): Promise<Prepared> {\n\tlet args: ReturnType<typeof parseCliArgs>;\n\ttry {\n\t\targs = parseCliArgs(argv);\n\t} catch (error) {\n\t\tio.error(`${describeError(error)}\\n${USAGE}`);\n\t\treturn { kind: \"exit\", code: EXIT_USAGE };\n\t}\n\tif (args.command === \"help\") {\n\t\tio.write(USAGE);\n\t\treturn { kind: \"exit\", code: 0 };\n\t}\n\tif (args.command === \"version\") {\n\t\tio.write(`${version}\\n`);\n\t\treturn { kind: \"exit\", code: 0 };\n\t}\n\n\ttry {\n\t\tconst project = projectFolder(io.cwd, args.project);\n\t\tconst envFiles = loadEnvironment(project, args.envFile);\n\t\tconst file = locateMemoryFile(project, args.config);\n\t\tconst client = await loadMemoryClient(file, project);\n\t\tconst memory = bind(client, args.scope);\n\t\tconst { allowForget, readOnly } = args;\n\t\t// Built once here so a bad option fails at startup, not on connect.\n\t\tcreateMemoryMcpServer({ memory, allowForget, readOnly });\n\t\tconst label = relative(project, file).replaceAll(\"\\\\\", \"/\") || file;\n\t\tio.error(\n\t\t\t`mnemocyte-mcp ${version}: ${label}, scope ${describeScope(memory.scope)}, tools ${toolNames({ allowForget, readOnly }).join(\", \")}, env ${envFiles.length === 0 ? \"none\" : envFiles.join(\", \")}\\n`,\n\t\t);\n\t\treturn {\n\t\t\tkind: \"serve\",\n\t\t\tcreateServer: () =>\n\t\t\t\tcreateMemoryMcpServer({ memory, allowForget, readOnly }),\n\t\t};\n\t} catch (error) {\n\t\tio.error(describeError(error));\n\t\treturn {\n\t\t\tkind: \"exit\",\n\t\t\tcode:\n\t\t\t\terror instanceof UsageError ||\n\t\t\t\t(isMnemocyteError(error) &&\n\t\t\t\t\t(error.code === \"VALIDATION\" || error.code === \"CONFIG\"))\n\t\t\t\t\t? EXIT_USAGE\n\t\t\t\t\t: 1,\n\t\t};\n\t}\n}\n\nfunction bind(\n\tclient: { for(scope: ServeScope): BoundMemoryClient },\n\tscope: ServeScope,\n): BoundMemoryClient {\n\ttry {\n\t\treturn client.for(scope);\n\t} catch (error) {\n\t\tif (isMnemocyteError(error) && error.code === \"VALIDATION\") {\n\t\t\tconst hint =\n\t\t\t\tscope.namespace === undefined\n\t\t\t\t\t? \" Pass --namespace, or set namespace in the memory file's createMemory().\"\n\t\t\t\t\t: \"\";\n\t\t\tthrow new UsageError(\n\t\t\t\t`The scope in the flags is not valid: ${error.message}${hint}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n","#!/usr/bin/env node\n// The `mnemocyte-mcp` bin. Not an export of the package: `package.json`\n// lists it under `bin` only.\nimport { serveStdio } from \"@modelcontextprotocol/server/stdio\";\nimport { redirectConsoleToStderr } from \"./cli/console.js\";\nimport { type CliIo, prepare } from \"./cli/main.js\";\nimport { SERVER_INFO } from \"./server.js\";\n\nconst io: CliIo = {\n\tcwd: process.cwd(),\n\twrite: (text) => process.stdout.write(text),\n\terror: (text) => process.stderr.write(text),\n};\n\n// Each stream's empty write is queued behind the output, so its callback\n// runs once that is flushed (pipes are asynchronous on Windows).\nfunction exit(code: number): void {\n\tprocess.stdout.write(\"\", () => {\n\t\tprocess.stderr.write(\"\", () => process.exit(code));\n\t});\n}\n\n// Before the memory file is imported, so nothing it logs reaches stdout.\nredirectConsoleToStderr();\n\n// No top-level await, like the rest of dist/.\nvoid prepare(process.argv.slice(2), io, SERVER_INFO.version).then(\n\t(prepared) => {\n\t\tif (prepared.kind === \"exit\") {\n\t\t\texit(prepared.code);\n\t\t\treturn;\n\t\t}\n\t\tserveStdio(prepared.createServer, {\n\t\t\tonerror: (error) => io.error(`mnemocyte-mcp: ${error.message}\\n`),\n\t\t});\n\t\t// The client ends the session by closing stdin. The app's database\n\t\t// client, which the bin does not own and cannot close, would keep the\n\t\t// process alive, so it exits here.\n\t\tlet ended = false;\n\t\tconst end = () => {\n\t\t\tif (!ended) {\n\t\t\t\tended = true;\n\t\t\t\texit(0);\n\t\t\t}\n\t\t};\n\t\tprocess.stdin.once(\"end\", end);\n\t\tprocess.stdin.once(\"close\", end);\n\t},\n);\n"],"mappings":";;;;;;;;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gBAAgB,MAAM,SAAS,YAAA,IAE7C;EACL;CACD;AACD;AAEA,SAAS,KACR,QACA,OACoB;CACpB,IAAI;EACH,OAAO,OAAO,IAAI,KAAK;CACxB,SAAS,OAAO;EACf,IAAI,iBAAiB,KAAK,KAAK,MAAM,SAAS,cAAc;GAC3D,MAAM,OACL,MAAM,cAAc,KAAA,IACjB,6EACA;GACJ,MAAM,IAAI,WACT,wCAAwC,MAAM,UAAU,QACxD,EAAE,OAAO,MAAM,CAChB;EACD;EACA,MAAM;CACP;AACD;;AC7JA,MAAM,KAAY;CACjB,KAAK,QAAQ,IAAI;CACjB,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI;CAC1C,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI;AAC3C;AAIA,SAAS,KAAK,MAAoB;CACjC,QAAQ,OAAO,MAAM,UAAU;EAC9B,QAAQ,OAAO,MAAM,UAAU,QAAQ,KAAK,IAAI,CAAC;CAClD,CAAC;AACF;AAGA,wBAAwB;AAGnB,QAAQ,QAAQ,KAAK,MAAM,CAAC,GAAG,IAAI,YAAY,OAAO,CAAC,CAAC,MAC3D,aAAa;CACb,IAAI,SAAS,SAAS,QAAQ;EAC7B,KAAK,SAAS,IAAI;EAClB;CACD;CACA,WAAW,SAAS,cAAc,EACjC,UAAU,UAAU,GAAG,MAAM,kBAAkB,MAAM,QAAQ,GAAG,EACjE,CAAC;CAID,IAAI,QAAQ;CACZ,MAAM,YAAY;EACjB,IAAI,CAAC,OAAO;GACX,QAAQ;GACR,KAAK,CAAC;EACP;CACD;CACA,QAAQ,MAAM,KAAK,OAAO,GAAG;CAC7B,QAAQ,MAAM,KAAK,SAAS,GAAG;AAChC,CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnemocyte/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "An MCP server for Mnemocyte memory: search, save and forget for one fixed scope.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@arethetypeswrong/cli": "0.18.5",
|
|
50
|
+
"@mnemocyte/loader": "0.0.0",
|
|
50
51
|
"@modelcontextprotocol/client": "^2.4.0",
|
|
51
52
|
"@types/node": "^22.20.5",
|
|
52
|
-
"mnemocyte": "1.
|
|
53
|
+
"mnemocyte": "1.4.0",
|
|
53
54
|
"publint": "0.3.25",
|
|
54
55
|
"tsdown": "0.23.1",
|
|
55
56
|
"typescript": "^6.0.3",
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"checktypes": "tsc --noEmit --project tsconfig.build.json && tsc --noEmit",
|
|
64
65
|
"test": "pnpm build && vitest run",
|
|
65
66
|
"test:unit": "vitest run",
|
|
66
|
-
"lint:package": "pnpm build && node scripts/check-package.
|
|
67
|
+
"lint:package": "pnpm build && node scripts/check-package.ts",
|
|
67
68
|
"pack:check": "pnpm pack --dry-run"
|
|
68
69
|
}
|
|
69
70
|
}
|