@membank/mcp 0.5.0 → 0.7.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,5 +1,5 @@
1
1
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
- import { DatabaseManager, EmbeddingService, MEMORY_TYPE_VALUES, MemoryRepository, QueryEngine, listMemoryTypes, resolveScope } from "@membank/core";
2
+ import { DatabaseManager, EmbeddingService, MEMORY_TYPE_VALUES, MemoryRepository, ProjectRepository, QueryEngine, listMemoryTypes, resolveProject } from "@membank/core";
3
3
  import { Server } from "@modelcontextprotocol/sdk/server";
4
4
  import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError } from "@modelcontextprotocol/sdk/types.js";
5
5
  //#region src/server.ts
@@ -8,12 +8,14 @@ const SERVER_VERSION = "0.1.0";
8
8
  function initCore(options = {}) {
9
9
  const db = options.useInMemoryDb ? DatabaseManager.openInMemory() : DatabaseManager.open(options.dbPath);
10
10
  const embedding = new EmbeddingService();
11
- const repo = new MemoryRepository(db, embedding);
11
+ const projects = new ProjectRepository(db);
12
+ const repo = new MemoryRepository(db, embedding, projects);
12
13
  return {
13
14
  db,
14
15
  embedding,
15
16
  repo,
16
- query: new QueryEngine(db, embedding, repo)
17
+ query: new QueryEngine(db, embedding, repo),
18
+ projects
17
19
  };
18
20
  }
19
21
  function createServer(core) {
@@ -120,6 +122,30 @@ function createServer(core) {
120
122
  },
121
123
  required: ["query"]
122
124
  }
125
+ },
126
+ {
127
+ name: "pin_memory",
128
+ description: "Pin a memory by id. Pinned memories are always injected into the session context.",
129
+ inputSchema: {
130
+ type: "object",
131
+ properties: { id: {
132
+ type: "string",
133
+ description: "Memory id to pin"
134
+ } },
135
+ required: ["id"]
136
+ }
137
+ },
138
+ {
139
+ name: "unpin_memory",
140
+ description: "Unpin a memory by id. Removes the memory from guaranteed session injection.",
141
+ inputSchema: {
142
+ type: "object",
143
+ properties: { id: {
144
+ type: "string",
145
+ description: "Memory id to unpin"
146
+ } },
147
+ required: ["id"]
148
+ }
123
149
  }
124
150
  ] }));
