@membank/mcp 0.10.0 → 0.11.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/index.mjs CHANGED
@@ -1,8 +1,12 @@
1
1
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
- import { DatabaseManager, EmbeddingService, MEMORY_TYPE_VALUES, MIGRATIONS, MemoryRepository, MemoryTypeSchema, ProjectRepository, QueryEngine, listMemoryTypes, resolveProject, runScopeToProjectsMigration } from "@membank/core";
2
+ import { readFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { DatabaseManager, EmbeddingService, MEMORY_TYPE_VALUES, MIGRATIONS, MemoryRepository, MemoryTypeSchema, PIN_BUDGET_THRESHOLD, ProjectRepository, QueryEngine, SynthesisRepository, isSynthesisEnabled, listMemoryTypes, resolveProject, runScopeToProjectsMigration } from "@membank/core";
3
6
  import { Server } from "@modelcontextprotocol/sdk/server";
4
7
  import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError } from "@modelcontextprotocol/sdk/types.js";
5
8
  import { ZodError, z } from "zod";
9
+ import { createSdkMcpServer, query, tool } from "@anthropic-ai/claude-agent-sdk";
6
10
  //#region src/schemas.ts
7
11
  const SaveMemoryArgsSchema = z.object({
8
12
  content: z.string().min(1),
@@ -12,7 +16,8 @@ const SaveMemoryArgsSchema = z.object({
12
16
  });
13
17
  const UpdateMemoryArgsSchema = z.object({
14
18
  id: z.string().min(1),
15
- content: z.string().min(1),
19
+ content: z.string().min(1).optional(),
20
+ type: MemoryTypeSchema.optional(),
16
21
  tags: z.array(z.string()).optional()
17
22
  });
18
23
  const DeleteMemoryArgsSchema = z.object({ id: z.string().min(1) });
@@ -20,28 +25,209 @@ const QueryMemoryArgsSchema = z.object({
20
25
  query: z.string().min(1),
21
26
  type: MemoryTypeSchema.optional(),
22
27
  limit: z.number().int().positive().optional(),
23
- includePinned: z.boolean().optional()
28
+ includePinned: z.boolean().optional(),
29
+ global: z.boolean().optional()
24
30
  });
25
31
  const MigrateArgsSchema = z.discriminatedUnion("mode", [z.object({ mode: z.literal("list") }), z.object({
26
32
  mode: z.literal("run"),
27
33
  name: z.string().min(1)
28
34
  })]);
29
35
  const PinMemoryArgsSchema = z.object({ id: z.string().min(1) });
36
+ const ResolveReviewArgsSchema = z.object({ id: z.string().min(1) });
37
+ //#endregion
38
+ //#region src/synthesis/agent-loop.ts
39
+ const SYNTHESIS_SYSTEM_PROMPT = "You are a memory synthesizer. Your job is to read the user's stored memories and produce a concise, well-structured summary of what's most important to remember about this user — their preferences, corrections, decisions, and key facts. Pinned memories are higher fidelity and should be weighted more heavily. Exclude transient or ephemeral details. Output plain text suitable for injection into an LLM context window. Be concise — target 200-400 words.";
40
+ const MAX_TURNS = 3;
41
+ var SynthesisAgentLoop = class {
42
+ #tools;
43
+ constructor(tools, _config) {
44
+ this.#tools = tools;
45
+ }
46
+ async run(scope) {
47
+ const apiKey = process.env.ANTHROPIC_API_KEY ?? process.env.CLAUDE_CODE_OAUTH_TOKEN;
48
+ if (apiKey === void 0 || apiKey === "") throw new Error("ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN) is required for synthesis. Set one of these environment variables to enable synthesis.");
49
+ const mcpServer = createSdkMcpServer({
50
+ name: "membank-synthesis-tools",
51
+ version: "1.0.0",
52
+ tools: [tool("query_memory", "Search memories by semantic similarity", {
53
+ query: z.string().describe("Search text"),
54
+ limit: z.number().optional().describe("Maximum results to return"),
55
+ global: z.boolean().optional().describe("Query global memories only when true, otherwise current project scope")
56
+ }, async ({ query: q, limit, global: isGlobal }) => {
57
+ return { content: [{
58
+ type: "text",
59
+ text: await this.#tools.queryMemory({
60
+ query: q,
61
+ limit,
62
+ global: isGlobal
63
+ })
64
+ }] };
65
+ }, { annotations: { readOnlyHint: true } }), tool("get_memory_summary", "Returns aggregate stats: total memories, counts by type, pinned count, review queue size", {}, async () => {
66
+ return { content: [{
67
+ type: "text",
68
+ text: await this.#tools.getMemorySummary()
69
+ }] };
70
+ }, { annotations: { readOnlyHint: true } })]
71
+ });
72
+ const prompt = `Synthesize the memories for ${scope === "global" ? "global (across all projects)" : `project scope: ${scope}`}. Use get_memory_summary first to understand the overall state, then use query_memory to retrieve relevant memories (query with broad terms like "preferences", "corrections", "decisions", "key facts"). After gathering information, produce a concise synthesis of the most important things to remember about this user. Output only the synthesis text — no preamble, no metadata.`;
73
+ const startTime = Date.now();
74
+ const env = Object.fromEntries(Object.entries(process.env).filter((e) => e[1] !== void 0));
75
+ const agentQuery = query({
76
+ prompt,
77
+ options: {
78
+ model: "claude-haiku-4-5-20251001",
79
+ maxTurns: MAX_TURNS,
80
+ systemPrompt: SYNTHESIS_SYSTEM_PROMPT,
81
+ mcpServers: { "membank-synthesis-tools": mcpServer },
82
+ allowedTools: ["query_memory", "get_memory_summary"],
83
+ permissionMode: "dontAsk",
84
+ env
85
+ }
86
+ });
87
+ let finalResult = "";
88
+ for await (const message of agentQuery) if (message.type === "result") if (message.subtype === "success") finalResult = message.result;
89
+ else {
90
+ const details = "errors" in message && Array.isArray(message.errors) ? `: ${message.errors.join("; ")}` : "";
91
+ throw new Error(`Synthesis agent failed: ${message.subtype}${details}`);
92
+ }
93
+ const durationMs = Date.now() - startTime;
94
+ process.stderr.write(`membank synthesis: scope=${scope} duration=${durationMs}ms\n`);
95
+ if (finalResult === "") throw new Error("Synthesis agent returned empty result");
96
+ return finalResult;
97
+ }
98
+ };
99
+ //#endregion
100
+ //#region src/synthesis/engine.ts
101
+ const DEFAULT_DEBOUNCE_MS = 45e3;
102
+ const DEFAULT_IN_FLIGHT_TIMEOUT_MS = 12e4;
103
+ const MAX_BACKOFF_MULTIPLIER = 5;
104
+ var SynthesisEngine = class {
105
+ #synthRepo;
106
+ #config;
107
+ #agentLoop;
108
+ #dirtyScopes = /* @__PURE__ */ new Set();
109
+ #failureCounts = /* @__PURE__ */ new Map();
110
+ #running = false;
111
+ #loopTimer;
112
+ #inFlightPromises = /* @__PURE__ */ new Map();
113
+ constructor(_db, synthRepo, config, agentLoop) {
114
+ this.#synthRepo = synthRepo;
115
+ this.#config = config;
116
+ this.#agentLoop = agentLoop;
117
+ }
118
+ async init() {
119
+ this.#synthRepo.expireStale();
120
+ const stale = this.#synthRepo.getExpiredOrDirtyScopes();
121
+ for (const { scope } of stale) this.#dirtyScopes.add(scope);
122
+ this.#running = true;
123
+ await this.#debounceLoop();
124
+ }
125
+ shutdown() {
126
+ this.#running = false;
127
+ if (this.#loopTimer !== void 0) {
128
+ clearTimeout(this.#loopTimer);
129
+ this.#loopTimer = void 0;
130
+ }
131
+ const inFlight = [...this.#inFlightPromises.values()];
132
+ if (inFlight.length === 0) return Promise.resolve();
133
+ const graceMs = 5e3;
134
+ return Promise.race([Promise.allSettled(inFlight).then(() => void 0), new Promise((resolve) => setTimeout(resolve, graceMs))]);
135
+ }
136
+ markDirty(scope) {
137
+ this.#dirtyScopes.add(scope);
138
+ }
139
+ #scheduleNextCycle() {
140
+ if (!this.#running) return;
141
+ const debounceMs = this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS;
142
+ this.#loopTimer = setTimeout(() => {
143
+ this.#debounceLoop();
144
+ }, debounceMs);
145
+ }
146
+ async #debounceLoop() {
147
+ const scopesToProcess = [...this.#dirtyScopes];
148
+ for (const scope of scopesToProcess) {
149
+ const inFlightTimeoutMs = this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS;
150
+ const synthesis = this.#synthRepo.getSynthesis(scope);
151
+ if (synthesis?.inFlightSince !== null && synthesis?.inFlightSince !== void 0) {
152
+ if (Date.now() - new Date(synthesis.inFlightSince).getTime() < inFlightTimeoutMs) continue;
153
+ this.#synthRepo.clearInFlight(scope);
154
+ }
155
+ this.#dirtyScopes.delete(scope);
156
+ const promise = this.#synthesizeScope(scope).finally(() => {
157
+ this.#inFlightPromises.delete(scope);
158
+ });
159
+ this.#inFlightPromises.set(scope, promise);
160
+ }
161
+ this.#scheduleNextCycle();
162
+ }
163
+ async #synthesizeScope(scope) {
164
+ this.#synthRepo.markInFlight(scope);
165
+ try {
166
+ const content = await this.#agentLoop.run(scope);
167
+ const sourceHash = this.#synthRepo.computeSourceMemoryHash(scope);
168
+ this.#synthRepo.saveSynthesis(scope, content, sourceHash);
169
+ this.#failureCounts.delete(scope);
170
+ } catch (err) {
171
+ const failures = (this.#failureCounts.get(scope) ?? 0) + 1;
172
+ this.#failureCounts.set(scope, failures);
173
+ const backoffMultiplier = Math.min(failures, MAX_BACKOFF_MULTIPLIER);
174
+ const backoffMs = (this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS) * backoffMultiplier;
175
+ process.stderr.write(`membank synthesis: error for scope=${scope} failures=${failures} backoff=${backoffMs}ms: ${err instanceof Error ? err.message : String(err)}\n`);
176
+ setTimeout(() => {
177
+ this.#dirtyScopes.add(scope);
178
+ }, backoffMs);
179
+ this.#synthRepo.clearInFlight(scope);
180
+ }
181
+ }
182
+ };
30
183
  //#endregion
