@membank/mcp 0.5.0 → 0.6.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 +44 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -120,6 +120,30 @@ function createServer(core) {
|
|
|
120
120
|
},
|
|
121
121
|
required: ["query"]
|
|
122
122
|
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "pin_memory",
|
|
126
|
+
description: "Pin a memory by id. Pinned memories are always injected into the session context.",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: { id: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "Memory id to pin"
|
|
132
|
+
} },
|
|
133
|
+
required: ["id"]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "unpin_memory",
|
|
138
|
+
description: "Unpin a memory by id. Removes the memory from guaranteed session injection.",
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: { id: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "Memory id to unpin"
|
|
144
|
+
} },
|
|
145
|
+
required: ["id"]
|
|
146
|
+
}
|
|
123
147
|
}
|
|
124
148
|
] }));
|
|
125
149
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
@@ -257,6 +281,26 @@ function createServer(core) {
|
|
|
257
281
|
};
|
|
258
282
|
}
|
|
259
283
|
}
|
|
284
|
+
if (request.params.name === "pin_memory" || request.params.name === "unpin_memory") {
|
|
285
|
+
const id = request.params.arguments?.id;
|
|
286
|
+
if (typeof id !== "string" || id.trim() === "") throw new McpError(ErrorCode.InvalidParams, "id is required and must be a non-empty string");
|
|
287
|
+
const pinned = request.params.name === "pin_memory";
|
|
288
|
+
try {
|
|
289
|
+
const memory = core.repo.setPin(id, pinned);
|
|
290
|
+
return { content: [{
|
|
291
|
+
type: "text",
|
|
292
|
+
text: JSON.stringify(memory)
|
|
293
|
+
}] };
|
|
294
|
+
} catch (err) {
|
|
295
|
+
return {
|
|
296
|
+
content: [{
|
|
297
|
+
type: "text",
|
|
298
|
+
text: err instanceof Error ? err.message : String(err)
|
|
299
|
+
}],
|
|
300
|
+
isError: true
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
260
304
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
261
305
|
});
|
|
262
306
|
return server;
|
package/dist/index.mjs.map
CHANGED
|
@@ -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":";;;;;AAkBA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAcvB,SAAgB,SAAS,UAAyB,EAAE,EAAgB;CAClE,M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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 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 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 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 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":";;;;;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,EAC9C,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CAChC;AAED,QAAO,kBAAkB,+BAA+B,EACtD,OAAO;EACL;GACE,MAAM;GACN,aAAa;GACb,aAAa;IAAE,MAAM;IAAU,YAAY,EAAE;IAAE,UAAU,EAAE;IAAE;GAC9D;EACD;GACE,MAAM;GACN,aACE;GACF,aAAa;IACX,MAAM;IACN,YAAY;KACV,SAAS;MAAE,MAAM;MAAU,aAAa;MAA0B;KAClE,MAAM;MACJ,MAAM;MACN,MAAM,CAAC,GAAG,mBAAmB;MAC7B,aAAa;MACd;KACD,MAAM;MACJ,MAAM;MACN,OAAO,EAAE,MAAM,UAAU;MACzB,aAAa;MACd;KACD,OAA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AM,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.
|
|
3
|
+
"version": "0.6.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.
|
|
21
|
+
"@membank/core": "0.5.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^25.6.0",
|