125
151
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -144,13 +170,21 @@ function createServer(core) {
144
170
  if (typeof content !== "string" || content.trim() === "") throw new McpError(ErrorCode.InvalidParams, "content is required and must be a non-empty string");
145
171
  if (typeof type !== "string" || !MEMORY_TYPE_VALUES.includes(type)) throw new McpError(ErrorCode.InvalidParams, "type is required and must be one of: correction, preference, decision, learning, fact");
146
172
  const tags = Array.isArray(args?.tags) ? args.tags : void 0;
147
- const scope = typeof args?.scope === "string" ? args.scope : await resolveScope();
173
+ let projectHash;
174
+ if (typeof args?.scope === "string") {
175
+ projectHash = args.scope;
176
+ core.projects.upsertByHash(args.scope, `project-${args.scope.slice(0, 8)}`);
177
+ } else {
178
+ const project = await resolveProject();
179
+ core.projects.upsertByHash(project.hash, project.name);
180
+ projectHash = project.hash;
181
+ }
148
182
  try {
149
183
  const memory = await core.repo.save({
150
184
  content,
151
185
  type,
152
186
  tags,
153
- scope
187
+ projectHash
154
188
  });
155
189
  return { content: [{
156
190
  type: "text",
@@ -226,20 +260,20 @@ function createServer(core) {
226
260
  const queryText = args?.query;
227
261
  if (typeof queryText !== "string" || queryText.trim() === "") throw new McpError(ErrorCode.InvalidParams, "query is required and must be a non-empty string");
228
262
  const type = args?.type;
229
- const scope = args?.scope;
263
+ const projectHash = args?.scope;
230
264
  const limit = typeof args?.limit === "number" ? args.limit : 10;
231
265
  try {
232
266
  const serialised = (await core.query.query({
233
267
  query: queryText,
234
268
  type,
235
- scope,
269
+ projectHash,
236
270
  limit
237
271
  })).map((r) => ({
238
272
  id: r.id,
239
273
  content: r.content,
240
274
  type: r.type,
241
275
  tags: r.tags,
242
- scope: r.scope,
276
+ projects: r.projects,
243
277
  pinned: r.pinned,
244
278
  score: r.score
245
279
  }));
@@ -257,6 +291,26 @@ function createServer(core) {
257
291
  };
258
292
  }
259
293
  }
294
+ if (request.params.name === "pin_memory" || request.params.name === "unpin_memory") {
295
+ const id = request.params.arguments?.id;
296
+ if (typeof id !== "string" || id.trim() === "") throw new McpError(ErrorCode.InvalidParams, "id is required and must be a non-empty string");
297
+ const pinned = request.params.name === "pin_memory";
298
+ try {
299
+ const memory = core.repo.setPin(id, pinned);
300
+ return { content: [{
301
+ type: "text",
302
+ text: JSON.stringify(memory)
303
+ }] };
304
+ } catch (err) {
305
+ return {
306
+ content: [{
307
+ type: "text",
308
+ text: err instanceof Error ? err.message : String(err)
309
+ }],
310
+ isError: true
311
+ };
312
+ }
313
+ }
260
314
  throw new Error(`Unknown tool: ${request.params.name}`);
261
315
  });
262
316
  return server;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/server.ts","../src/index.ts"],"sourcesContent":["import type { MemoryType } from \"@membank/core\";\nimport {\n DatabaseManager,\n EmbeddingService,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n QueryEngine,\n resolveScope,\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\";\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}\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 repo = new MemoryRepository(db, embedding);\n const query = new QueryEngine(db, embedding, repo);\n return { db, embedding, repo, query };\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 scope) 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 scope: { type: \"string\", description: \"Scope (defaults to resolved project scope)\" },\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 scope: { type: \"string\", description: \"Filter by scope\" },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n },\n required: [\"query\"],\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 = request.params.arguments as Record<string, unknown> | undefined;\n const content = args?.content;\n const type = args?.type;\n\n if (typeof content !== \"string\" || content.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"content is required and must be a non-empty string\"\n );\n }\n\n if (typeof type !== \"string\" || !(MEMORY_TYPE_VALUES as readonly string[]).includes(type)) {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"type is required and must be one of: correction, preference, decision, learning, fact\"\n );\n }\n\n const tags = Array.isArray(args?.tags) ? (args.tags as string[]) : undefined;\n const scope = typeof args?.scope === \"string\" ? args.scope : await resolveScope();\n\n try {\n const memory = await core.repo.save({\n content,\n type: type as MemoryType,\n tags,\n 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 = request.params.arguments as Record<string, unknown> | undefined;\n const id = args?.id;\n const content = args?.content;\n\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"id is required and must be a non-empty string\"\n );\n }\n\n if (typeof content !== \"string\" || content.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"content is required and must be a non-empty string\"\n );\n }\n\n const tags = Array.isArray(args?.tags) ? (args.tags as string[]) : undefined;\n\n try {\n const memory = await core.repo.update(id, { content, tags });\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 = request.params.arguments as Record<string, unknown> | undefined;\n const id = args?.id;\n\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"id is required and must be a non-empty string\"\n );\n }\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${id}` }],\n isError: true,\n };\n }\n\n await core.repo.delete(id);\n return { content: [{ type: \"text\", text: JSON.stringify({ success: true, id }) }] };\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 = request.params.arguments as Record<string, unknown> | undefined;\n const queryText = args?.query;\n\n if (typeof queryText !== \"string\" || queryText.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"query is required and must be a non-empty string\"\n );\n }\n\n const type = args?.type as MemoryType | undefined;\n const scope = args?.scope as string | undefined;\n const limit = typeof args?.limit === \"number\" ? args.limit : 10;\n\n try {\n const results = await core.query.query({ query: queryText, type, scope, limit });\n\n const serialised = results.map((r) => ({\n id: r.id,\n content: r.content,\n type: r.type,\n tags: r.tags,\n scope: r.scope,\n pinned: r.pinned,\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 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":";;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I;AACJ,KAAI;AACF,SAAO,UAAU;UACV,KAAK;EACZ,MAAM,UAAU,eAAe,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":[],"sources":["../src/server.ts","../src/index.ts"],"sourcesContent":["import type { MemoryType } from \"@membank/core\";\nimport {\n DatabaseManager,\n EmbeddingService,\n listMemoryTypes,\n MEMORY_TYPE_VALUES,\n MemoryRepository,\n ProjectRepository,\n QueryEngine,\n resolveProject,\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\";\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\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 scope) 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 scope: { type: \"string\", description: \"Scope (defaults to resolved project scope)\" },\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 scope: { type: \"string\", description: \"Filter by scope\" },\n limit: { type: \"number\", description: \"Maximum results to return (default 10)\" },\n },\n required: [\"query\"],\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 = request.params.arguments as Record<string, unknown> | undefined;\n const content = args?.content;\n const type = args?.type;\n\n if (typeof content !== \"string\" || content.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"content is required and must be a non-empty string\"\n );\n }\n\n if (typeof type !== \"string\" || !(MEMORY_TYPE_VALUES as readonly string[]).includes(type)) {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"type is required and must be one of: correction, preference, decision, learning, fact\"\n );\n }\n\n const tags = Array.isArray(args?.tags) ? (args.tags as string[]) : undefined;\n\n let projectHash: string | undefined;\n if (typeof args?.scope === \"string\") {\n projectHash = args.scope;\n core.projects.upsertByHash(args.scope, `project-${args.scope.slice(0, 8)}`);\n } else {\n const project = await resolveProject();\n core.projects.upsertByHash(project.hash, project.name);\n projectHash = project.hash;\n }\n\n try {\n const memory = await core.repo.save({\n content,\n type: type as MemoryType,\n tags,\n projectHash,\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 = request.params.arguments as Record<string, unknown> | undefined;\n const id = args?.id;\n const content = args?.content;\n\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"id is required and must be a non-empty string\"\n );\n }\n\n if (typeof content !== \"string\" || content.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"content is required and must be a non-empty string\"\n );\n }\n\n const tags = Array.isArray(args?.tags) ? (args.tags as string[]) : undefined;\n\n try {\n const memory = await core.repo.update(id, { content, tags });\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 = request.params.arguments as Record<string, unknown> | undefined;\n const id = args?.id;\n\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"id is required and must be a non-empty string\"\n );\n }\n\n try {\n const exists =\n core.db.db\n .prepare<[string], { id: string }>(`SELECT id FROM memories WHERE id = ?`)\n .get(id) !== undefined;\n\n if (!exists) {\n return {\n content: [{ type: \"text\", text: `Memory not found: ${id}` }],\n isError: true,\n };\n }\n\n await core.repo.delete(id);\n return { content: [{ type: \"text\", text: JSON.stringify({ success: true, id }) }] };\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 = request.params.arguments as Record<string, unknown> | undefined;\n const queryText = args?.query;\n\n if (typeof queryText !== \"string\" || queryText.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"query is required and must be a non-empty string\"\n );\n }\n\n const type = args?.type as MemoryType | undefined;\n const projectHash = args?.scope as string | undefined;\n const limit = typeof args?.limit === \"number\" ? args.limit : 10;\n\n try {\n const results = await core.query.query({ query: queryText, type, projectHash, limit });\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 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 === \"pin_memory\" || request.params.name === \"unpin_memory\") {\n const args = request.params.arguments as Record<string, unknown> | undefined;\n const id = args?.id;\n\n if (typeof id !== \"string\" || id.trim() === \"\") {\n throw new McpError(\n ErrorCode.InvalidParams,\n \"id is required and must be a non-empty string\"\n );\n }\n\n const pinned = request.params.name === \"pin_memory\";\n\n try {\n const memory = core.repo.setPin(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":";;;;;AAmBA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAevB,SAAgB,SAAS,UAAyB,EAAE,EAAgB;CAClE,MAAM,KAAK,QAAQ,gBACf,gBAAgB,cAAc,GAC9B,gBAAgB,KAAK,QAAQ,OAAO;CACxC,MAAM,YAAY,IAAI,kBAAkB;CACxC,MAAM,WAAW,IAAI,kBAAkB,GAAG;CAC1C,MAAM,OAAO,IAAI,iBAAiB,IAAI,WAAW,SAAS;AAE1D,QAAO;EAAE;EAAI;EAAW;EAAM,OAAA,IADZ,YAAY,IAAI,WAAW,KACV;EAAE;EAAU;;AAGjD,SAAgB,aAAa,MAA4B;CACvD,MAAM,SAAS,IAAI,OACjB;EAAE,MAAM;EAAa,SAAS;EAAgB,EAC9C,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CAChC;AAED,QAAO,kBAAkB,+BAA+B,EACtD,OAAO;EACL;GACE,MAAM;GACN,aA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AM,IAAI,SACR,UAAU,eACV,gDACD;GAGH,MAAM,SAAS,QAAQ,OAAO,SAAS;AAEvC,OAAI;IACF,MAAM,SAAS,KAAK,KAAK,OAAO,IAAI,OAAO;AAC3C,WAAO,EAAE,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,KAAK,UAAU,OAAO;KAAE,CAAC,EAAE;YAC7D,KAAK;AAEZ,WAAO;KAAE,SAAS,CAAC;MAAE,MAAM;MAAQ,MADnB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;MACd,CAAC;KAAE,SAAS;KAAM;;;AAIxE,QAAM,IAAI,MAAM,iBAAiB,QAAQ,OAAO,OAAO;GACvD;AAEF,QAAO;;;;AC/UT,eAAsB,cAA6B;CACjD,IAAI;AACJ,KAAI;AACF,SAAO,UAAU;UACV,KAAK;EACZ,MAAM,UAAU,eAAe,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@membank/mcp",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@modelcontextprotocol/sdk": "^1.29.0",
21
- "@membank/core": "0.5.0"
21
+ "@membank/core": "0.6.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^25.6.0",