@codemem/mcp 0.31.4 → 0.32.1
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/audit.d.ts +54 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/content.d.ts +13 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/http.d.ts +38 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +1049 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +2 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -602
- package/dist/memory-access.d.ts.map +1 -1
- package/dist/memory-kinds.d.ts +2 -0
- package/dist/memory-kinds.d.ts.map +1 -0
- package/dist/oauth.d.ts +176 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oidc.d.ts +35 -0
- package/dist/oidc.d.ts.map +1 -0
- package/dist/project-scope.d.ts +4 -0
- package/dist/project-scope.d.ts.map +1 -1
- package/dist/provider.d.ts +51 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/schemas.d.ts +36 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/server-Djvf0Yik.js +488 -0
- package/dist/server-Djvf0Yik.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/stdio.d.ts +9 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +69 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tool-context.d.ts +12 -0
- package/dist/tool-context.d.ts.map +1 -0
- package/dist/tools/items.d.ts +4 -0
- package/dist/tools/items.d.ts.map +1 -0
- package/dist/tools/learn.d.ts +3 -0
- package/dist/tools/learn.d.ts.map +1 -0
- package/dist/tools/schema.d.ts +3 -0
- package/dist/tools/schema.d.ts.map +1 -0
- package/dist/tools/search.d.ts +4 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/timeline.d.ts +4 -0
- package/dist/tools/timeline.d.ts.map +1 -0
- package/package.json +19 -7
- package/dist/index.js.map +0 -1
package/dist/stdio.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as e } from "./server-Djvf0Yik.js";
|
|
3
|
+
import { MemoryStore as t, resolveDbPath as n } from "@codemem/core";
|
|
4
|
+
import { spawn as r } from "node:child_process";
|
|
5
|
+
import { existsSync as i } from "node:fs";
|
|
6
|
+
import { dirname as a, join as o } from "node:path";
|
|
7
|
+
import { StdioServerTransport as s } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
//#region src/stdio.ts
|
|
9
|
+
var c = process.env.CODEMEM_VIEWER_HOST ?? "127.0.0.1", l = process.env.CODEMEM_VIEWER_PORT ?? "38888";
|
|
10
|
+
function u() {
|
|
11
|
+
let e = [], t = a(import.meta.dirname ?? ".");
|
|
12
|
+
e.push(o(t, "..", "cli", "dist", "index.js")), e.push(o(t, "..", ".bin", "codemem")), e.push(o(t, "..", "..", ".bin", "codemem"));
|
|
13
|
+
for (let t of e) if (i(t)) return t;
|
|
14
|
+
return "codemem";
|
|
15
|
+
}
|
|
16
|
+
async function d() {
|
|
17
|
+
try {
|
|
18
|
+
let e = `http://${c}:${l}/api/health`;
|
|
19
|
+
return (await fetch(e, { signal: AbortSignal.timeout(2e3) })).ok;
|
|
20
|
+
} catch {
|
|
21
|
+
return !1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function f() {
|
|
25
|
+
if (process.env.CODEMEM_VIEWER === "0" || process.env.CODEMEM_VIEWER_AUTO === "0" || await d()) return;
|
|
26
|
+
let e = u();
|
|
27
|
+
if (e) try {
|
|
28
|
+
let t = e.endsWith(".js"), n = t ? process.execPath : e, i = t ? [
|
|
29
|
+
e,
|
|
30
|
+
"serve",
|
|
31
|
+
"start"
|
|
32
|
+
] : ["serve", "start"];
|
|
33
|
+
c !== "127.0.0.1" && i.push("--host", c), l !== "38888" && i.push("--port", l);
|
|
34
|
+
let a = r(n, i, {
|
|
35
|
+
detached: !0,
|
|
36
|
+
stdio: "ignore",
|
|
37
|
+
env: {
|
|
38
|
+
...process.env,
|
|
39
|
+
CODEMEM_PLUGIN_IGNORE: "1"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
a.on("error", () => {}), a.unref();
|
|
43
|
+
for (let e = 0; e < 5; e++) if (await new Promise((e) => setTimeout(e, 1e3)), await d()) return;
|
|
44
|
+
} catch {}
|
|
45
|
+
}
|
|
46
|
+
async function p() {
|
|
47
|
+
let r = new t(n());
|
|
48
|
+
try {
|
|
49
|
+
f().catch(() => {});
|
|
50
|
+
let t = e(r), n = new s(), i = () => {
|
|
51
|
+
try {
|
|
52
|
+
r.close();
|
|
53
|
+
} catch {}
|
|
54
|
+
process.exit(0);
|
|
55
|
+
};
|
|
56
|
+
process.on("SIGINT", i), process.on("SIGTERM", i), await t.connect(n);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
try {
|
|
59
|
+
r.close();
|
|
60
|
+
} catch {}
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
p().catch((e) => {
|
|
65
|
+
console.error("codemem MCP server failed to start:", e), process.exit(1);
|
|
66
|
+
});
|
|
67
|
+
//#endregion
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.js","names":[],"sources":["../src/stdio.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * @codemem/mcp — MCP stdio server bootstrap.\n *\n * Runs as a separate process spawned by the host (OpenCode/Claude).\n * Owns its own better-sqlite3 connection. Communicates via stdio JSON-RPC.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { MemoryStore, resolveDbPath } from \"@codemem/core\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createCodememMcpServer } from \"./server.js\";\n\n/** Default viewer host/port for health checks. */\nconst VIEWER_HOST = process.env.CODEMEM_VIEWER_HOST ?? \"127.0.0.1\";\nconst VIEWER_PORT = process.env.CODEMEM_VIEWER_PORT ?? \"38888\";\n\n/** Resolve the `codemem` CLI binary path. Checks package-local paths first, then PATH. */\nfunction resolveCliPath(): string | null {\n\t// When installed via npm/npx, the MCP server and CLI share node_modules.\n\t// Walk up from this file to find the CLI's bin entry.\n\tconst candidates: string[] = [];\n\tconst selfDir = dirname(import.meta.dirname ?? \".\");\n\t// Monorepo dev: sibling package\n\tcandidates.push(join(selfDir, \"..\", \"cli\", \"dist\", \"index.js\"));\n\t// npm install: node_modules/.bin/codemem\n\tcandidates.push(join(selfDir, \"..\", \".bin\", \"codemem\"));\n\t// npm install: deeper node_modules\n\tcandidates.push(join(selfDir, \"..\", \"..\", \".bin\", \"codemem\"));\n\tfor (const p of candidates) {\n\t\tif (existsSync(p)) return p;\n\t}\n\t// Fall back to PATH\n\treturn \"codemem\";\n}\n\n/** Check if the viewer is already running. */\nasync function isViewerHealthy(): Promise<boolean> {\n\ttry {\n\t\tconst url = `http://${VIEWER_HOST}:${VIEWER_PORT}/api/health`;\n\t\tconst response = await fetch(url, { signal: AbortSignal.timeout(2_000) });\n\t\treturn response.ok;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Attempt to start the viewer server as a detached background process.\n * Best-effort: failures are logged to stderr but never block MCP startup.\n */\nasync function ensureViewer(): Promise<void> {\n\tif (process.env.CODEMEM_VIEWER === \"0\" || process.env.CODEMEM_VIEWER_AUTO === \"0\") return;\n\n\tif (await isViewerHealthy()) return;\n\n\tconst cli = resolveCliPath();\n\tif (!cli) return;\n\n\ttry {\n\t\t// If the resolved path is a .js file, run it with node.\n\t\t// Otherwise it's a bin script that can run directly.\n\t\tconst isJsFile = cli.endsWith(\".js\");\n\t\tconst cmd = isJsFile ? process.execPath : cli;\n\t\tconst args = isJsFile ? [cli, \"serve\", \"start\"] : [\"serve\", \"start\"];\n\t\t// Pass non-default host/port so the spawned viewer matches what we health-check.\n\t\tif (VIEWER_HOST !== \"127.0.0.1\") args.push(\"--host\", VIEWER_HOST);\n\t\tif (VIEWER_PORT !== \"38888\") args.push(\"--port\", VIEWER_PORT);\n\n\t\tconst child = spawn(cmd, args, {\n\t\t\tdetached: true,\n\t\t\tstdio: \"ignore\",\n\t\t\tenv: { ...process.env, CODEMEM_PLUGIN_IGNORE: \"1\" },\n\t\t});\n\t\tchild.on(\"error\", () => {}); // swallow — best effort\n\t\tchild.unref();\n\n\t\t// Brief health check loop — don't block for long\n\t\tfor (let i = 0; i < 5; i++) {\n\t\t\tawait new Promise((r) => setTimeout(r, 1_000));\n\t\t\tif (await isViewerHealthy()) return;\n\t\t}\n\t} catch {\n\t\t// Best effort — MCP server continues regardless\n\t}\n}\n\nasync function main() {\n\tconst dbPath = resolveDbPath();\n\tconst store = new MemoryStore(dbPath);\n\n\ttry {\n\t\t// Auto-start viewer in background (belt and suspenders with any hook-based start)\n\t\tensureViewer().catch(() => {});\n\n\t\tconst server = createCodememMcpServer(store);\n\t\tconst transport = new StdioServerTransport();\n\n\t\tconst shutdown = () => {\n\t\t\ttry {\n\t\t\t\tstore.close();\n\t\t\t} catch {\n\t\t\t\t// Best effort — process is exiting\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t};\n\n\t\tprocess.on(\"SIGINT\", shutdown);\n\t\tprocess.on(\"SIGTERM\", shutdown);\n\n\t\tawait server.connect(transport);\n\t} catch (err) {\n\t\t// Close the store before bubbling so a startup failure does not leave\n\t\t// the SQLite journal behind. Signal handlers are not yet attached if we\n\t\t// crash before `server.connect` resolves.\n\t\ttry {\n\t\t\tstore.close();\n\t\t} catch {\n\t\t\t// best effort\n\t\t}\n\t\tthrow err;\n\t}\n}\n\nmain().catch((err) => {\n\tconsole.error(\"codemem MCP server failed to start:\", err);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;;AAiBA,IAAM,IAAc,QAAQ,IAAI,uBAAuB,aACjD,IAA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B,CAAE;SAEvB;;AAKT,eAAe,IAAO;CAErB,IAAM,IAAQ,IAAI,EADH,GACe,CAAO;AAErC,KAAI;AAEH,KAAc,CAAC,YAAY,GAAG;EAE9B,IAAM,IAAS,EAAuB,EAAM,EACtC,IAAY,IAAI,GAAsB,EAEtC,UAAiB;AACtB,OAAI;AACH,MAAM,OAAO;WACN;AAGR,WAAQ,KAAK,EAAE;;AAMhB,EAHA,QAAQ,GAAG,UAAU,EAAS,EAC9B,QAAQ,GAAG,WAAW,EAAS,EAE/B,MAAM,EAAO,QAAQ,EAAU;UACvB,GAAK;AAIb,MAAI;AACH,KAAM,OAAO;UACN;AAGR,QAAM;;;AAIR,GAAM,CAAC,OAAO,MAAQ;AAErB,CADA,QAAQ,MAAM,uCAAuC,EAAI,EACzD,QAAQ,KAAK,EAAE;EACd"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MemoryStore } from "@codemem/core";
|
|
2
|
+
export interface CodememMcpServerOptions {
|
|
3
|
+
defaultProject?: string | null;
|
|
4
|
+
resolveDefaultProject?: () => string | null;
|
|
5
|
+
envProject?: string | null;
|
|
6
|
+
}
|
|
7
|
+
export interface ToolRegistrationContext {
|
|
8
|
+
store: MemoryStore;
|
|
9
|
+
defaultProject: () => string | null;
|
|
10
|
+
envProject: () => string | null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=tool-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-context.d.ts","sourceRoot":"","sources":["../src/tool-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,WAAW,uBAAuB;IACvC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,cAAc,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACpC,UAAU,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;CAChC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ToolRegistrationContext } from "../tool-context.js";
|
|
3
|
+
export declare function registerItemTools(server: McpServer, context: ToolRegistrationContext): void;
|
|
4
|
+
//# sourceMappingURL=items.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../src/tools/items.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAWzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAyF3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learn.d.ts","sourceRoot":"","sources":["../../src/tools/learn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA0F1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/tools/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAwB3D"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ToolRegistrationContext } from "../tool-context.js";
|
|
3
|
+
export declare function registerSearchTools(server: McpServer, context: ToolRegistrationContext): void;
|
|
4
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CA0J7F"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ToolRegistrationContext } from "../tool-context.js";
|
|
3
|
+
export declare function registerTimelineTools(server: McpServer, context: ToolRegistrationContext): void;
|
|
4
|
+
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/tools/timeline.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAmL/F"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"source": "./src/index.ts",
|
|
9
|
-
"import": "./dist/index.js"
|
|
10
|
-
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./stdio": {
|
|
13
|
+
"types": "./dist/stdio.d.ts",
|
|
14
|
+
"source": "./src/stdio.ts",
|
|
15
|
+
"import": "./dist/stdio.js"
|
|
16
|
+
},
|
|
17
|
+
"./http": {
|
|
18
|
+
"types": "./dist/http.d.ts",
|
|
19
|
+
"source": "./src/http.ts",
|
|
20
|
+
"import": "./dist/http.js"
|
|
11
21
|
}
|
|
12
22
|
},
|
|
13
23
|
"bin": {
|
|
14
|
-
"codemem-mcp-ts": "./dist/
|
|
24
|
+
"codemem-mcp-ts": "./dist/stdio.js"
|
|
15
25
|
},
|
|
16
26
|
"files": [
|
|
17
27
|
"dist/"
|
|
18
28
|
],
|
|
19
29
|
"dependencies": {
|
|
20
30
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
31
|
+
"express": "^5.2.1",
|
|
21
32
|
"zod": "^4.4.2",
|
|
22
|
-
"@codemem/core": "^0.
|
|
33
|
+
"@codemem/core": "^0.32.1"
|
|
23
34
|
},
|
|
24
35
|
"devDependencies": {
|
|
25
|
-
"@types/
|
|
36
|
+
"@types/express": "^5.0.6",
|
|
37
|
+
"@types/node": "^24.0.0",
|
|
26
38
|
"typescript": "^6.0.3",
|
|
27
39
|
"vite": "^8.0.10",
|
|
28
40
|
"vitest": "^4.1.5"
|
|
@@ -41,7 +53,7 @@
|
|
|
41
53
|
},
|
|
42
54
|
"scripts": {
|
|
43
55
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
44
|
-
"build": "pnpm exec vite build
|
|
56
|
+
"build": "pnpm exec vite build && pnpm exec tsc --build --force",
|
|
45
57
|
"typecheck": "pnpm exec tsc --noEmit"
|
|
46
58
|
}
|
|
47
59
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/memory-access.ts","../src/project-scope.ts","../src/index.ts"],"sourcesContent":["import {\n\ttype MemoryFilters,\n\ttype MemoryItemResponse,\n\ttype MemoryStore,\n\ttoJson,\n} from \"@codemem/core\";\n\nexport function getMemoryForMcp(\n\tstore: MemoryStore,\n\tmemoryId: number,\n\tfilters?: MemoryFilters,\n): MemoryItemResponse | null {\n\tconst rows = store.timeline(null, memoryId, 0, 0, filters ?? null);\n\treturn rows.find((row) => row.id === memoryId) ?? null;\n}\n\nexport function getManyForMcp(\n\tstore: MemoryStore,\n\tids: number[],\n\tfilters?: MemoryFilters,\n): MemoryItemResponse[] {\n\tif (ids.length === 0) return [];\n\tconst results: MemoryItemResponse[] = [];\n\tfor (const id of ids) {\n\t\tconst item = getMemoryForMcp(store, id, filters);\n\t\tif (item) results.push(item);\n\t}\n\treturn results;\n}\n\nexport function forgetMemoryForMcp(\n\tstore: MemoryStore,\n\tmemoryId: number,\n\tfilters?: MemoryFilters,\n): boolean {\n\tconst item = getMemoryForMcp(store, memoryId, filters);\n\tif (!item) return false;\n\tstore.forget(memoryId);\n\treturn true;\n}\n\nexport interface RememberMemoryForMcpInput {\n\tkind: string;\n\ttitle: string;\n\tbody: string;\n\tconfidence: number;\n\tproject?: string | null;\n}\n\nexport interface RememberMemoryForMcpContext {\n\tcwd?: string;\n\tuser?: string;\n\tenvProject?: string | null;\n\tnow?: () => string;\n}\n\nexport function rememberMemoryForMcp(\n\tstore: MemoryStore,\n\tinput: RememberMemoryForMcpInput,\n\tcontext: RememberMemoryForMcpContext = {},\n): { memId: number; title: string; body: string } {\n\treturn store.db.transaction(() => {\n\t\tconst now = context.now?.() ?? new Date().toISOString();\n\t\tconst user = context.user ?? process.env.USER ?? \"unknown\";\n\t\tconst cwd = context.cwd ?? process.cwd();\n\t\tconst project = input.project ?? context.envProject ?? null;\n\n\t\tconst sessionInfo = store.db\n\t\t\t.prepare(\n\t\t\t\t`INSERT INTO sessions(started_at, ended_at, cwd, project, user, tool_version, metadata_json)\n\t\t\t\t VALUES (?, ?, ?, ?, ?, ?, ?)`,\n\t\t\t)\n\t\t\t.run(now, now, cwd, project, user, \"mcp-ts\", toJson({ mcp: true }));\n\t\tconst sessionId = Number(sessionInfo.lastInsertRowid);\n\n\t\tconst memId = store.remember(sessionId, input.kind, input.title, input.body, input.confidence);\n\t\tif (!getMemoryForMcp(store, memId)) {\n\t\t\tthrow new Error(\"unauthorized_scope\");\n\t\t}\n\n\t\tstore.db\n\t\t\t.prepare(\"UPDATE sessions SET ended_at = ?, metadata_json = ? WHERE id = ?\")\n\t\t\t.run(context.now?.() ?? new Date().toISOString(), toJson({ mcp: true }), sessionId);\n\n\t\treturn { memId, title: input.title, body: input.body };\n\t})();\n}\n","import { type MemoryFilters, resolveProject } from \"@codemem/core\";\n\nexport function resolveDefaultProject(): string | null {\n\tconst project = process.env.CODEMEM_PROJECT?.trim();\n\treturn project || resolveProject(process.cwd());\n}\n\nexport function buildFilters(\n\traw: Record<string, unknown>,\n\tdefaultProject = resolveDefaultProject(),\n): MemoryFilters | undefined {\n\tconst filters: MemoryFilters = {};\n\tlet hasAny = false;\n\n\tconst explicitProject = typeof raw.project === \"string\" ? raw.project.trim() : undefined;\n\tconst resolvedProject = explicitProject || defaultProject || undefined;\n\tif (resolvedProject) {\n\t\tfilters.project = resolvedProject;\n\t\thasAny = true;\n\t}\n\n\tfor (const key of [\n\t\t\"kind\",\n\t\t\"visibility\",\n\t\t\"scope_id\",\n\t\t\"include_scope_ids\",\n\t\t\"exclude_scope_ids\",\n\t\t\"include_visibility\",\n\t\t\"exclude_visibility\",\n\t\t\"include_workspace_ids\",\n\t\t\"exclude_workspace_ids\",\n\t\t\"include_workspace_kinds\",\n\t\t\"exclude_workspace_kinds\",\n\t\t\"include_actor_ids\",\n\t\t\"exclude_actor_ids\",\n\t\t\"include_trust_states\",\n\t\t\"exclude_trust_states\",\n\t\t\"ownership_scope\",\n\t\t\"personal_first\",\n\t\t\"trust_bias\",\n\t\t\"widen_shared_when_weak\",\n\t\t\"widen_shared_min_personal_results\",\n\t\t\"widen_shared_min_personal_score\",\n\t] as const) {\n\t\tconst val = raw[key];\n\t\tif (val !== undefined && val !== null) {\n\t\t\t(filters as Record<string, unknown>)[key] = val;\n\t\t\thasAny = true;\n\t\t}\n\t}\n\n\treturn hasAny ? filters : undefined;\n}\n","#!/usr/bin/env node\n\n/**\n * @codemem/mcp — MCP stdio server.\n *\n * Runs as a separate process spawned by the host (OpenCode/Claude).\n * Owns its own better-sqlite3 connection. Communicates via stdio JSON-RPC.\n *\n * Port of codemem/mcp_server.py — all 13 tools.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport {\n\tdedupeOrderedIds,\n\ttype MemoryItemResponse,\n\ttype MemoryResult,\n\tMemoryStore,\n\tprojectMatchesFilter,\n\tresolveDbPath,\n\tstoreVectors,\n\tVERSION,\n} from \"@codemem/core\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { z } from \"zod\";\nimport {\n\tforgetMemoryForMcp,\n\tgetManyForMcp,\n\tgetMemoryForMcp,\n\trememberMemoryForMcp,\n} from \"./memory-access.js\";\nimport { buildFilters, resolveDefaultProject } from \"./project-scope.js\";\n\n// ---------------------------------------------------------------------------\n// Static data\n// ---------------------------------------------------------------------------\n\nconst MEMORY_KINDS: Record<string, string> = {\n\tdiscovery: \"Something learned about the codebase, architecture, or tools\",\n\tchange: \"A code change that was made\",\n\tfeature: \"A new feature that was implemented\",\n\tbugfix: \"A bug that was found and fixed\",\n\trefactor: \"Code that was refactored or restructured\",\n\tdecision: \"A design or architecture decision\",\n\texploration: \"An experiment or investigation (may not have shipped)\",\n};\n\n// ---------------------------------------------------------------------------\n// Shared zod filter schema (spread into each tool that accepts filters)\n// ---------------------------------------------------------------------------\n\nconst scopeFilterSchema = {\n\tscope_id: z.string().optional().describe(\"Filter by a single sharing domain scope_id\"),\n\tinclude_scope_ids: z.array(z.string()).optional().describe(\"Sharing domain scope_ids to include\"),\n\texclude_scope_ids: z.array(z.string()).optional().describe(\"Sharing domain scope_ids to exclude\"),\n};\n\nconst filterSchema = {\n\tkind: z.string().optional().describe(\"Filter by memory kind\"),\n\tproject: z.string().optional().describe(\"Filter by project scope (matches sessions.project)\"),\n\t...scopeFilterSchema,\n\tvisibility: z.array(z.string()).optional(),\n\tinclude_visibility: z.array(z.string()).optional(),\n\texclude_visibility: z.array(z.string()).optional(),\n\tinclude_workspace_ids: z.array(z.string()).optional(),\n\texclude_workspace_ids: z.array(z.string()).optional(),\n\tinclude_workspace_kinds: z.array(z.string()).optional(),\n\texclude_workspace_kinds: z.array(z.string()).optional(),\n\tinclude_actor_ids: z.array(z.string()).optional(),\n\texclude_actor_ids: z.array(z.string()).optional(),\n\tinclude_trust_states: z.array(z.string()).optional(),\n\texclude_trust_states: z.array(z.string()).optional(),\n\townership_scope: z.string().optional(),\n\tpersonal_first: z.union([z.boolean(), z.string()]).optional(),\n\ttrust_bias: z.string().optional(),\n\twiden_shared_when_weak: z.union([z.boolean(), z.string()]).optional(),\n\twiden_shared_min_personal_results: z.number().int().optional(),\n\twiden_shared_min_personal_score: z.number().optional(),\n};\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nconst defaultProject = resolveDefaultProject();\n\n/** Wrap a JSON result into the MCP text content envelope. */\nfunction jsonContent(data: unknown) {\n\treturn { content: [{ type: \"text\" as const, text: JSON.stringify(data) }] };\n}\n\n/** Wrap an error message into the MCP text content envelope. */\nfunction errorContent(message: string) {\n\treturn { content: [{ type: \"text\" as const, text: JSON.stringify({ error: message }) }] };\n}\n\n// ---------------------------------------------------------------------------\n// Viewer autostart\n// ---------------------------------------------------------------------------\n\n/** Default viewer host/port for health checks. */\nconst VIEWER_HOST = process.env.CODEMEM_VIEWER_HOST ?? \"127.0.0.1\";\nconst VIEWER_PORT = process.env.CODEMEM_VIEWER_PORT ?? \"38888\";\n\n/** Resolve the `codemem` CLI binary path. Checks package-local paths first, then PATH. */\nfunction resolveCliPath(): string | null {\n\t// When installed via npm/npx, the MCP server and CLI share node_modules.\n\t// Walk up from this file to find the CLI's bin entry.\n\tconst candidates: string[] = [];\n\tconst selfDir = dirname(import.meta.dirname ?? \".\");\n\t// Monorepo dev: sibling package\n\tcandidates.push(join(selfDir, \"..\", \"cli\", \"dist\", \"index.js\"));\n\t// npm install: node_modules/.bin/codemem\n\tcandidates.push(join(selfDir, \"..\", \".bin\", \"codemem\"));\n\t// npm install: deeper node_modules\n\tcandidates.push(join(selfDir, \"..\", \"..\", \".bin\", \"codemem\"));\n\tfor (const p of candidates) {\n\t\tif (existsSync(p)) return p;\n\t}\n\t// Fall back to PATH\n\treturn \"codemem\";\n}\n\n/** Check if the viewer is already running. */\nasync function isViewerHealthy(): Promise<boolean> {\n\ttry {\n\t\tconst url = `http://${VIEWER_HOST}:${VIEWER_PORT}/api/health`;\n\t\tconst response = await fetch(url, { signal: AbortSignal.timeout(2_000) });\n\t\treturn response.ok;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Attempt to start the viewer server as a detached background process.\n * Best-effort: failures are logged to stderr but never block MCP startup.\n */\nasync function ensureViewer(): Promise<void> {\n\tif (process.env.CODEMEM_VIEWER === \"0\" || process.env.CODEMEM_VIEWER_AUTO === \"0\") return;\n\n\tif (await isViewerHealthy()) return;\n\n\tconst cli = resolveCliPath();\n\tif (!cli) return;\n\n\ttry {\n\t\t// If the resolved path is a .js file, run it with node.\n\t\t// Otherwise it's a bin script that can run directly.\n\t\tconst isJsFile = cli.endsWith(\".js\");\n\t\tconst cmd = isJsFile ? process.execPath : cli;\n\t\tconst args = isJsFile ? [cli, \"serve\", \"start\"] : [\"serve\", \"start\"];\n\t\t// Pass non-default host/port so the spawned viewer matches what we health-check.\n\t\tif (VIEWER_HOST !== \"127.0.0.1\") args.push(\"--host\", VIEWER_HOST);\n\t\tif (VIEWER_PORT !== \"38888\") args.push(\"--port\", VIEWER_PORT);\n\n\t\tconst child = spawn(cmd, args, {\n\t\t\tdetached: true,\n\t\t\tstdio: \"ignore\",\n\t\t\tenv: { ...process.env, CODEMEM_PLUGIN_IGNORE: \"1\" },\n\t\t});\n\t\tchild.on(\"error\", () => {}); // swallow — best effort\n\t\tchild.unref();\n\n\t\t// Brief health check loop — don't block for long\n\t\tfor (let i = 0; i < 5; i++) {\n\t\t\tawait new Promise((r) => setTimeout(r, 1_000));\n\t\t\tif (await isViewerHealthy()) return;\n\t\t}\n\t} catch {\n\t\t// Best effort — MCP server continues regardless\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Server bootstrap\n// ---------------------------------------------------------------------------\n\nasync function main() {\n\tconst dbPath = resolveDbPath();\n\tconst store = new MemoryStore(dbPath);\n\n\t// Auto-start viewer in background (belt and suspenders with any hook-based start)\n\tensureViewer().catch(() => {});\n\n\tconst server = new McpServer({ name: \"codemem\", version: VERSION });\n\n\t// -------------------------------------------------------------------\n\t// 1. memory_search\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_search\",\n\t\t\"Search memories by text query. Returns full body text for each match.\",\n\t\t{\n\t\t\tquery: z.string().describe(\"Search query\"),\n\t\t\tlimit: z.number().int().min(1).max(50).default(5).describe(\"Max results\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst items = store.search(args.query, args.limit, filters);\n\t\t\t\treturn jsonContent({\n\t\t\t\t\titems: items.map((m: MemoryResult) => ({\n\t\t\t\t\t\tid: m.id,\n\t\t\t\t\t\ttitle: m.title,\n\t\t\t\t\t\tkind: m.kind,\n\t\t\t\t\t\tbody: m.body_text,\n\t\t\t\t\t\tconfidence: m.confidence,\n\t\t\t\t\t\tscore: m.score,\n\t\t\t\t\t\tsession_id: m.session_id,\n\t\t\t\t\t\tmetadata: m.metadata,\n\t\t\t\t\t})),\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 2. memory_search_index\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_search_index\",\n\t\t\"Search memories by text query. Returns compact index entries (no body) for browsing.\",\n\t\t{\n\t\t\tquery: z.string().describe(\"Search query\"),\n\t\t\tlimit: z.number().int().min(1).max(50).default(8).describe(\"Max results\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst items = store.search(args.query, args.limit, filters);\n\t\t\t\treturn jsonContent({\n\t\t\t\t\titems: items.map((m: MemoryResult) => ({\n\t\t\t\t\t\tid: m.id,\n\t\t\t\t\t\tkind: m.kind,\n\t\t\t\t\t\ttitle: m.title,\n\t\t\t\t\t\tscore: m.score,\n\t\t\t\t\t\tcreated_at: m.created_at,\n\t\t\t\t\t\tsession_id: m.session_id,\n\t\t\t\t\t\tmetadata: m.metadata,\n\t\t\t\t\t})),\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 3. memory_timeline\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_timeline\",\n\t\t\"Get a chronological window of memories around an anchor (by ID or query).\",\n\t\t{\n\t\t\tquery: z.string().optional().describe(\"Search query to find anchor\"),\n\t\t\tmemory_id: z.number().int().optional().describe(\"Anchor memory ID\"),\n\t\t\tdepth_before: z.number().int().min(0).default(3).describe(\"Items before anchor\"),\n\t\t\tdepth_after: z.number().int().min(0).default(3).describe(\"Items after anchor\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst items = store.timeline(\n\t\t\t\t\targs.query ?? null,\n\t\t\t\t\targs.memory_id ?? null,\n\t\t\t\t\targs.depth_before,\n\t\t\t\t\targs.depth_after,\n\t\t\t\t\tfilters,\n\t\t\t\t);\n\t\t\t\treturn jsonContent({ items });\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 4. memory_explain\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_explain\",\n\t\t\"Explain search results with detailed scoring breakdown.\",\n\t\t{\n\t\t\tquery: z.string().optional().describe(\"Search query\"),\n\t\t\tids: z.array(z.number().int()).max(200).optional().describe(\"Specific memory IDs to explain\"),\n\t\t\tlimit: z.number().int().min(1).max(50).default(10).describe(\"Max results\"),\n\t\t\tinclude_pack_context: z.boolean().default(false).describe(\"Include formatted pack context\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst result = store.explain(args.query ?? null, args.ids ?? null, args.limit, filters, {\n\t\t\t\t\tincludePackContext: args.include_pack_context,\n\t\t\t\t});\n\t\t\t\treturn jsonContent(result);\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 5. memory_expand\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_expand\",\n\t\t\"Fetch memories by ID with surrounding timeline context.\",\n\t\t{\n\t\t\tids: z\n\t\t\t\t.array(z.union([z.number(), z.string()]))\n\t\t\t\t.max(200)\n\t\t\t\t.describe(\"Memory IDs to expand\"),\n\t\t\tdepth_before: z.number().int().min(0).default(3).describe(\"Timeline items before\"),\n\t\t\tdepth_after: z.number().int().min(0).default(3).describe(\"Timeline items after\"),\n\t\t\tinclude_observations: z.boolean().default(false).describe(\"Include full observation details\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\t// Python: project if project is not None else default_project\n\t\t\t\t// Explicit \"\" clears project scoping; only fall back to default when undefined.\n\t\t\t\tconst filterDefaultProject =\n\t\t\t\t\targs.project !== undefined && !args.project.trim() ? null : defaultProject;\n\t\t\t\tconst filters = buildFilters(args, filterDefaultProject);\n\t\t\t\tconst resolvedProject = filters?.project ?? null;\n\t\t\t\tconst { ordered: orderedIds, invalid: invalidIds } = dedupeOrderedIds(args.ids);\n\t\t\t\tconst errors: Array<Record<string, unknown>> = [];\n\n\t\t\t\tif (invalidIds.length > 0) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"INVALID_ARGUMENT\",\n\t\t\t\t\t\tfield: \"ids\",\n\t\t\t\t\t\tmessage: \"some ids are not valid integers\",\n\t\t\t\t\t\tids: invalidIds,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst missingNotFound: number[] = [];\n\t\t\t\tconst missingProjectMismatch: number[] = [];\n\t\t\t\tconst missingFilterMismatch: number[] = [];\n\t\t\t\tconst anchors: MemoryItemResponse[] = [];\n\t\t\t\tconst timelineItems: MemoryItemResponse[] = [];\n\t\t\t\tconst timelineSeen = new Set<number>();\n\t\t\t\tconst sessionProjects = new Map<number, string | null>();\n\n\t\t\t\tfor (const memoryId of orderedIds) {\n\t\t\t\t\tconst item = store.get(memoryId);\n\t\t\t\t\tif (!item?.active) {\n\t\t\t\t\t\tmissingNotFound.push(memoryId);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst sessionId = item.session_id;\n\t\t\t\t\tif (resolvedProject && sessionId > 0) {\n\t\t\t\t\t\tif (!sessionProjects.has(sessionId)) {\n\t\t\t\t\t\t\tconst row = store.db\n\t\t\t\t\t\t\t\t.prepare(\"SELECT project FROM sessions WHERE id = ? LIMIT 1\")\n\t\t\t\t\t\t\t\t.get(sessionId) as { project: string | null } | undefined;\n\t\t\t\t\t\t\tsessionProjects.set(sessionId, typeof row?.project === \"string\" ? row.project : null);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!projectMatchesFilter(resolvedProject, sessionProjects.get(sessionId) ?? null)) {\n\t\t\t\t\t\t\tmissingProjectMismatch.push(memoryId);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (resolvedProject && sessionId <= 0) {\n\t\t\t\t\t\tmissingProjectMismatch.push(memoryId);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst expanded = store.timeline(\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\tmemoryId,\n\t\t\t\t\t\targs.depth_before,\n\t\t\t\t\t\targs.depth_after,\n\t\t\t\t\t\tfilters,\n\t\t\t\t\t);\n\t\t\t\t\tconst anchor = expanded.find((expandedItem) => expandedItem.id === memoryId);\n\t\t\t\t\tif (!anchor) {\n\t\t\t\t\t\tmissingFilterMismatch.push(memoryId);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tanchors.push(anchor);\n\t\t\t\t\tfor (const expandedItem of expanded) {\n\t\t\t\t\t\tconst expandedId = expandedItem.id;\n\t\t\t\t\t\tif (expandedId <= 0 || timelineSeen.has(expandedId)) continue;\n\t\t\t\t\t\ttimelineSeen.add(expandedId);\n\t\t\t\t\t\ttimelineItems.push(expandedItem);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (missingNotFound.length > 0) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"NOT_FOUND\",\n\t\t\t\t\t\tfield: \"ids\",\n\t\t\t\t\t\tmessage: \"some requested ids were not found\",\n\t\t\t\t\t\tids: missingNotFound,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (missingProjectMismatch.length > 0) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"PROJECT_MISMATCH\",\n\t\t\t\t\t\tfield: \"project\",\n\t\t\t\t\t\tmessage: \"some requested ids are outside the requested project scope\",\n\t\t\t\t\t\tids: missingProjectMismatch,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (missingFilterMismatch.length > 0) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tcode: \"FILTER_MISMATCH\",\n\t\t\t\t\t\tfield: \"filters\",\n\t\t\t\t\t\tmessage: \"some requested ids are outside the requested filters\",\n\t\t\t\t\t\tids: missingFilterMismatch,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Collect full observations if requested\n\t\t\t\tlet observations: MemoryItemResponse[] = [];\n\t\t\t\tif (args.include_observations) {\n\t\t\t\t\tconst observationSeen = new Set<number>();\n\t\t\t\t\tconst observationIds: number[] = [];\n\t\t\t\t\tfor (const item of [...anchors, ...timelineItems]) {\n\t\t\t\t\t\tif (item.id > 0 && !observationSeen.has(item.id)) {\n\t\t\t\t\t\t\tobservationSeen.add(item.id);\n\t\t\t\t\t\t\tobservationIds.push(item.id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tobservations = getManyForMcp(store, observationIds, filters);\n\t\t\t\t}\n\n\t\t\t\treturn jsonContent({\n\t\t\t\t\tanchors,\n\t\t\t\t\ttimeline: timelineItems,\n\t\t\t\t\tobservations,\n\t\t\t\t\tmissing_ids: orderedIds.filter(\n\t\t\t\t\t\t(memoryId: number) =>\n\t\t\t\t\t\t\tmissingNotFound.includes(memoryId) ||\n\t\t\t\t\t\t\tmissingProjectMismatch.includes(memoryId) ||\n\t\t\t\t\t\t\tmissingFilterMismatch.includes(memoryId),\n\t\t\t\t\t),\n\t\t\t\t\terrors,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tproject: resolvedProject,\n\t\t\t\t\t\trequested_ids_count: orderedIds.length,\n\t\t\t\t\t\treturned_anchor_count: anchors.length,\n\t\t\t\t\t\ttimeline_count: timelineItems.length,\n\t\t\t\t\t\tinclude_observations: args.include_observations,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 6. memory_get\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_get\",\n\t\t\"Fetch a single memory item by ID.\",\n\t\t{\n\t\t\tmemory_id: z.number().int().describe(\"Memory ID\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst item = getMemoryForMcp(store, args.memory_id, buildFilters(args, null));\n\t\t\t\tif (!item) return errorContent(\"not_found\");\n\t\t\t\treturn jsonContent(item);\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 7. memory_get_observations\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_get_observations\",\n\t\t\"Fetch multiple memory items by their IDs.\",\n\t\t{\n\t\t\tids: z.array(z.number().int()).max(200).describe(\"Memory IDs to fetch\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst items = getManyForMcp(store, args.ids, buildFilters(args, null));\n\t\t\t\treturn jsonContent({ items });\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 8. memory_recent\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_recent\",\n\t\t\"Return recent memories, newest first.\",\n\t\t{\n\t\t\tlimit: z.number().int().min(1).max(100).default(8).describe(\"Max results\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst items = store.recent(args.limit, filters);\n\t\t\t\treturn jsonContent({ items });\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 9. memory_pack\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_pack\",\n\t\t\"Build a formatted memory pack from search results — quick one-shot context block.\",\n\t\t{\n\t\t\tcontext: z.string().describe(\"Context description to search for\"),\n\t\t\tlimit: z.number().int().min(1).max(50).optional().describe(\"Max items to include\"),\n\t\t\tcompact: z\n\t\t\t\t.boolean()\n\t\t\t\t.optional()\n\t\t\t\t.describe(\n\t\t\t\t\t\"When true, render a scannable index of all items with full detail only for the top N (default 3). Saves tokens when broad overview matters more than per-item detail.\",\n\t\t\t\t),\n\t\t\tcompact_detail_count: z\n\t\t\t\t.number()\n\t\t\t\t.int()\n\t\t\t\t.min(0)\n\t\t\t\t.max(50)\n\t\t\t\t.optional()\n\t\t\t\t.describe(\"Number of items to show in full detail in compact mode (default 3)\"),\n\t\t\tcompression_mode: z\n\t\t\t\t.enum([\"off\", \"compact\", \"ids\"])\n\t\t\t\t.optional()\n\t\t\t\t.describe(\n\t\t\t\t\t\"Near-related compression mode: off disables it, compact applies only to compact rendering, ids applies in all modes. Defaults to CODEMEM_PACK_COMPRESSION or compact.\",\n\t\t\t\t),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst filters = buildFilters(args);\n\t\t\t\tconst renderOptions =\n\t\t\t\t\targs.compact || args.compact_detail_count != null || args.compression_mode != null\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tcompact: args.compact ?? (args.compact_detail_count != null ? true : undefined),\n\t\t\t\t\t\t\t\tcompactDetailCount: args.compact_detail_count,\n\t\t\t\t\t\t\t\tcompressionMode: args.compression_mode,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst result = await store.buildMemoryPackAsync(\n\t\t\t\t\targs.context,\n\t\t\t\t\targs.limit ?? undefined,\n\t\t\t\t\tnull,\n\t\t\t\t\tfilters,\n\t\t\t\t\trenderOptions,\n\t\t\t\t);\n\t\t\t\treturn jsonContent(result);\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 10. memory_remember\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_remember\",\n\t\t\"Create a new memory. Use for milestones, decisions, and notable facts.\",\n\t\t{\n\t\t\tkind: z\n\t\t\t\t.enum([\"discovery\", \"change\", \"feature\", \"bugfix\", \"refactor\", \"decision\", \"exploration\"])\n\t\t\t\t.describe(\"Memory kind\"),\n\t\t\ttitle: z.string().describe(\"Short title\"),\n\t\t\tbody: z.string().describe(\"Body text (high-signal content)\"),\n\t\t\tconfidence: z.number().min(0).max(1).default(0.5).describe(\"Confidence 0-1\"),\n\t\t\tproject: z.string().optional().describe(\"Project identifier\"),\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tconst result = rememberMemoryForMcp(store, args, {\n\t\t\t\t\tenvProject: process.env.CODEMEM_PROJECT ?? null,\n\t\t\t\t});\n\n\t\t\t\ttry {\n\t\t\t\t\tawait storeVectors(store.db, result.memId, result.title, result.body);\n\t\t\t\t} catch {\n\t\t\t\t\t// Non-fatal — memory writes should succeed even if embeddings are unavailable\n\t\t\t\t}\n\n\t\t\t\treturn jsonContent({ id: result.memId });\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 11. memory_forget\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_forget\",\n\t\t\"Soft-delete a memory item. Use for incorrect or sensitive data.\",\n\t\t{\n\t\t\tmemory_id: z.number().int().describe(\"Memory ID to forget\"),\n\t\t\t...filterSchema,\n\t\t},\n\t\tasync (args) => {\n\t\t\ttry {\n\t\t\t\tif (!forgetMemoryForMcp(store, args.memory_id, buildFilters(args, null))) {\n\t\t\t\t\treturn errorContent(\"not_found\");\n\t\t\t\t}\n\t\t\t\treturn jsonContent({ status: \"ok\" });\n\t\t\t} catch (err) {\n\t\t\t\treturn errorContent(err instanceof Error ? err.message : String(err));\n\t\t\t}\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 12. memory_schema\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_schema\",\n\t\t\"Return the memory schema — kinds, fields, and available filters.\",\n\t\t{},\n\t\tasync () => {\n\t\t\treturn jsonContent({\n\t\t\t\tkinds: Object.keys(MEMORY_KINDS),\n\t\t\t\tkind_descriptions: MEMORY_KINDS,\n\t\t\t\tfields: {\n\t\t\t\t\ttitle: \"short text\",\n\t\t\t\t\tbody: \"long text\",\n\t\t\t\t\tsubtitle: \"short text\",\n\t\t\t\t\tfacts: \"list<string>\",\n\t\t\t\t\tnarrative: \"long text\",\n\t\t\t\t\tconcepts: \"list<string>\",\n\t\t\t\t\tfiles_read: \"list<string>\",\n\t\t\t\t\tfiles_modified: \"list<string>\",\n\t\t\t\t\tprompt_number: \"int\",\n\t\t\t\t},\n\t\t\t\tfilters: [\n\t\t\t\t\t\"kind\",\n\t\t\t\t\t\"session_id\",\n\t\t\t\t\t\"since\",\n\t\t\t\t\t\"project\",\n\t\t\t\t\t\"scope_id\",\n\t\t\t\t\t\"include_scope_ids\",\n\t\t\t\t\t\"exclude_scope_ids\",\n\t\t\t\t\t\"include_actor_ids\",\n\t\t\t\t\t\"exclude_actor_ids\",\n\t\t\t\t\t\"include_visibility\",\n\t\t\t\t\t\"exclude_visibility\",\n\t\t\t\t\t\"include_workspace_ids\",\n\t\t\t\t\t\"exclude_workspace_ids\",\n\t\t\t\t\t\"include_workspace_kinds\",\n\t\t\t\t\t\"exclude_workspace_kinds\",\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// 13. memory_learn\n\t// -------------------------------------------------------------------\n\tserver.tool(\n\t\t\"memory_learn\",\n\t\t\"Learn how to use codemem memory tools. Call this first if unfamiliar.\",\n\t\t{},\n\t\tasync () => {\n\t\t\treturn jsonContent({\n\t\t\t\tintro: \"Use this tool when you're new to codemem or unsure when to recall/persist.\",\n\t\t\t\tclient_hint: \"If you are unfamiliar with codemem, call memory.learn first.\",\n\t\t\t\trecall: {\n\t\t\t\t\twhen: [\n\t\t\t\t\t\t\"Start of a task or when the user references prior work.\",\n\t\t\t\t\t\t\"When you need background context, decisions, or recent changes.\",\n\t\t\t\t\t],\n\t\t\t\t\thow: [\n\t\t\t\t\t\t\"Use memory.search_index to get compact candidates.\",\n\t\t\t\t\t\t\"Use memory.timeline to expand around a promising memory.\",\n\t\t\t\t\t\t\"Use memory.get_observations for full details only when needed.\",\n\t\t\t\t\t\t\"Use memory.pack for quick one-shot context blocks.\",\n\t\t\t\t\t\t\"Use the project filter unless the user requests cross-project context.\",\n\t\t\t\t\t],\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t'memory.search_index(\"billing cache bug\", limit=5)',\n\t\t\t\t\t\t\"memory.timeline(memory_id=123)\",\n\t\t\t\t\t\t\"memory.get_observations([123, 456])\",\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tpersistence: {\n\t\t\t\t\twhen: [\n\t\t\t\t\t\t\"Milestones (task done, key decision, new facts learned).\",\n\t\t\t\t\t\t\"Notable regressions or follow-ups that should be remembered.\",\n\t\t\t\t\t],\n\t\t\t\t\thow: [\n\t\t\t\t\t\t\"Use memory.remember with kind decision/discovery/change/exploration.\",\n\t\t\t\t\t\t\"Keep titles short and bodies high-signal.\",\n\t\t\t\t\t\t\"ALWAYS pass the project parameter if known.\",\n\t\t\t\t\t],\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t'memory.remember(kind=\"decision\", title=\"Switch to async cache\", body=\"...why...\", project=\"my-service\")',\n\t\t\t\t\t\t'memory.remember(kind=\"change\", title=\"Fixed retry loop\", body=\"...impact...\", project=\"my-service\")',\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tforget: {\n\t\t\t\t\twhen: [\n\t\t\t\t\t\t\"Accidental or sensitive data stored in memory items.\",\n\t\t\t\t\t\t\"Obsolete or incorrect items that should no longer surface.\",\n\t\t\t\t\t],\n\t\t\t\t\thow: [\n\t\t\t\t\t\t\"Call memory.forget(id) to mark the item inactive.\",\n\t\t\t\t\t\t\"Prefer forgetting over overwriting to preserve auditability.\",\n\t\t\t\t\t],\n\t\t\t\t\texamples: [\"memory.forget(123)\"],\n\t\t\t\t},\n\t\t\t\tprompt_hint:\n\t\t\t\t\t\"At task start: call memory.search_index; during work: memory.timeline + memory.get_observations; at milestones: memory.remember.\",\n\t\t\t\trecommended_system_prompt: [\n\t\t\t\t\t\"Trigger policy (1-liner): If the user references prior work or starts a task,\",\n\t\t\t\t\t\"immediately call memory.search_index; then use memory.timeline + memory.get_observations;\",\n\t\t\t\t\t\"at milestones, call memory.remember; use memory.forget for incorrect/sensitive items.\",\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"System prompt:\",\n\t\t\t\t\t\"You have access to codemem MCP tools. If unfamiliar, call memory.learn first.\",\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Recall:\",\n\t\t\t\t\t\"- Start of any task: call memory.search_index with a concise task query.\",\n\t\t\t\t\t'- If prior work is referenced (\"as before\", \"last time\", \"we already did…\", \"regression\"),',\n\t\t\t\t\t\" call memory.search_index or memory.timeline.\",\n\t\t\t\t\t\"- Use memory.get_observations only after filtering IDs.\",\n\t\t\t\t\t\"- Prefer project-scoped queries unless the user asks for cross-project.\",\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Persistence:\",\n\t\t\t\t\t\"- On milestones (task done, key decision, new facts learned), call memory.remember.\",\n\t\t\t\t\t\"- Use kind=decision for tradeoffs, kind=change for outcomes, kind=discovery/exploration for useful findings.\",\n\t\t\t\t\t\"- Keep titles short and bodies high-signal.\",\n\t\t\t\t\t\"- ALWAYS pass the project parameter if known.\",\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Safety:\",\n\t\t\t\t\t\"- Use memory.forget(id) for incorrect or sensitive items.\",\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Examples:\",\n\t\t\t\t\t'- memory.search_index(\"billing cache bug\")',\n\t\t\t\t\t\"- memory.timeline(memory_id=123)\",\n\t\t\t\t\t\"- memory.get_observations([123, 456])\",\n\t\t\t\t\t'- memory.remember(kind=\"decision\", title=\"Use async cache\", body=\"Chose async cache to avoid lock contention in X.\", project=\"my-service\")',\n\t\t\t\t\t'- memory.remember(kind=\"change\", title=\"Fixed retry loop\", body=\"Root cause was Y; added guard in Z.\", project=\"my-service\")',\n\t\t\t\t\t\"- memory.forget(123)\",\n\t\t\t\t].join(\"\\n\"),\n\t\t\t});\n\t\t},\n\t);\n\n\t// -------------------------------------------------------------------\n\t// Connect and handle shutdown\n\t// -------------------------------------------------------------------\n\tconst transport = new StdioServerTransport();\n\n\tconst shutdown = () => {\n\t\ttry {\n\t\t\tstore.close();\n\t\t} catch {\n\t\t\t// Best effort — process is exiting\n\t\t}\n\t\tprocess.exit(0);\n\t};\n\n\tprocess.on(\"SIGINT\", shutdown);\n\tprocess.on(\"SIGTERM\", shutdown);\n\n\tawait server.connect(transport);\n}\n\nmain().catch((err) => {\n\tconsole.error(\"codemem MCP server failed to start:\", err);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;;;AAOA,SAAgB,gBACf,OACA,UACA,SAC4B;AAE5B,QADa,MAAM,SAAS,MAAM,UAAU,GAAG,GAAG,WAAW,KACtD,CAAK,MAAM,QAAQ,IAAI,OAAO,SAAS,IAAI;;AAGnD,SAAgB,cACf,OACA,KACA,SACuB;AACvB,KAAI,IAAI,WAAW,EAAG,QAAO,EAAE;CAC/B,MAAM,UAAgC,EAAE;AACxC,MAAK,MAAM,MAAM,KAAK;EACrB,MAAM,OAAO,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,gBACA,yEACA,EAAE,EACF,YAAY;AACX,SAAO,YAAY;GAClB,OAAO;GACP,aAAa;GACb,QAAQ;IACP,MAAM,CACL,2DACA,kEACA;IACD,KAAK;KACJ;KACA;KACA;KACA;KACA;KACA;IACD,UAAU;KACT;KACA;KACA;KACA;IACD;GACD,aAAa;IACZ,MAAM,CACL,4DACA,+DACA;IACD,KAAK;KACJ;KACA;KACA;KACA;IACD,UAAU,CACT,mHACA,8GACA;IACD;GACD,QAAQ;IACP,MAAM,CACL,wDACA,6DACA;IACD,KAAK,CACJ,qDACA,+DACA;IACD,UAAU,CAAC,qBAAqB;IAChC;GACD,aACC;GACD,2BAA2B;IAC1B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,CAAC,KAAK,KAAK;GACZ,CAAC;GAEH;CAKD,MAAM,YAAY,IAAI,sBAAsB;CAE5C,MAAM,iBAAiB;AACtB,MAAI;AACH,SAAM,OAAO;UACN;AAGR,UAAQ,KAAK,EAAE;;AAGhB,SAAQ,GAAG,UAAU,SAAS;AAC9B,SAAQ,GAAG,WAAW,SAAS;AAE/B,OAAM,OAAO,QAAQ,UAAU;;AAGhC,MAAM,CAAC,OAAO,QAAQ;AACrB,SAAQ,MAAM,uCAAuC,IAAI;AACzD,SAAQ,KAAK,EAAE;EACd"}
|