@membank/mcp 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
- import { DatabaseManager, EmbeddingService, MemoryRepository, QueryEngine, listMemoryTypes, resolveScope } from "@membank/core";
2
+ import { DatabaseManager, EmbeddingService, MEMORY_TYPE_VALUES, MemoryRepository, QueryEngine, listMemoryTypes, resolveScope } 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
@@ -43,13 +43,7 @@ function createServer(core) {
43
43
  },
44
44
  type: {
45
45
  type: "string",
46
- enum: [
47
- "correction",
48
- "preference",
49
- "decision",
50
- "learning",
51
- "fact"
52
- ],
46
+ enum: [...MEMORY_TYPE_VALUES],
53
47
  description: "Memory type"
54
48
  },
55
49
  tags: {
@@ -112,13 +106,7 @@ function createServer(core) {
112
106
  },
113
107
  type: {
114
108
  type: "string",
115
- enum: [
116
- "correction",
117
- "preference",
118
- "decision",
119
- "learning",
120
- "fact"
121
- ],
109
+ enum: [...MEMORY_TYPE_VALUES],
122
110
  description: "Filter by memory type"
123
111
  },
124
112
  scope: {
@@ -154,13 +142,7 @@ function createServer(core) {
154
142
  const content = args?.content;
155
143
  const type = args?.type;
156
144
  if (typeof content !== "string" || content.trim() === "") throw new McpError(ErrorCode.InvalidParams, "content is required and must be a non-empty string");
157
- if (typeof type !== "string" || ![
158
- "correction",
159
- "preference",
160
- "decision",
161
- "learning",
162
- "fact"
163
- ].includes(type)) throw new McpError(ErrorCode.InvalidParams, "type is required and must be one of: correction, preference, decision, learning, fact");
145
+ 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");
164
146
  const tags = Array.isArray(args?.tags) ? args.tags : void 0;
165
147
  const scope = typeof args?.scope === "string" ? args.scope : await resolveScope();
166
148
  try {
@@ -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 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: [\"correction\", \"preference\", \"decision\", \"learning\", \"fact\"],\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: [\"correction\", \"preference\", \"decision\", \"learning\", \"fact\"],\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 (\n typeof type !== \"string\" ||\n ![\"correction\", \"preference\", \"decision\", \"learning\", \"fact\"].includes(type)\n ) {\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":";;;;;AAiBA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAcvB,SAAgB,SAAS,UAAyB,EAAE,EAAgB;CAClE,MAAM,KAAK,QAAQ,gBACf,gBAAgB,cAAc,GAC9B,gBAAgB,KAAK,QAAQ,OAAO;CACxC,MAAM,YAAY,IAAI,kBAAkB;CACxC,MAAM,OAAO,IAAI,iBAAiB,IAAI,UAAU;AAEhD,QAAO;EAAE;EAAI;EAAW;EAAM,OAAA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AAI,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 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":";;;;;AAkBA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAcvB,SAAgB,SAAS,UAAyB,EAAE,EAAgB;CAClE,MAAM,KAAK,QAAQ,gBACf,gBAAgB,cAAc,GAC9B,gBAAgB,KAAK,QAAQ,OAAO;CACxC,MAAM,YAAY,IAAI,kBAAkB;CACxC,MAAM,OAAO,IAAI,iBAAiB,IAAI,UAAU;AAEhD,QAAO;EAAE;EAAI;EAAW;EAAM,OAAA,IADZ,YAAY,IAAI,WAAW,KACV;EAAE;;AAGvC,SAAgB,aAAa,MAA4B;CACvD,MAAM,SAAS,IAAI,OACjB;EAAE,MAAM;EAAa,SAAS;EAAgB,E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 -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@modelcontextprotocol/sdk": "^1.29.0",
21
- "@membank/core": "0.0.3"
21
+ "@membank/core": "0.1.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^25.6.0",