31
184
  //#region src/server.ts
32
185
  const SERVER_NAME = "membank";
33
186
  const SERVER_VERSION = "0.1.0";
187
+ function loadSynthesisConfig() {
188
+ const configPath = join(homedir(), ".membank", "config.json");
189
+ try {
190
+ const raw = readFileSync(configPath, "utf8");
191
+ const parsed = JSON.parse(raw);
192
+ return {
193
+ enabled: parsed.synthesis?.enabled === true,
194
+ maxTokensPerRun: parsed.synthesis?.maxTokensPerRun,
195
+ debounceMs: parsed.synthesis?.debounceMs,
196
+ stalenessDays: parsed.synthesis?.stalenessDays,
197
+ inFlightTimeoutMs: parsed.synthesis?.inFlightTimeoutMs
198
+ };
199
+ } catch {
200
+ return { enabled: false };
201
+ }
202
+ }
34
203
  function initCore(options = {}) {
35
204
  const db = options.useInMemoryDb ? DatabaseManager.openInMemory() : DatabaseManager.open(options.dbPath);
36
205
  const embedding = new EmbeddingService();
37
206
  const projects = new ProjectRepository(db);
38
207
  const repo = new MemoryRepository(db, embedding, projects);
208
+ const query = new QueryEngine(db, embedding, repo);
209
+ const synthConfig = loadSynthesisConfig();
210
+ let synthEngine;
211
+ if (synthConfig.enabled) synthEngine = new SynthesisEngine(db, new SynthesisRepository(db), synthConfig, new SynthesisAgentLoop({
212
+ queryMemory: async (args) => {
213
+ const projectHash = args.global === true ? void 0 : (await resolveProject()).hash;
214
+ const results = await query.query({
215
+ query: args.query,
216
+ projectHash,
217
+ limit: args.limit ?? 20,
218
+ includePinned: true
219
+ });
220
+ return JSON.stringify(results);
221
+ },
222
+ getMemorySummary: async () => JSON.stringify(repo.stats())
223
+ }, synthConfig));
39
224
  return {
40
225
  db,
41
226
  embedding,
42
227
  repo,
43
- query: new QueryEngine(db, embedding, repo),
44
- projects
228
+ query,
229
+ projects,
230
+ synthEngine
45
231
  };
46
232
  }
47
233
  function parseArgs(schema, raw) {
@@ -97,7 +283,7 @@ function createServer(core) {
97
283
  },
98
284
  {
99
285
  name: "update_memory",
100
- description: "Update the content and/or tags of an existing memory by id.",
286
+ description: "Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.",
101
287
  inputSchema: {
102
288
  type: "object",
103
289
  properties: {
@@ -109,13 +295,18 @@ function createServer(core) {
109
295
  type: "string",
110
296
  description: "New content for the memory"
111
297
  },
298
+ type: {
299
+ type: "string",
300
+ enum: [...MEMORY_TYPE_VALUES],
301
+ description: "New type for the memory (reclassification)"
302
+ },
112
303
  tags: {
113
304
  type: "array",
114
305
  items: { type: "string" },
115
306
  description: "Replacement tags (optional)"
116
307
  }
117
308
  },
118
- required: ["id", "content"]
309
+ required: ["id"]
119
310
  }
120
311
  },
121
312
  {
@@ -152,6 +343,10 @@ function createServer(core) {
152
343
  includePinned: {
153
344
  type: "boolean",
154
345
  description: "Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates."
346
+ },
347
+ global: {
348
+ type: "boolean",
349
+ description: "Query global memories only. When omitted or false, queries the current project scope."
155
350
  }
156
351
  },
157
352
  required: ["query"]
@@ -199,6 +394,36 @@ function createServer(core) {
199
394
  } },
200
395
  required: ["id"]
201
396
  }
397
+ },
398
+ {
399
+ name: "get_memory_summary",
400
+ description: "Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.",
401
+ inputSchema: {
402
+ type: "object",
403
+ properties: {},
404
+ required: []
405
+ }
406
+ },
407
+ {
408
+ name: "list_flagged_memories",
409
+ description: "List memories that have unresolved dedup review events. These were flagged automatically when a near-duplicate was saved (cosine similarity 0.75–0.92).",
410
+ inputSchema: {
411
+ type: "object",
412
+ properties: {},
413
+ required: []
414
+ }
415
+ },
416
+ {
417
+ name: "resolve_review",
418
+ description: "Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.",
419
+ inputSchema: {
420
+ type: "object",
421
+ properties: { id: {
422
+ type: "string",
423
+ description: "Memory id to resolve review events for"
424
+ } },
425
+ required: ["id"]
426
+ }
202
427
  }
203
428
  ] }));
204
429
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -226,6 +451,10 @@ function createServer(core) {
226
451
  tags: args.tags,
227
452
  projectScope
228
453
  });
454
+ if (core.synthEngine !== void 0) {
455
+ const scope = memory.projects.length > 0 ? memory.projects[0]?.scopeHash ?? "global" : "global";
456
+ core.synthEngine.markDirty(scope);
457
+ }
229
458
  return { content: [{
230
459
  type: "text",
231
460
  text: JSON.stringify(memory)
@@ -245,8 +474,13 @@ function createServer(core) {
245
474
  try {
246
475
  const memory = await core.repo.update(args.id, {
247
476
  content: args.content,
477
+ type: args.type,
248
478
  tags: args.tags
249
479
  });
480
+ if (core.synthEngine !== void 0) {
481
+ const scope = memory.projects.length > 0 ? memory.projects[0]?.scopeHash ?? "global" : "global";
482
+ core.synthEngine.markDirty(scope);
483
+ }
250
484
  return { content: [{
251
485
  type: "text",
252
486
  text: JSON.stringify(memory)
@@ -271,7 +505,12 @@ function createServer(core) {
271
505
  }],
272
506
  isError: true
273
507
  };
508
+ let memoryScopeBeforeDelete;
509
+ if (core.synthEngine !== void 0) memoryScopeBeforeDelete = core.db.db.prepare(`SELECT p.scope_hash FROM projects p
510
+ JOIN memory_projects mp ON mp.project_id = p.id
511
+ WHERE mp.memory_id = ?`).get(args.id)?.scope_hash ?? "global";
274
512
  await core.repo.delete(args.id);
513
+ if (core.synthEngine !== void 0 && memoryScopeBeforeDelete !== void 0) core.synthEngine.markDirty(memoryScopeBeforeDelete);
275
514
  return { content: [{
276
515
  type: "text",
277
516
  text: JSON.stringify({
@@ -291,10 +530,12 @@ function createServer(core) {
291
530
  }
292
531
  if (request.params.name === "query_memory") {
293
532
  const args = parseArgs(QueryMemoryArgsSchema, request.params.arguments);
533
+ const projectHash = args.global === true ? void 0 : (await resolveProject()).hash;
294
534
  try {
295
535
  const serialised = (await core.query.query({
296
536
  query: args.query,
297
537
  type: args.type,
538
+ projectHash,
298
539
  limit: args.limit ?? 10,
299
540
  includePinned: args.includePinned
300
541
  })).map((r) => ({
@@ -305,6 +546,9 @@ function createServer(core) {
305
546
  projects: r.projects,
306
547
  pinned: r.pinned,
307
548
  reviewEvents: r.reviewEvents,
549
+ createdAt: r.createdAt,
550
+ updatedAt: r.updatedAt,
551
+ sourceHarness: r.sourceHarness,
308
552
  score: r.score
309
553
  }));
310
554
  return { content: [{
@@ -356,6 +600,19 @@ function createServer(core) {
356
600
  const pinned = request.params.name === "pin_memory";
357
601
  try {
358
602
  const memory = core.repo.setPin(args.id, pinned);
603
+ if (pinned) {
604
+ const charCount = core.repo.getPinnedCharCount();
605
+ if (charCount > PIN_BUDGET_THRESHOLD && !isSynthesisEnabled()) {
606
+ const result = {
607
+ ...memory,
608
+ pinBudgetWarning: `Pinned memories now use ${charCount} characters (threshold: ${PIN_BUDGET_THRESHOLD}). Consider unpinning older memories or enabling synthesis to compress them.`
609
+ };
610
+ return { content: [{
611
+ type: "text",
612
+ text: JSON.stringify(result)
613
+ }] };
614
+ }
615
+ }
359
616
  return { content: [{
360
617
  type: "text",
361
618
  text: JSON.stringify(memory)
@@ -370,6 +627,63 @@ function createServer(core) {
370
627
  };
371
628
  }
372
629
  }
630
+ if (request.params.name === "get_memory_summary") try {
631
+ return { content: [{
632
+ type: "text",
633
+ text: JSON.stringify(core.repo.stats())
634
+ }] };
635
+ } catch (err) {
636
+ return {
637
+ content: [{
638
+ type: "text",
639
+ text: err instanceof Error ? err.message : String(err)
640
+ }],
641
+ isError: true
642
+ };
643
+ }
644
+ if (request.params.name === "list_flagged_memories") try {
645
+ const memories = core.repo.listFlagged();
646
+ return { content: [{
647
+ type: "text",
648
+ text: JSON.stringify(memories)
649
+ }] };
650
+ } catch (err) {
651
+ return {
652
+ content: [{
653
+ type: "text",
654
+ text: err instanceof Error ? err.message : String(err)
655
+ }],
656
+ isError: true
657
+ };
658
+ }
659
+ if (request.params.name === "resolve_review") {
660
+ const args = parseArgs(ResolveReviewArgsSchema, request.params.arguments);
661
+ try {
662
+ if (!(core.db.db.prepare(`SELECT id FROM memories WHERE id = ?`).get(args.id) !== void 0)) return {
663
+ content: [{
664
+ type: "text",
665
+ text: `Memory not found: ${args.id}`
666
+ }],
667
+ isError: true
668
+ };
669
+ core.repo.resolveReviewEvents(args.id);
670
+ return { content: [{
671
+ type: "text",
672
+ text: JSON.stringify({
673
+ success: true,
674
+ id: args.id
675
+ })
676
+ }] };
677
+ } catch (err) {
678
+ return {
679
+ content: [{
680
+ type: "text",
681
+ text: err instanceof Error ? err.message : String(err)
682
+ }],
683
+ isError: true
684
+ };
685
+ }
686
+ }
373
687
  throw new Error(`Unknown tool: ${request.params.name}`);
374
688
  });
375
689
  return server;
@@ -385,6 +699,22 @@ async function startServer() {
385
699
  process.stderr.write(`membank: failed to initialise core: ${message}\n`);
386
700
  process.exit(1);
387
701
  }
702
+ if (core.synthEngine !== void 0) try {
703
+ await core.synthEngine.init();
704
+ } catch (err) {
705
+ const message = err instanceof Error ? err.message : String(err);
706
+ process.stderr.write(`membank: synthesis engine init failed: ${message}\n`);
707
+ }
708
+ const shutdown = async () => {
709
+ if (core.synthEngine !== void 0) await core.synthEngine.shutdown();
710
+ process.exit(0);
711
+ };
712
+ process.on("SIGTERM", () => {
713
+ shutdown();
714
+ });
715
+ process.on("SIGINT", () => {
716
+ shutdown();
717
+ });
388
718
  const server = createServer(core);
389
719
  const transport = new StdioServerTransport();
390
720
  await server.connect(transport);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/schemas.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { MemoryTypeSchema } from \"@membank/core\";\nimport { z } from \"zod\";\n\nexport const SaveMemoryArgsSchema = z.object({\n content: z.string().min(1),\n type: MemoryTypeSchema,\n tags: z.array(z.string()).optional(),\n global: z.boolean().optional(),\n});\n\nexport const UpdateMemoryArgsSchema = z.object({\n id: z.string().min(1),\n content: z.string().min(1),\n tags: z.array(z.string()).optional(),\n});\n\nexport const DeleteMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const QueryMemoryArgsSchema = z.object({\n query: z.string().min(1),\n type: MemoryTypeSchema.optional(),\n limit: z.number().int().positive().optional(),\n includePinned: z.boolean().optional(),\n});\n\nexport const MigrateArgsSchema = z.discriminatedUnion(\"mode\", [\n z.object({ mode: z.literal(\"list\") }),\n z.object({ mode: z.literal(\"run\"), name: z.string().min(1) }),\n]);\n\nexport const PinMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n","import {\n DatabaseManager,\n EmbeddingService,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n MIGRATIONS,\n ProjectRepository,\n QueryEngine,\n resolveProject,\n runScopeToProjectsMigration,\n} from \"@membank/core\";\nimport { Server } from \"@modelcontextprotocol/sdk/server\";\nimport {\n CallToolRequestSchema,\n ErrorCode,\n ListToolsRequestSchema,\n McpError,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { ZodError } from \"zod\";\nimport {\n DeleteMemoryArgsSchema,\n MigrateArgsSchema,\n PinMemoryArgsSchema,\n QueryMemoryArgsSchema,\n SaveMemoryArgsSchema,\n UpdateMemoryArgsSchema,\n} from \"./schemas.js\";\n\nconst SERVER_NAME = \"membank\";\nconst SERVER_VERSION = \"0.1.0\";\n\nexport interface CoreServices {\n db: DatabaseManager;\n embedding: EmbeddingService;\n repo: MemoryRepository;\n query: QueryEngine;\n projects: ProjectRepository;\n}\n\nexport interface ServerOptions {\n dbPath?: string;\n useInMemoryDb?: boolean;\n}\n\nexport function initCore(options: ServerOptions = {}): CoreServices {\n const db = options.useInMemoryDb\n ? DatabaseManager.openInMemory()\n : DatabaseManager.open(options.dbPath);\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const query = new QueryEngine(db, embedding, repo);\n return { db, embedding, repo, query, projects };\n}\n\nfunction parseArgs<T>(schema: { parse: (v: unknown) => T }, raw: unknown): T {\n try {\n return schema.parse(raw);\n } catch (e) {\n const msg = e instanceof ZodError ? (e.issues[0]?.message ?? e.message) : String(e);\n throw new McpError(ErrorCode.InvalidParams, msg);\n }\n}\n\nexport function createServer(core: CoreServices): Server {\n const server = new Server(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { capabilities: { tools: {} } }\n );\n\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [\n {\n name: \"list_memory_types\",\n description: \"Returns the ordered list of memory type values supported by membank.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"save_memory\",\n description:\n \"Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Memory content to save\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Memory type\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Optional tags\",\n },\n global: {\n type: \"boolean\",\n description: \"Save as a global memory, not tied to any project\",\n },\n },\n required: [\"content\", \"type\"],\n },\n },\n {\n name: \"update_memory\",\n description: \"Update the content and/or tags of an existing memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to update\" },\n content: { type: \"string\", description: \"New content for the memory\" },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Replacement tags (optional)\",\n },\n },\n required: [\"id\", \"content\"],\n },\n },\n {\n name: \"delete_memory\",\n description: \"Delete a memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to delete\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"query_memory\",\n description:\n \"Search memories by semantic similarity. Returns results ranked by confidence score.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search text\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Filter by memory type\",\n },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n includePinned: {\n type: \"boolean\",\n description:\n \"Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.\",\n },\n },\n required: [\"query\"],\n },\n },\n {\n name: \"migrate\",\n description:\n 'List or run named data migrations. Use mode \"list\" to see available migrations; mode \"run\" with a migration name to execute one.',\n inputSchema: {\n type: \"object\",\n properties: {\n mode: {\n type: \"string\",\n enum: [\"list\", \"run\"],\n description: 'Mode: \"list\" to see available migrations, \"run\" to execute one',\n },\n name: {\n type: \"string\",\n description: 'Migration name (required when mode is \"run\")',\n },\n },\n required: [\"mode\"],\n },\n },\n {\n name: \"pin_memory\",\n description:\n \"Pin a memory by id. Pinned memories are always injected into the session context.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to pin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"unpin_memory\",\n description: \"Unpin a memory by id. Removes the memory from guaranteed session injection.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to unpin\" },\n },\n required: [\"id\"],\n },\n },\n ],\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n if (request.params.name === \"list_memory_types\") {\n try {\n return {\n content: [{ type: \"text\", text: JSON.stringify(listMemoryTypes()) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"save_memory\") {\n const args = parseArgs(SaveMemoryArgsSchema, request.params.arguments);\n const projectScope = args.global === true ? undefined : await resolveProject();\n\n try {\n const memory = await core.repo.save({\n content: args.content,\n type: args.type,\n tags: args.tags,\n projectScope,\n });\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(memory) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"update_memory\") {\n const args = parseArgs(UpdateMemoryArgsSchema, request.params.arguments);\n\n try {\n const memory = await core.repo.update(args.id, {\n content: args.content,\n tags: args.tags,\n });\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"delete_memory\") {\n const args = parseArgs(DeleteMemoryArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n await core.repo.delete(args.id);\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"query_memory\") {\n const args = parseArgs(QueryMemoryArgsSchema, request.params.arguments);\n\n try {\n const results = await core.query.query({\n query: args.query,\n type: args.type,\n limit: args.limit ?? 10,\n includePinned: args.includePinned,\n });\n\n const serialised = results.map((r) => ({\n id: r.id,\n content: r.content,\n type: r.type,\n tags: r.tags,\n projects: r.projects,\n pinned: r.pinned,\n reviewEvents: r.reviewEvents,\n score: r.score,\n }));\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(serialised) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"migrate\") {\n const args = parseArgs(MigrateArgsSchema, request.params.arguments);\n\n if (args.mode === \"list\") {\n return {\n content: [{ type: \"text\", text: JSON.stringify(MIGRATIONS) }],\n };\n }\n\n if (args.name === \"scope-to-projects\") {\n try {\n const result = await runScopeToProjectsMigration(core.projects);\n if (result === null) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({ error: \"No project found for current directory.\" }),\n },\n ],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new McpError(\n ErrorCode.InvalidParams,\n `Unknown migration: \"${args.name}\". Available: ${MIGRATIONS.map((m) => m.name).join(\", \")}`\n );\n }\n\n if (request.params.name === \"pin_memory\" || request.params.name === \"unpin_memory\") {\n const args = parseArgs(PinMemoryArgsSchema, request.params.arguments);\n const pinned = request.params.name === \"pin_memory\";\n\n try {\n const memory = core.repo.setPin(args.id, pinned);\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new Error(`Unknown tool: ${request.params.name}`);\n });\n\n return server;\n}\n","import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport type { CoreServices } from \"./server.js\";\nimport { createServer, initCore } from \"./server.js\";\n\nexport async function startServer(): Promise<void> {\n let core: CoreServices;\n try {\n core = initCore();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: failed to initialise core: ${message}\\n`);\n process.exit(1);\n }\n\n const server = createServer(core);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n"],"mappings":";;;;;;AAGA,MAAa,uBAAuB,EAAE,OAAO;CAC3C,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACpC,QAAQ,EAAE,SAAS,CAAC,UAAU;CAC/B,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO;CAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;CACrB,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACrC,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO,EAC7C,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACtB,CAAC;AAEF,MAAa,wBAAwB,EAAE,OAAO;CAC5C,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE;CACxB,MAAM,iBAAiB,UAAU;CACjC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU;CAC7C,eAAe,EAAE,SAAS,CAAC,UAAU;CACtC,CAAC;AAEF,MAAa,oBAAoB,EAAE,mBAAmB,QAAQ,CAC5D,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,OAAO,EAAE,CAAC,EACrC,EAAE,OAAO;CAAE,MAAM,EAAE,QAAQ,MAAM;CAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE;CAAE,CAAC,CAC9D,CAAC;AAEF,MAAa,sBAAsB,EAAE,OAAO,EAC1C,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,EACtB,CAAC;;;ACLF,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAevB,SAAgB,SAAS,UAAyB,EAAE,EAAgB;CAClE,MAAM,KAAK,Q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Ae,QAAQ,IAAI,UAAU,OAAO,IAAI;AAChE,UAAQ,OAAO,MAAM,uCAAuC,QAAQ,IAAI;AACxE,UAAQ,KAAK,EAAE;;CAGjB,MAAM,SAAS,aAAa,KAAK;CACjC,MAAM,YAAY,IAAI,sBAAsB;AAC5C,OAAM,OAAO,QAAQ,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":["#tools","#synthRepo","#config","#agentLoop","#dirtyScopes","#failureCounts","#running","#debounceLoop","#loopTimer","#inFlightPromises","#synthesizeScope","#scheduleNextCycle"],"sources":["../src/schemas.ts","../src/synthesis/agent-loop.ts","../src/synthesis/engine.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { MemoryTypeSchema } from \"@membank/core\";\nimport { z } from \"zod\";\n\nexport const SaveMemoryArgsSchema = z.object({\n content: z.string().min(1),\n type: MemoryTypeSchema,\n tags: z.array(z.string()).optional(),\n global: z.boolean().optional(),\n});\n\nexport const UpdateMemoryArgsSchema = z.object({\n id: z.string().min(1),\n content: z.string().min(1).optional(),\n type: MemoryTypeSchema.optional(),\n tags: z.array(z.string()).optional(),\n});\n\nexport const DeleteMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const QueryMemoryArgsSchema = z.object({\n query: z.string().min(1),\n type: MemoryTypeSchema.optional(),\n limit: z.number().int().positive().optional(),\n includePinned: z.boolean().optional(),\n global: z.boolean().optional(),\n});\n\nexport const MigrateArgsSchema = z.discriminatedUnion(\"mode\", [\n z.object({ mode: z.literal(\"list\") }),\n z.object({ mode: z.literal(\"run\"), name: z.string().min(1) }),\n]);\n\nexport const PinMemoryArgsSchema = z.object({\n id: z.string().min(1),\n});\n\nexport const ResolveReviewArgsSchema = z.object({\n id: z.string().min(1),\n});\n","import { createSdkMcpServer, query, tool } from \"@anthropic-ai/claude-agent-sdk\";\nimport { z } from \"zod\";\n\nconst SYNTHESIS_SYSTEM_PROMPT =\n \"You are a memory synthesizer. Your job is to read the user's stored memories and produce a concise, well-structured summary of what's most important to remember about this user — their preferences, corrections, decisions, and key facts. Pinned memories are higher fidelity and should be weighted more heavily. Exclude transient or ephemeral details. Output plain text suitable for injection into an LLM context window. Be concise — target 200-400 words.\";\n\nconst MAX_TURNS = 3;\n\nexport interface SynthesisConfig {\n enabled: boolean;\n maxTokensPerRun?: number;\n debounceMs?: number;\n stalenessDays?: number;\n inFlightTimeoutMs?: number;\n}\n\ninterface SynthesisTools {\n queryMemory: (args: { query: string; limit?: number; global?: boolean }) => Promise<string>;\n getMemorySummary: () => Promise<string>;\n}\n\nexport class SynthesisAgentLoop {\n readonly #tools: SynthesisTools;\n\n constructor(tools: SynthesisTools, _config: SynthesisConfig) {\n this.#tools = tools;\n }\n\n async run(scope: string): Promise<string> {\n const apiKey = process.env.ANTHROPIC_API_KEY ?? process.env.CLAUDE_CODE_OAUTH_TOKEN;\n if (apiKey === undefined || apiKey === \"\") {\n throw new Error(\n \"ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN) is required for synthesis. Set one of these environment variables to enable synthesis.\"\n );\n }\n\n const queryMemoryTool = tool(\n \"query_memory\",\n \"Search memories by semantic similarity\",\n {\n query: z.string().describe(\"Search text\"),\n limit: z.number().optional().describe(\"Maximum results to return\"),\n global: z\n .boolean()\n .optional()\n .describe(\"Query global memories only when true, otherwise current project scope\"),\n },\n async ({ query: q, limit, global: isGlobal }) => {\n const result = await this.#tools.queryMemory({\n query: q,\n limit,\n global: isGlobal,\n });\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const getMemorySummaryTool = tool(\n \"get_memory_summary\",\n \"Returns aggregate stats: total memories, counts by type, pinned count, review queue size\",\n {},\n async () => {\n const result = await this.#tools.getMemorySummary();\n return { content: [{ type: \"text\" as const, text: result }] };\n },\n { annotations: { readOnlyHint: true } }\n );\n\n const mcpServer = createSdkMcpServer({\n name: \"membank-synthesis-tools\",\n version: \"1.0.0\",\n tools: [queryMemoryTool, getMemorySummaryTool],\n });\n\n const isGlobal = scope === \"global\";\n const scopeDescription = isGlobal ? \"global (across all projects)\" : `project scope: ${scope}`;\n\n const prompt = `Synthesize the memories for ${scopeDescription}. Use get_memory_summary first to understand the overall state, then use query_memory to retrieve relevant memories (query with broad terms like \"preferences\", \"corrections\", \"decisions\", \"key facts\"). After gathering information, produce a concise synthesis of the most important things to remember about this user. Output only the synthesis text — no preamble, no metadata.`;\n\n const startTime = Date.now();\n\n const env = Object.fromEntries(\n Object.entries(process.env).filter((e): e is [string, string] => e[1] !== undefined)\n );\n\n const agentQuery = query({\n prompt,\n options: {\n model: \"claude-haiku-4-5-20251001\",\n maxTurns: MAX_TURNS,\n systemPrompt: SYNTHESIS_SYSTEM_PROMPT,\n mcpServers: { \"membank-synthesis-tools\": mcpServer },\n allowedTools: [\"query_memory\", \"get_memory_summary\"],\n permissionMode: \"dontAsk\",\n env,\n },\n });\n\n let finalResult = \"\";\n\n for await (const message of agentQuery) {\n if (message.type === \"result\") {\n if (message.subtype === \"success\") {\n finalResult = message.result;\n } else {\n const details =\n \"errors\" in message && Array.isArray(message.errors)\n ? `: ${message.errors.join(\"; \")}`\n : \"\";\n throw new Error(`Synthesis agent failed: ${message.subtype}${details}`);\n }\n }\n }\n\n const durationMs = Date.now() - startTime;\n process.stderr.write(`membank synthesis: scope=${scope} duration=${durationMs}ms\\n`);\n\n if (finalResult === \"\") {\n throw new Error(\"Synthesis agent returned empty result\");\n }\n\n return finalResult;\n }\n}\n","import type { DatabaseManager, SynthesisRepository } from \"@membank/core\";\nimport type { SynthesisAgentLoop, SynthesisConfig } from \"./agent-loop.js\";\n\nconst DEFAULT_DEBOUNCE_MS = 45_000;\nconst DEFAULT_IN_FLIGHT_TIMEOUT_MS = 120_000;\nconst MAX_BACKOFF_MULTIPLIER = 5;\n\nexport class SynthesisEngine {\n readonly #synthRepo: SynthesisRepository;\n readonly #config: SynthesisConfig;\n readonly #agentLoop: SynthesisAgentLoop;\n readonly #dirtyScopes = new Set<string>();\n readonly #failureCounts = new Map<string, number>();\n #running = false;\n #loopTimer: ReturnType<typeof setTimeout> | undefined;\n #inFlightPromises = new Map<string, Promise<void>>();\n\n constructor(\n _db: DatabaseManager,\n synthRepo: SynthesisRepository,\n config: SynthesisConfig,\n agentLoop: SynthesisAgentLoop\n ) {\n this.#synthRepo = synthRepo;\n this.#config = config;\n this.#agentLoop = agentLoop;\n }\n\n async init(): Promise<void> {\n this.#synthRepo.expireStale();\n\n const stale = this.#synthRepo.getExpiredOrDirtyScopes();\n for (const { scope } of stale) {\n this.#dirtyScopes.add(scope);\n }\n\n this.#running = true;\n // Process any scopes discovered at startup immediately, then begin the periodic cycle\n await this.#debounceLoop();\n }\n\n shutdown(): Promise<void> {\n this.#running = false;\n\n if (this.#loopTimer !== undefined) {\n clearTimeout(this.#loopTimer);\n this.#loopTimer = undefined;\n }\n\n const inFlight = [...this.#inFlightPromises.values()];\n if (inFlight.length === 0) return Promise.resolve();\n\n const graceMs = 5_000;\n return Promise.race([\n Promise.allSettled(inFlight).then(() => undefined),\n new Promise<void>((resolve) => setTimeout(resolve, graceMs)),\n ]);\n }\n\n markDirty(scope: string): void {\n this.#dirtyScopes.add(scope);\n }\n\n #scheduleNextCycle(): void {\n if (!this.#running) return;\n const debounceMs = this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS;\n this.#loopTimer = setTimeout(() => {\n void this.#debounceLoop();\n }, debounceMs);\n }\n\n async #debounceLoop(): Promise<void> {\n const scopesToProcess = [...this.#dirtyScopes];\n\n for (const scope of scopesToProcess) {\n const inFlightTimeoutMs = this.#config.inFlightTimeoutMs ?? DEFAULT_IN_FLIGHT_TIMEOUT_MS;\n const synthesis = this.#synthRepo.getSynthesis(scope);\n\n if (synthesis?.inFlightSince !== null && synthesis?.inFlightSince !== undefined) {\n const inFlightMs = Date.now() - new Date(synthesis.inFlightSince).getTime();\n if (inFlightMs < inFlightTimeoutMs) {\n continue;\n }\n // Stale in-flight — clear it and allow resynthesis\n this.#synthRepo.clearInFlight(scope);\n }\n\n this.#dirtyScopes.delete(scope);\n const promise = this.#synthesizeScope(scope).finally(() => {\n this.#inFlightPromises.delete(scope);\n });\n this.#inFlightPromises.set(scope, promise);\n }\n\n this.#scheduleNextCycle();\n }\n\n async #synthesizeScope(scope: string): Promise<void> {\n this.#synthRepo.markInFlight(scope);\n\n try {\n const content = await this.#agentLoop.run(scope);\n const sourceHash = this.#synthRepo.computeSourceMemoryHash(scope);\n this.#synthRepo.saveSynthesis(scope, content, sourceHash);\n this.#failureCounts.delete(scope);\n } catch (err) {\n const failures = (this.#failureCounts.get(scope) ?? 0) + 1;\n this.#failureCounts.set(scope, failures);\n\n // Exponential backoff: re-queue with multiplied debounce up to MAX_BACKOFF_MULTIPLIER\n const backoffMultiplier = Math.min(failures, MAX_BACKOFF_MULTIPLIER);\n const backoffMs = (this.#config.debounceMs ?? DEFAULT_DEBOUNCE_MS) * backoffMultiplier;\n\n process.stderr.write(\n `membank synthesis: error for scope=${scope} failures=${failures} backoff=${backoffMs}ms: ${err instanceof Error ? err.message : String(err)}\\n`\n );\n\n setTimeout(() => {\n this.#dirtyScopes.add(scope);\n }, backoffMs);\n\n this.#synthRepo.clearInFlight(scope);\n }\n }\n}\n","import { readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport {\n DatabaseManager,\n EmbeddingService,\n isSynthesisEnabled,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n MIGRATIONS,\n PIN_BUDGET_THRESHOLD,\n ProjectRepository,\n QueryEngine,\n resolveProject,\n runScopeToProjectsMigration,\n SynthesisRepository,\n} from \"@membank/core\";\nimport { Server } from \"@modelcontextprotocol/sdk/server\";\nimport {\n CallToolRequestSchema,\n ErrorCode,\n ListToolsRequestSchema,\n McpError,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { ZodError } from \"zod\";\nimport {\n DeleteMemoryArgsSchema,\n MigrateArgsSchema,\n PinMemoryArgsSchema,\n QueryMemoryArgsSchema,\n ResolveReviewArgsSchema,\n SaveMemoryArgsSchema,\n UpdateMemoryArgsSchema,\n} from \"./schemas.js\";\nimport type { SynthesisConfig } from \"./synthesis/index.js\";\nimport { SynthesisAgentLoop, SynthesisEngine } from \"./synthesis/index.js\";\n\nconst SERVER_NAME = \"membank\";\nconst SERVER_VERSION = \"0.1.0\";\n\nexport interface CoreServices {\n db: DatabaseManager;\n embedding: EmbeddingService;\n repo: MemoryRepository;\n query: QueryEngine;\n projects: ProjectRepository;\n synthEngine?: SynthesisEngine;\n}\n\nexport interface ServerOptions {\n dbPath?: string;\n useInMemoryDb?: boolean;\n}\n\nfunction loadSynthesisConfig(): SynthesisConfig {\n const configPath = join(homedir(), \".membank\", \"config.json\");\n try {\n const raw = readFileSync(configPath, \"utf8\");\n const parsed = JSON.parse(raw) as {\n synthesis?: Partial<SynthesisConfig>;\n };\n return {\n enabled: parsed.synthesis?.enabled === true,\n maxTokensPerRun: parsed.synthesis?.maxTokensPerRun,\n debounceMs: parsed.synthesis?.debounceMs,\n stalenessDays: parsed.synthesis?.stalenessDays,\n inFlightTimeoutMs: parsed.synthesis?.inFlightTimeoutMs,\n };\n } catch {\n return { enabled: false };\n }\n}\n\nexport function initCore(options: ServerOptions = {}): CoreServices {\n const db = options.useInMemoryDb\n ? DatabaseManager.openInMemory()\n : DatabaseManager.open(options.dbPath);\n const embedding = new EmbeddingService();\n const projects = new ProjectRepository(db);\n const repo = new MemoryRepository(db, embedding, projects);\n const query = new QueryEngine(db, embedding, repo);\n\n const synthConfig = loadSynthesisConfig();\n let synthEngine: SynthesisEngine | undefined;\n\n if (synthConfig.enabled) {\n const synthRepo = new SynthesisRepository(db);\n const agentLoop = new SynthesisAgentLoop(\n {\n queryMemory: async (args) => {\n const projectHash = args.global === true ? undefined : (await resolveProject()).hash;\n const results = await query.query({\n query: args.query,\n projectHash,\n limit: args.limit ?? 20,\n includePinned: true,\n });\n return JSON.stringify(results);\n },\n getMemorySummary: async () => JSON.stringify(repo.stats()),\n },\n synthConfig\n );\n synthEngine = new SynthesisEngine(db, synthRepo, synthConfig, agentLoop);\n }\n\n return { db, embedding, repo, query, projects, synthEngine };\n}\n\nfunction parseArgs<T>(schema: { parse: (v: unknown) => T }, raw: unknown): T {\n try {\n return schema.parse(raw);\n } catch (e) {\n const msg = e instanceof ZodError ? (e.issues[0]?.message ?? e.message) : String(e);\n throw new McpError(ErrorCode.InvalidParams, msg);\n }\n}\n\nexport function createServer(core: CoreServices): Server {\n const server = new Server(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { capabilities: { tools: {} } }\n );\n\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [\n {\n name: \"list_memory_types\",\n description: \"Returns the ordered list of memory type values supported by membank.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"save_memory\",\n description:\n \"Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Memory content to save\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Memory type\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Optional tags\",\n },\n global: {\n type: \"boolean\",\n description: \"Save as a global memory, not tied to any project\",\n },\n },\n required: [\"content\", \"type\"],\n },\n },\n {\n name: \"update_memory\",\n description:\n \"Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to update\" },\n content: { type: \"string\", description: \"New content for the memory\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"New type for the memory (reclassification)\",\n },\n tags: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Replacement tags (optional)\",\n },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"delete_memory\",\n description: \"Delete a memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to delete\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"query_memory\",\n description:\n \"Search memories by semantic similarity. Returns results ranked by confidence score.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search text\" },\n type: {\n type: \"string\",\n enum: [...MEMORY_TYPE_VALUES],\n description: \"Filter by memory type\",\n },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n includePinned: {\n type: \"boolean\",\n description:\n \"Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.\",\n },\n global: {\n type: \"boolean\",\n description:\n \"Query global memories only. When omitted or false, queries the current project scope.\",\n },\n },\n required: [\"query\"],\n },\n },\n {\n name: \"migrate\",\n description:\n 'List or run named data migrations. Use mode \"list\" to see available migrations; mode \"run\" with a migration name to execute one.',\n inputSchema: {\n type: \"object\",\n properties: {\n mode: {\n type: \"string\",\n enum: [\"list\", \"run\"],\n description: 'Mode: \"list\" to see available migrations, \"run\" to execute one',\n },\n name: {\n type: \"string\",\n description: 'Migration name (required when mode is \"run\")',\n },\n },\n required: [\"mode\"],\n },\n },\n {\n name: \"pin_memory\",\n description:\n \"Pin a memory by id. Pinned memories are always injected into the session context.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to pin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"unpin_memory\",\n description: \"Unpin a memory by id. Removes the memory from guaranteed session injection.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to unpin\" },\n },\n required: [\"id\"],\n },\n },\n {\n name: \"get_memory_summary\",\n description:\n \"Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"list_flagged_memories\",\n description:\n \"List memories that have unresolved dedup review events. These were flagged automatically when a near-duplicate was saved (cosine similarity 0.75–0.92).\",\n inputSchema: { type: \"object\", properties: {}, required: [] },\n },\n {\n name: \"resolve_review\",\n description:\n \"Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Memory id to resolve review events for\" },\n },\n required: [\"id\"],\n },\n },\n ],\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n if (request.params.name === \"list_memory_types\") {\n try {\n return {\n content: [{ type: \"text\", text: JSON.stringify(listMemoryTypes()) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"save_memory\") {\n const args = parseArgs(SaveMemoryArgsSchema, request.params.arguments);\n const projectScope = args.global === true ? undefined : await resolveProject();\n\n try {\n const memory = await core.repo.save({\n content: args.content,\n type: args.type,\n tags: args.tags,\n projectScope,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(memory) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"update_memory\") {\n const args = parseArgs(UpdateMemoryArgsSchema, request.params.arguments);\n\n try {\n const memory = await core.repo.update(args.id, {\n content: args.content,\n type: args.type,\n tags: args.tags,\n });\n\n if (core.synthEngine !== undefined) {\n const scope =\n memory.projects.length > 0 ? (memory.projects[0]?.scopeHash ?? \"global\") : \"global\";\n core.synthEngine.markDirty(scope);\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"delete_memory\") {\n const args = parseArgs(DeleteMemoryArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n let memoryScopeBeforeDelete: string | undefined;\n if (core.synthEngine !== undefined) {\n const projectRow = core.db.db\n .prepare<[string], { scope_hash: string }>(\n `SELECT p.scope_hash FROM projects p\n JOIN memory_projects mp ON mp.project_id = p.id\n WHERE mp.memory_id = ?`\n )\n .get(args.id);\n memoryScopeBeforeDelete = projectRow?.scope_hash ?? \"global\";\n }\n\n await core.repo.delete(args.id);\n\n if (core.synthEngine !== undefined && memoryScopeBeforeDelete !== undefined) {\n core.synthEngine.markDirty(memoryScopeBeforeDelete);\n }\n\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"query_memory\") {\n const args = parseArgs(QueryMemoryArgsSchema, request.params.arguments);\n const projectHash = args.global === true ? undefined : (await resolveProject()).hash;\n\n try {\n const results = await core.query.query({\n query: args.query,\n type: args.type,\n projectHash,\n limit: args.limit ?? 10,\n includePinned: args.includePinned,\n });\n\n const serialised = results.map((r) => ({\n id: r.id,\n content: r.content,\n type: r.type,\n tags: r.tags,\n projects: r.projects,\n pinned: r.pinned,\n reviewEvents: r.reviewEvents,\n createdAt: r.createdAt,\n updatedAt: r.updatedAt,\n sourceHarness: r.sourceHarness,\n score: r.score,\n }));\n\n return {\n content: [{ type: \"text\", text: JSON.stringify(serialised) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"migrate\") {\n const args = parseArgs(MigrateArgsSchema, request.params.arguments);\n\n if (args.mode === \"list\") {\n return {\n content: [{ type: \"text\", text: JSON.stringify(MIGRATIONS) }],\n };\n }\n\n if (args.name === \"scope-to-projects\") {\n try {\n const result = await runScopeToProjectsMigration(core.projects);\n if (result === null) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({ error: \"No project found for current directory.\" }),\n },\n ],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new McpError(\n ErrorCode.InvalidParams,\n `Unknown migration: \"${args.name}\". Available: ${MIGRATIONS.map((m) => m.name).join(\", \")}`\n );\n }\n\n if (request.params.name === \"pin_memory\" || request.params.name === \"unpin_memory\") {\n const args = parseArgs(PinMemoryArgsSchema, request.params.arguments);\n const pinned = request.params.name === \"pin_memory\";\n\n try {\n const memory = core.repo.setPin(args.id, pinned);\n\n if (pinned) {\n const charCount = core.repo.getPinnedCharCount();\n if (charCount > PIN_BUDGET_THRESHOLD && !isSynthesisEnabled()) {\n const result = {\n ...memory,\n pinBudgetWarning: `Pinned memories now use ${charCount} characters (threshold: ${PIN_BUDGET_THRESHOLD}). Consider unpinning older memories or enabling synthesis to compress them.`,\n };\n return { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n }\n }\n\n return { content: [{ type: \"text\", text: JSON.stringify(memory) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"get_memory_summary\") {\n try {\n return { content: [{ type: \"text\", text: JSON.stringify(core.repo.stats()) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"list_flagged_memories\") {\n try {\n const memories = core.repo.listFlagged();\n return { content: [{ type: \"text\", text: JSON.stringify(memories) }] };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n if (request.params.name === \"resolve_review\") {\n const args = parseArgs(ResolveReviewArgsSchema, request.params.arguments);\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(args.id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${args.id}` }],\n isError: true,\n };\n }\n\n core.repo.resolveReviewEvents(args.id);\n return {\n content: [{ type: \"text\", text: JSON.stringify({ success: true, id: args.id }) }],\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { content: [{ type: \"text\", text: message }], isError: true };\n }\n }\n\n throw new Error(`Unknown tool: ${request.params.name}`);\n });\n\n return server;\n}\n","import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport type { CoreServices } from \"./server.js\";\nimport { createServer, initCore } from \"./server.js\";\n\nexport async function startServer(): Promise<void> {\n let core: CoreServices;\n try {\n core = initCore();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: failed to initialise core: ${message}\\n`);\n process.exit(1);\n }\n\n if (core.synthEngine !== undefined) {\n try {\n await core.synthEngine.init();\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n process.stderr.write(`membank: synthesis engine init failed: ${message}\\n`);\n }\n }\n\n const shutdown = async (): Promise<void> => {\n if (core.synthEngine !== undefined) {\n await core.synthEngine.shutdown();\n }\n process.exit(0);\n };\n\n process.on(\"SIGTERM\", () => {\n void shutdown();\n });\n process.on(\"SIGINT\", () => {\n void shutdown();\n });\n\n const server = createServer(core);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n"],"mappings":";;;;;;;;;;AAGA,MAAa,uBAAuB,EAAE,OAAO;CAC3C,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACpC,QAAQ,EAAE,SAAS,CAAC,UAAU;CAC/B,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO;CAC7C,I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AAI;EACF,MAAM,KAAK,YAAY,MAAM;UACtB,KAAK;EACZ,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;EAChE,QAAQ,OAAO,MAAM,0CAA0C,QAAQ,IAAI;;CAI/E,MAAM,WAAW,YAA2B;EAC1C,IAAI,KAAK,gBAAgB,KAAA,GACvB,MAAM,KAAK,YAAY,UAAU;EAEnC,QAAQ,KAAK,EAAE;;CAGjB,QAAQ,GAAG,iBAAiB;EAC1B,UAAe;GACf;CACF,QAAQ,GAAG,gBAAgB;EACzB,UAAe;GACf;CAEF,MAAM,SAAS,aAAa,KAAK;CACjC,MAAM,YAAY,IAAI,sBAAsB;CAC5C,MAAM,OAAO,QAAQ,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@membank/mcp",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,9 +17,10 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
+ "@anthropic-ai/claude-agent-sdk": "^0.2.131",
20
21
  "@modelcontextprotocol/sdk": "^1.29.0",
21
22
  "zod": "^4.4.3",
22
- "@membank/core": "0.8.0"
23
+ "@membank/core": "0.9.0"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/node": "^25.6.0",