@membank/mcp 0.14.0 → 0.14.2
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/bin.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/bin.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{readFileSync as e}from"node:fs";import{dirname as t,join as n}from"node:path";import{fileURLToPath as r}from"node:url";import{Command as i}from"commander";import{DatabaseManager as a,EmbeddingService as o,MEMORY_TYPE_VALUES as s,MIGRATIONS as c,MemoryTypeSchema as l,PIN_BUDGET_THRESHOLD as u,QueryEngine as d,SynthesisEngine as f,createMemoryRepository as p,createProjectRepository as m,createSynthesisAgentRunner as h,createSynthesisRepository as g,isSynthesisEnabled as _,listMemoryTypes as v,resolveProject as y,runScopeToProjectsMigration as b,saveMemory as x,updateMemory as S}from"@membank/core";import{StdioServerTransport as C}from"@modelcontextprotocol/sdk/server/stdio.js";import{homedir as w}from"node:os";import{Server as T}from"@modelcontextprotocol/sdk/server";import{CallToolRequestSchema as E,ErrorCode as D,ListToolsRequestSchema as O,McpError as k}from"@modelcontextprotocol/sdk/types.js";import{ZodError as A,z as j}from"zod";const M=j.object({content:j.string().min(1),type:l,tags:j.array(j.string()).optional(),global:j.boolean().optional()}),N=j.object({id:j.string().min(1),content:j.string().min(1).optional(),type:l.optional(),tags:j.array(j.string()).optional()}),P=j.object({id:j.string().min(1)}),F=j.object({query:j.string().min(1),type:l.optional(),limit:j.number().int().positive().optional(),includePinned:j.boolean().optional(),global:j.boolean().optional()}),I=j.discriminatedUnion(`mode`,[j.object({mode:j.literal(`list`)}),j.object({mode:j.literal(`run`),name:j.string().min(1)})]),L=j.object({id:j.string().min(1)}),R=j.object({id:j.string().min(1)});function z(){let t=n(w(),`.membank`,`config.json`);try{let n=e(t,`utf8`),r=JSON.parse(n);return{enabled:r.synthesis?.enabled===!0,maxTokensPerRun:r.synthesis?.maxTokensPerRun,debounceMs:r.synthesis?.debounceMs,stalenessDays:r.synthesis?.stalenessDays,inFlightTimeoutMs:r.synthesis?.inFlightTimeoutMs}}catch{return{enabled:!1}}}function B(e,t){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await y()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??20,includePinned:!0});return JSON.stringify(r)},getMemorySummary:async()=>JSON.stringify(e.stats())}}function V(e={}){let t=e.useInMemoryDb?a.openInMemory():a.open(e.dbPath),n=new o,r=m(t),i=p(t,r),s=new d(t,n,i),c=z(),l;return c.enabled&&(l=new f(g(t),c,h(B(i,s),c))),{db:t,embedding:n,repo:i,query:s,projects:r,synthEngine:l}}function H(e,t){try{return e.parse(t)}catch(e){let t=e instanceof A?e.issues[0]?.message??e.message:String(e);throw new k(D.InvalidParams,t)}}function U(e){let t=new T({name:`membank`,version:`0.1.0`},{capabilities:{tools:{}}});return t.setRequestHandler(O,()=>({tools:[{name:`list_memory_types`,description:`Returns the ordered list of memory type values supported by membank.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`save_memory`,description:`Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`Memory content to save`},type:{type:`string`,enum:[...s],description:`Memory type`},tags:{type:`array`,items:{type:`string`},description:`Optional tags`},global:{type:`boolean`,description:`Save as a global memory, not tied to any project`}},required:[`content`,`type`]}},{name:`update_memory`,description:`Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to update`},content:{type:`string`,description:`New content for the memory`},type:{type:`string`,enum:[...s],description:`New type for the memory (reclassification)`},tags:{type:`array`,items:{type:`string`},description:`Replacement tags (optional)`}},required:[`id`]}},{name:`delete_memory`,description:`Delete a memory by id.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to delete`}},required:[`id`]}},{name:`query_memory`,description:`Search memories by semantic similarity. Returns results ranked by confidence score.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search text`},type:{type:`string`,enum:[...s],description:`Filter by memory type`},limit:{type:`number`,description:`Maximum results to return (default 10)`},includePinned:{type:`boolean`,description:`Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.`},global:{type:`boolean`,description:`Query global memories only. When omitted or false, queries the current project scope.`}},required:[`query`]}},{name:`migrate`,description:`List or run named data migrations. Use mode "list" to see available migrations; mode "run" with a migration name to execute one.`,inputSchema:{type:`object`,properties:{mode:{type:`string`,enum:[`list`,`run`],description:`Mode: "list" to see available migrations, "run" to execute one`},name:{type:`string`,description:`Migration name (required when mode is "run")`}},required:[`mode`]}},{name:`pin_memory`,description:`Pin a memory by id. Pinned memories are always injected into the session context.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to pin`}},required:[`id`]}},{name:`unpin_memory`,description:`Unpin a memory by id. Removes the memory from guaranteed session injection.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to unpin`}},required:[`id`]}},{name:`get_memory_summary`,description:`Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`list_flagged_memories`,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).`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`resolve_review`,description:`Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to resolve review events for`}},required:[`id`]}}]})),t.setRequestHandler(E,async t=>{if(t.params.name===`list_memory_types`)try{return{content:[{type:`text`,text:JSON.stringify(v())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`save_memory`){let n=H(M,t.params.arguments),r=n.global===!0?void 0:await y();try{let t=await x({content:n.content,type:n.type,tags:n.tags,projectScope:r},{repo:e.repo,embedder:e.embedding});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??`global`:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`update_memory`){let n=H(N,t.params.arguments);try{let t=await S(n.id,{content:n.content,type:n.type,tags:n.tags},{repo:e.repo,embedder:e.embedding});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??`global`:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`delete_memory`){let n=H(P,t.params.arguments);try{let t=e.repo.findById(n.id);if(t===void 0)return{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0};let r=e.synthEngine===void 0?void 0:t.projects[0]?.scopeHash??`global`;return e.repo.delete(n.id),e.synthEngine!==void 0&&r!==void 0&&e.synthEngine.markDirty(r),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`query_memory`){let n=H(F,t.params.arguments),r=n.global===!0?void 0:(await y()).hash;try{let t=(await e.query.query({query:n.query,type:n.type,projectHash:r,limit:n.limit??10,includePinned:n.includePinned})).map(e=>({id:e.id,content:e.content,type:e.type,tags:e.tags,projects:e.projects,pinned:e.pinned,reviewEvents:e.reviewEvents,createdAt:e.createdAt,updatedAt:e.updatedAt,sourceHarness:e.sourceHarness,score:e.score}));return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`migrate`){let n=H(I,t.params.arguments);if(n.mode===`list`)return{content:[{type:`text`,text:JSON.stringify(c)}]};if(n.name===`scope-to-projects`)try{let t=await b(e.projects);return t===null?{content:[{type:`text`,text:JSON.stringify({error:`No project found for current directory.`})}],isError:!0}:{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}throw new k(D.InvalidParams,`Unknown migration: "${n.name}". Available: ${c.map(e=>e.name).join(`, `)}`)}if(t.params.name===`pin_memory`||t.params.name===`unpin_memory`){let n=H(L,t.params.arguments),r=t.params.name===`pin_memory`;try{let t=e.repo.setPin(n.id,r);if(r){let n=e.repo.getPinnedCharCount();if(n>u&&!_()){let e={...t,pinBudgetWarning:`Pinned memories now use ${n} characters (threshold: ${u}). Consider unpinning older memories or enabling synthesis to compress them.`};return{content:[{type:`text`,text:JSON.stringify(e)}]}}}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`get_memory_summary`)try{return{content:[{type:`text`,text:JSON.stringify(e.repo.stats())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`list_flagged_memories`)try{let t=e.repo.listFlagged();return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`resolve_review`){let n=H(R,t.params.arguments);try{return e.repo.findById(n.id)===void 0?{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0}:(e.repo.resolveReviewEvents(n.id),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]})}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}throw Error(`Unknown tool: ${t.params.name}`)}),t}async function W(){let e;try{e=V()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: failed to initialise core: ${t}\n`),process.exit(1)}if(e.synthEngine!==void 0)try{await e.synthEngine.init()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: synthesis engine init failed: ${t}\n`)}let t=async()=>{e.synthEngine!==void 0&&await e.synthEngine.shutdown(),process.exit(0)};process.on(`SIGTERM`,()=>{t()}),process.on(`SIGINT`,()=>{t()});let n=U(e),r=new C;await n.connect(r)}const{version:G}=JSON.parse(e(n(t(r(import.meta.url)),`../package.json`),`utf8`)),K=new i;K.name(`membank-mcp`).description(`Membank MCP stdio server — for harness integration`).version(G).action(W),await K.parseAsync(process.argv);export{};
|
|
2
|
+
import{readFileSync as e}from"node:fs";import{dirname as t,join as n}from"node:path";import{fileURLToPath as r}from"node:url";import{Command as i}from"commander";import{DatabaseManager as a,EmbeddingService as o,GLOBAL_SCOPE_HASH as s,MEMORY_TYPE_VALUES as c,MIGRATIONS as l,MemoryTypeSchema as u,PIN_BUDGET_THRESHOLD as d,QueryEngine as f,SynthesisEngine as p,createActivityLogger as m,createMemoryRepository as h,createProjectRepository as g,createSynthesisAgentRunner as _,createSynthesisRepository as v,deleteMemory as y,isSynthesisEnabled as b,listMemoryTypes as x,resolveProject as S,runScopeToProjectsMigration as C,saveMemory as w,updateMemory as T}from"@membank/core";import{StdioServerTransport as E}from"@modelcontextprotocol/sdk/server/stdio.js";import{homedir as D}from"node:os";import{Server as O}from"@modelcontextprotocol/sdk/server";import{CallToolRequestSchema as k,ErrorCode as A,ListToolsRequestSchema as j,McpError as M}from"@modelcontextprotocol/sdk/types.js";import{ZodError as N,z as P}from"zod";const F=P.object({content:P.string().min(1),type:u,tags:P.array(P.string()).optional(),global:P.boolean().optional()}),I=P.object({id:P.string().min(1),content:P.string().min(1).optional(),type:u.optional(),tags:P.array(P.string()).optional()}),L=P.object({id:P.string().min(1)}),R=P.object({query:P.string().min(1),type:u.optional(),limit:P.number().int().positive().optional(),includePinned:P.boolean().optional(),global:P.boolean().optional()}),z=P.discriminatedUnion(`mode`,[P.object({mode:P.literal(`list`)}),P.object({mode:P.literal(`run`),name:P.string().min(1)})]),B=P.object({id:P.string().min(1)}),V=P.object({id:P.string().min(1)});function H(){let t=n(D(),`.membank`,`config.json`);try{let n=e(t,`utf8`),r=JSON.parse(n);return{enabled:r.synthesis?.enabled===!0,maxTokensPerRun:r.synthesis?.maxTokensPerRun,debounceMs:r.synthesis?.debounceMs,stalenessDays:r.synthesis?.stalenessDays,inFlightTimeoutMs:r.synthesis?.inFlightTimeoutMs}}catch{return{enabled:!1}}}function U(e,t){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await S()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??20,includePinned:!0});return JSON.stringify(r)},getMemorySummary:async()=>{let t=await S();return JSON.stringify(e.stats(t.hash))}}}function W(e={}){let t=e.useInMemoryDb?a.openInMemory():a.open(e.dbPath),n=new o,r=g(t),i=h(t,r),s=m(t),c=new f(t,n,i,s),l=H(),u;return l.enabled&&(u=new p(v(t),l,_(U(i,c),l))),{db:t,embedding:n,repo:i,query:c,projects:r,activityLogger:s,synthEngine:u}}function G(e,t){try{return e.parse(t)}catch(e){let t=e instanceof N?e.issues[0]?.message??e.message:String(e);throw new M(A.InvalidParams,t)}}function K(e){let t=new O({name:`membank`,version:`0.1.0`},{capabilities:{tools:{}}});return t.setRequestHandler(j,()=>({tools:[{name:`list_memory_types`,description:`Returns the ordered list of memory type values supported by membank.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`save_memory`,description:`Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`Memory content to save`},type:{type:`string`,enum:[...c],description:`Memory type`},tags:{type:`array`,items:{type:`string`},description:`Optional tags`},global:{type:`boolean`,description:`Save as a global memory, not tied to any project`}},required:[`content`,`type`]}},{name:`update_memory`,description:`Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to update`},content:{type:`string`,description:`New content for the memory`},type:{type:`string`,enum:[...c],description:`New type for the memory (reclassification)`},tags:{type:`array`,items:{type:`string`},description:`Replacement tags (optional)`}},required:[`id`]}},{name:`delete_memory`,description:`Delete a memory by id.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to delete`}},required:[`id`]}},{name:`query_memory`,description:`Search memories by semantic similarity. Returns results ranked by confidence score.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search text`},type:{type:`string`,enum:[...c],description:`Filter by memory type`},limit:{type:`number`,description:`Maximum results to return (default 10)`},includePinned:{type:`boolean`,description:`Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.`},global:{type:`boolean`,description:`Query global memories only. When omitted or false, queries the current project scope.`}},required:[`query`]}},{name:`migrate`,description:`List or run named data migrations. Use mode "list" to see available migrations; mode "run" with a migration name to execute one.`,inputSchema:{type:`object`,properties:{mode:{type:`string`,enum:[`list`,`run`],description:`Mode: "list" to see available migrations, "run" to execute one`},name:{type:`string`,description:`Migration name (required when mode is "run")`}},required:[`mode`]}},{name:`pin_memory`,description:`Pin a memory by id. Pinned memories are always injected into the session context.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to pin`}},required:[`id`]}},{name:`unpin_memory`,description:`Unpin a memory by id. Removes the memory from guaranteed session injection.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to unpin`}},required:[`id`]}},{name:`get_memory_summary`,description:`Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`list_flagged_memories`,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).`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`resolve_review`,description:`Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to resolve review events for`}},required:[`id`]}}]})),t.setRequestHandler(k,async t=>{if(t.params.name===`list_memory_types`)try{return{content:[{type:`text`,text:JSON.stringify(x())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`save_memory`){let n=G(F,t.params.arguments),r=n.global===!0?void 0:await S();try{let t=await w({content:n.content,type:n.type,tags:n.tags,projectScope:r},{repo:e.repo,embedder:e.embedding,activityLogger:e.activityLogger});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??s:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`update_memory`){let n=G(I,t.params.arguments);try{let t=await T(n.id,{content:n.content,type:n.type,tags:n.tags},{repo:e.repo,embedder:e.embedding,activityLogger:e.activityLogger});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??s:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`delete_memory`){let n=G(L,t.params.arguments);try{let t=e.repo.findById(n.id);if(t===void 0)return{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0};let r=e.synthEngine===void 0?void 0:t.projects[0]?.scopeHash??s;return await y(n.id,e.repo,e.activityLogger),e.synthEngine!==void 0&&r!==void 0&&e.synthEngine.markDirty(r),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`query_memory`){let n=G(R,t.params.arguments),r=n.global===!0?void 0:(await S()).hash;try{let t=(await e.query.query({query:n.query,type:n.type,projectHash:r,limit:n.limit??10,includePinned:n.includePinned})).map(e=>({id:e.id,content:e.content,type:e.type,tags:e.tags,projects:e.projects,pinned:e.pinned,reviewEvents:e.reviewEvents,createdAt:e.createdAt,updatedAt:e.updatedAt,sourceHarness:e.sourceHarness,score:e.score}));return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`migrate`){let n=G(z,t.params.arguments);if(n.mode===`list`)return{content:[{type:`text`,text:JSON.stringify(l)}]};if(n.name===`scope-to-projects`)try{let t=await C(e.projects);return t===null?{content:[{type:`text`,text:JSON.stringify({error:`No project found for current directory.`})}],isError:!0}:{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}throw new M(A.InvalidParams,`Unknown migration: "${n.name}". Available: ${l.map(e=>e.name).join(`, `)}`)}if(t.params.name===`pin_memory`||t.params.name===`unpin_memory`){let n=G(B,t.params.arguments),r=t.params.name===`pin_memory`;try{let t=e.repo.setPin(n.id,r);if(r){let{hash:n}=await S(),r=e.repo.getPinnedCharCount(n);if(r>d&&!b()){let e={...t,pinBudgetWarning:`Pinned memories now use ${r} characters (threshold: ${d}). Consider unpinning older memories or enabling synthesis to compress them.`};return{content:[{type:`text`,text:JSON.stringify(e)}]}}}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`get_memory_summary`)try{let{hash:t}=await S();return{content:[{type:`text`,text:JSON.stringify(e.repo.stats(t))}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`list_flagged_memories`)try{let{hash:t}=await S(),n=e.repo.listFlagged(t);return{content:[{type:`text`,text:JSON.stringify(n)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`resolve_review`){let n=G(V,t.params.arguments);try{return e.repo.findById(n.id)===void 0?{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0}:(e.repo.resolveReviewEvents(n.id),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]})}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}throw Error(`Unknown tool: ${t.params.name}`)}),t}async function q(){let e;try{e=W()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: failed to initialise core: ${t}\n`),process.exit(1)}if(e.synthEngine!==void 0)try{await e.synthEngine.init()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: synthesis engine init failed: ${t}\n`)}let t=async()=>{e.synthEngine!==void 0&&await e.synthEngine.shutdown(),process.exit(0)};process.on(`SIGTERM`,()=>{t()}),process.on(`SIGINT`,()=>{t()});let n=K(e),r=new E;await n.connect(r)}const{version:J}=JSON.parse(e(n(t(r(import.meta.url)),`../package.json`),`utf8`)),Y=new i;Y.name(`membank-mcp`).description(`Membank MCP stdio server — for harness integration`).version(J).action(q),await Y.parseAsync(process.argv);export{};
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DatabaseManager as e,EmbeddingService as t,MEMORY_TYPE_VALUES as n,MIGRATIONS as r,MemoryTypeSchema as i,PIN_BUDGET_THRESHOLD as a,QueryEngine as o,SynthesisEngine as s,createClaudeCodeTranscriptReader as c,createExtractionAgentRunner as l,createExtractionRunRepository as u,createMemoryRepository as d,createProjectRepository as f,createSynthesisAgentRunner as p,createSynthesisRepository as m,isSynthesisEnabled as h,listMemoryTypes as g,resolveProject as _,runExtraction as v,runScopeToProjectsMigration as y,runSynthesis as b,saveMemory as x,updateMemory as S}from"@membank/core";import{StdioServerTransport as C}from"@modelcontextprotocol/sdk/server/stdio.js";import{readFileSync as w}from"node:fs";import{homedir as T}from"node:os";import{join as E}from"node:path";import{Server as D}from"@modelcontextprotocol/sdk/server";import{CallToolRequestSchema as O,ErrorCode as k,ListToolsRequestSchema as A,McpError as j}from"@modelcontextprotocol/sdk/types.js";import{ZodError as M,z as N}from"zod";const P=N.object({content:N.string().min(1),type:i,tags:N.array(N.string()).optional(),global:N.boolean().optional()}),F=N.object({id:N.string().min(1),content:N.string().min(1).optional(),type:i.optional(),tags:N.array(N.string()).optional()}),I=N.object({id:N.string().min(1)}),L=N.object({query:N.string().min(1),type:i.optional(),limit:N.number().int().positive().optional(),includePinned:N.boolean().optional(),global:N.boolean().optional()}),R=N.discriminatedUnion(`mode`,[N.object({mode:N.literal(`list`)}),N.object({mode:N.literal(`run`),name:N.string().min(1)})]),z=N.object({id:N.string().min(1)}),B=N.object({id:N.string().min(1)});function V(){let e=E(T(),`.membank`,`config.json`);try{let t=w(e,`utf8`),n=JSON.parse(t);return{enabled:n.synthesis?.enabled===!0,maxTokensPerRun:n.synthesis?.maxTokensPerRun,debounceMs:n.synthesis?.debounceMs,stalenessDays:n.synthesis?.stalenessDays,inFlightTimeoutMs:n.synthesis?.inFlightTimeoutMs}}catch{return{enabled:!1}}}function H(e,t,n){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await _()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??10,includePinned:!0});return JSON.stringify(r)},saveMemory:async t=>{let r=t.global===!0?void 0:await _(),a=await x({content:t.content,type:i.parse(t.type),tags:t.tags,projectScope:r,sourceHarness:`membank-extraction`},{repo:e,embedder:n});return JSON.stringify(a)},updateMemory:async t=>{let r=await S(t.id,{content:t.content,type:t.type===void 0?void 0:i.parse(t.type),tags:t.tags},{repo:e,embedder:n});return JSON.stringify(r)}}}function U(e,t){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await _()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??20,includePinned:!0});return JSON.stringify(r)},getMemorySummary:async()=>JSON.stringify(e.stats())}}function W(n={}){let r=n.useInMemoryDb?e.openInMemory():e.open(n.dbPath),i=new t,a=f(r),c=d(r,a),l=new o(r,i,c),u=V(),h;return u.enabled&&(h=new s(m(r),u,p(U(c,l),u))),{db:r,embedding:i,repo:c,query:l,projects:a,synthEngine:h}}function G(e,t){try{return e.parse(t)}catch(e){let t=e instanceof M?e.issues[0]?.message??e.message:String(e);throw new j(k.InvalidParams,t)}}function K(e){let t=new D({name:`membank`,version:`0.1.0`},{capabilities:{tools:{}}});return t.setRequestHandler(A,()=>({tools:[{name:`list_memory_types`,description:`Returns the ordered list of memory type values supported by membank.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`save_memory`,description:`Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`Memory content to save`},type:{type:`string`,enum:[...n],description:`Memory type`},tags:{type:`array`,items:{type:`string`},description:`Optional tags`},global:{type:`boolean`,description:`Save as a global memory, not tied to any project`}},required:[`content`,`type`]}},{name:`update_memory`,description:`Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to update`},content:{type:`string`,description:`New content for the memory`},type:{type:`string`,enum:[...n],description:`New type for the memory (reclassification)`},tags:{type:`array`,items:{type:`string`},description:`Replacement tags (optional)`}},required:[`id`]}},{name:`delete_memory`,description:`Delete a memory by id.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to delete`}},required:[`id`]}},{name:`query_memory`,description:`Search memories by semantic similarity. Returns results ranked by confidence score.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search text`},type:{type:`string`,enum:[...n],description:`Filter by memory type`},limit:{type:`number`,description:`Maximum results to return (default 10)`},includePinned:{type:`boolean`,description:`Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.`},global:{type:`boolean`,description:`Query global memories only. When omitted or false, queries the current project scope.`}},required:[`query`]}},{name:`migrate`,description:`List or run named data migrations. Use mode "list" to see available migrations; mode "run" with a migration name to execute one.`,inputSchema:{type:`object`,properties:{mode:{type:`string`,enum:[`list`,`run`],description:`Mode: "list" to see available migrations, "run" to execute one`},name:{type:`string`,description:`Migration name (required when mode is "run")`}},required:[`mode`]}},{name:`pin_memory`,description:`Pin a memory by id. Pinned memories are always injected into the session context.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to pin`}},required:[`id`]}},{name:`unpin_memory`,description:`Unpin a memory by id. Removes the memory from guaranteed session injection.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to unpin`}},required:[`id`]}},{name:`get_memory_summary`,description:`Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`list_flagged_memories`,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).`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`resolve_review`,description:`Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to resolve review events for`}},required:[`id`]}}]})),t.setRequestHandler(O,async t=>{if(t.params.name===`list_memory_types`)try{return{content:[{type:`text`,text:JSON.stringify(g())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`save_memory`){let n=G(P,t.params.arguments),r=n.global===!0?void 0:await _();try{let t=await x({content:n.content,type:n.type,tags:n.tags,projectScope:r},{repo:e.repo,embedder:e.embedding});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??`global`:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`update_memory`){let n=G(F,t.params.arguments);try{let t=await S(n.id,{content:n.content,type:n.type,tags:n.tags},{repo:e.repo,embedder:e.embedding});if(e.synthEngine!==void 0){let n=t.projects.length>0?t.projects[0]?.scopeHash??`global`:`global`;e.synthEngine.markDirty(n)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`delete_memory`){let n=G(I,t.params.arguments);try{let t=e.repo.findById(n.id);if(t===void 0)return{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0};let r=e.synthEngine===void 0?void 0:t.projects[0]?.scopeHash??`global`;return e.repo.delete(n.id),e.synthEngine!==void 0&&r!==void 0&&e.synthEngine.markDirty(r),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`query_memory`){let n=G(L,t.params.arguments),r=n.global===!0?void 0:(await _()).hash;try{let t=(await e.query.query({query:n.query,type:n.type,projectHash:r,limit:n.limit??10,includePinned:n.includePinned})).map(e=>({id:e.id,content:e.content,type:e.type,tags:e.tags,projects:e.projects,pinned:e.pinned,reviewEvents:e.reviewEvents,createdAt:e.createdAt,updatedAt:e.updatedAt,sourceHarness:e.sourceHarness,score:e.score}));return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`migrate`){let n=G(R,t.params.arguments);if(n.mode===`list`)return{content:[{type:`text`,text:JSON.stringify(r)}]};if(n.name===`scope-to-projects`)try{let t=await y(e.projects);return t===null?{content:[{type:`text`,text:JSON.stringify({error:`No project found for current directory.`})}],isError:!0}:{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}throw new j(k.InvalidParams,`Unknown migration: "${n.name}". Available: ${r.map(e=>e.name).join(`, `)}`)}if(t.params.name===`pin_memory`||t.params.name===`unpin_memory`){let n=G(z,t.params.arguments),r=t.params.name===`pin_memory`;try{let t=e.repo.setPin(n.id,r);if(r){let n=e.repo.getPinnedCharCount();if(n>a&&!h()){let e={...t,pinBudgetWarning:`Pinned memories now use ${n} characters (threshold: ${a}). Consider unpinning older memories or enabling synthesis to compress them.`};return{content:[{type:`text`,text:JSON.stringify(e)}]}}}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`get_memory_summary`)try{return{content:[{type:`text`,text:JSON.stringify(e.repo.stats())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`list_flagged_memories`)try{let t=e.repo.listFlagged();return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`resolve_review`){let n=G(B,t.params.arguments);try{return e.repo.findById(n.id)===void 0?{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0}:(e.repo.resolveReviewEvents(n.id),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]})}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}throw Error(`Unknown tool: ${t.params.name}`)}),t}async function q(){let e;try{e=W()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: failed to initialise core: ${t}\n`),process.exit(1)}if(e.synthEngine!==void 0)try{await e.synthEngine.init()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: synthesis engine init failed: ${t}\n`)}let t=async()=>{e.synthEngine!==void 0&&await e.synthEngine.shutdown(),process.exit(0)};process.on(`SIGTERM`,()=>{t()}),process.on(`SIGINT`,()=>{t()});let n=K(e),r=new C;await n.connect(r)}async function J(n){if(!h())throw Error(`Synthesis is not enabled. Run: membank config set synthesis.enabled true`);let r=e.open(),i=new t,a=f(r),s=d(r,a),c=new o(r,i,s),l=m(r),u=p(U(s,c),{enabled:!0}),g=n;if(n!==`global`&&!/^[0-9a-f]{16}$/.test(n)){let e=a.getByName(n);e!==void 0&&(g=e.scopeHash)}try{return await b(g,{synthRepo:l,agentRunner:u})}finally{r.close()}}async function Y(n){let r=e.open();try{let e=new t,i=d(r,f(r)),a=new o(r,e,i),s=u(r),p=l(H(i,a,e)),m=c(),h=n.projectHash??(await _()).hash;return await v({sessionId:n.sessionId,transcriptPath:n.transcriptPath,projectHash:h},{repo:s,transcripts:m,agent:p,config:{}})}finally{r.close()}}export{Y as runExtraction,J as runSynthesis,q as startServer};
|
|
1
|
+
import{DatabaseManager as e,EmbeddingService as t,GLOBAL_SCOPE_HASH as n,MEMORY_TYPE_VALUES as r,MIGRATIONS as i,MemoryTypeSchema as a,PIN_BUDGET_THRESHOLD as o,QueryEngine as s,SynthesisEngine as c,createActivityLogger as l,createClaudeCodeTranscriptReader as u,createExtractionAgentRunner as d,createExtractionRunRepository as f,createMemoryRepository as p,createProjectRepository as m,createSynthesisAgentRunner as h,createSynthesisRepository as g,deleteMemory as _,isSynthesisEnabled as v,listMemoryTypes as y,resolveProject as b,runExtraction as x,runScopeToProjectsMigration as S,runSynthesis as C,saveMemory as w,updateMemory as T}from"@membank/core";import{StdioServerTransport as E}from"@modelcontextprotocol/sdk/server/stdio.js";import{readFileSync as D}from"node:fs";import{homedir as O}from"node:os";import{join as k}from"node:path";import{Server as A}from"@modelcontextprotocol/sdk/server";import{CallToolRequestSchema as j,ErrorCode as M,ListToolsRequestSchema as N,McpError as P}from"@modelcontextprotocol/sdk/types.js";import{ZodError as F,z as I}from"zod";const L=I.object({content:I.string().min(1),type:a,tags:I.array(I.string()).optional(),global:I.boolean().optional()}),R=I.object({id:I.string().min(1),content:I.string().min(1).optional(),type:a.optional(),tags:I.array(I.string()).optional()}),z=I.object({id:I.string().min(1)}),B=I.object({query:I.string().min(1),type:a.optional(),limit:I.number().int().positive().optional(),includePinned:I.boolean().optional(),global:I.boolean().optional()}),V=I.discriminatedUnion(`mode`,[I.object({mode:I.literal(`list`)}),I.object({mode:I.literal(`run`),name:I.string().min(1)})]),H=I.object({id:I.string().min(1)}),U=I.object({id:I.string().min(1)});function W(){let e=k(O(),`.membank`,`config.json`);try{let t=D(e,`utf8`),n=JSON.parse(t);return{enabled:n.synthesis?.enabled===!0,maxTokensPerRun:n.synthesis?.maxTokensPerRun,debounceMs:n.synthesis?.debounceMs,stalenessDays:n.synthesis?.stalenessDays,inFlightTimeoutMs:n.synthesis?.inFlightTimeoutMs}}catch{return{enabled:!1}}}function G(e,t,n){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await b()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??10,includePinned:!0});return JSON.stringify(r)},saveMemory:async t=>{let r=t.global===!0?void 0:await b(),i=await w({content:t.content,type:a.parse(t.type),tags:t.tags,projectScope:r,sourceHarness:`membank-extraction`},{repo:e,embedder:n});return JSON.stringify(i)},updateMemory:async t=>{let r=await T(t.id,{content:t.content,type:t.type===void 0?void 0:a.parse(t.type),tags:t.tags},{repo:e,embedder:n});return JSON.stringify(r)}}}function K(e,t){return{queryMemory:async e=>{let n=e.global===!0?void 0:e.projectHash??(await b()).hash,r=await t.query({query:e.query,projectHash:n,limit:e.limit??20,includePinned:!0});return JSON.stringify(r)},getMemorySummary:async()=>{let t=await b();return JSON.stringify(e.stats(t.hash))}}}function q(n={}){let r=n.useInMemoryDb?e.openInMemory():e.open(n.dbPath),i=new t,a=m(r),o=p(r,a),u=l(r),d=new s(r,i,o,u),f=W(),_;return f.enabled&&(_=new c(g(r),f,h(K(o,d),f))),{db:r,embedding:i,repo:o,query:d,projects:a,activityLogger:u,synthEngine:_}}function J(e,t){try{return e.parse(t)}catch(e){let t=e instanceof F?e.issues[0]?.message??e.message:String(e);throw new P(M.InvalidParams,t)}}function Y(e){let t=new A({name:`membank`,version:`0.1.0`},{capabilities:{tools:{}}});return t.setRequestHandler(N,()=>({tools:[{name:`list_memory_types`,description:`Returns the ordered list of memory type values supported by membank.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`save_memory`,description:`Save a new memory. Handles deduplication automatically — near-identical memories (cosine similarity >0.92, same type and project) overwrite the existing record.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`Memory content to save`},type:{type:`string`,enum:[...r],description:`Memory type`},tags:{type:`array`,items:{type:`string`},description:`Optional tags`},global:{type:`boolean`,description:`Save as a global memory, not tied to any project`}},required:[`content`,`type`]}},{name:`update_memory`,description:`Update the content, type, and/or tags of an existing memory by id. All fields except id are optional.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to update`},content:{type:`string`,description:`New content for the memory`},type:{type:`string`,enum:[...r],description:`New type for the memory (reclassification)`},tags:{type:`array`,items:{type:`string`},description:`Replacement tags (optional)`}},required:[`id`]}},{name:`delete_memory`,description:`Delete a memory by id.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to delete`}},required:[`id`]}},{name:`query_memory`,description:`Search memories by semantic similarity. Returns results ranked by confidence score.`,inputSchema:{type:`object`,properties:{query:{type:`string`,description:`Search text`},type:{type:`string`,enum:[...r],description:`Filter by memory type`},limit:{type:`number`,description:`Maximum results to return (default 10)`},includePinned:{type:`boolean`,description:`Include pinned memories in results. Pinned memories are already injected into session context, so excluded by default to avoid duplicates.`},global:{type:`boolean`,description:`Query global memories only. When omitted or false, queries the current project scope.`}},required:[`query`]}},{name:`migrate`,description:`List or run named data migrations. Use mode "list" to see available migrations; mode "run" with a migration name to execute one.`,inputSchema:{type:`object`,properties:{mode:{type:`string`,enum:[`list`,`run`],description:`Mode: "list" to see available migrations, "run" to execute one`},name:{type:`string`,description:`Migration name (required when mode is "run")`}},required:[`mode`]}},{name:`pin_memory`,description:`Pin a memory by id. Pinned memories are always injected into the session context.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to pin`}},required:[`id`]}},{name:`unpin_memory`,description:`Unpin a memory by id. Removes the memory from guaranteed session injection.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to unpin`}},required:[`id`]}},{name:`get_memory_summary`,description:`Returns aggregate stats for session orientation: total memories, counts by type, pinned count, and review queue size.`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`list_flagged_memories`,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).`,inputSchema:{type:`object`,properties:{},required:[]}},{name:`resolve_review`,description:`Dismiss all unresolved review events for a memory. Use after reviewing the memory and deciding it should be kept as-is.`,inputSchema:{type:`object`,properties:{id:{type:`string`,description:`Memory id to resolve review events for`}},required:[`id`]}}]})),t.setRequestHandler(j,async t=>{if(t.params.name===`list_memory_types`)try{return{content:[{type:`text`,text:JSON.stringify(y())}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`save_memory`){let r=J(L,t.params.arguments),i=r.global===!0?void 0:await b();try{let t=await w({content:r.content,type:r.type,tags:r.tags,projectScope:i},{repo:e.repo,embedder:e.embedding,activityLogger:e.activityLogger});if(e.synthEngine!==void 0){let r=t.projects.length>0?t.projects[0]?.scopeHash??n:`global`;e.synthEngine.markDirty(r)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`update_memory`){let r=J(R,t.params.arguments);try{let t=await T(r.id,{content:r.content,type:r.type,tags:r.tags},{repo:e.repo,embedder:e.embedding,activityLogger:e.activityLogger});if(e.synthEngine!==void 0){let r=t.projects.length>0?t.projects[0]?.scopeHash??n:`global`;e.synthEngine.markDirty(r)}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`delete_memory`){let r=J(z,t.params.arguments);try{let t=e.repo.findById(r.id);if(t===void 0)return{content:[{type:`text`,text:`Memory not found: ${r.id}`}],isError:!0};let i=e.synthEngine===void 0?void 0:t.projects[0]?.scopeHash??n;return await _(r.id,e.repo,e.activityLogger),e.synthEngine!==void 0&&i!==void 0&&e.synthEngine.markDirty(i),{content:[{type:`text`,text:JSON.stringify({success:!0,id:r.id})}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`query_memory`){let n=J(B,t.params.arguments),r=n.global===!0?void 0:(await b()).hash;try{let t=(await e.query.query({query:n.query,type:n.type,projectHash:r,limit:n.limit??10,includePinned:n.includePinned})).map(e=>({id:e.id,content:e.content,type:e.type,tags:e.tags,projects:e.projects,pinned:e.pinned,reviewEvents:e.reviewEvents,createdAt:e.createdAt,updatedAt:e.updatedAt,sourceHarness:e.sourceHarness,score:e.score}));return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`migrate`){let n=J(V,t.params.arguments);if(n.mode===`list`)return{content:[{type:`text`,text:JSON.stringify(i)}]};if(n.name===`scope-to-projects`)try{let t=await S(e.projects);return t===null?{content:[{type:`text`,text:JSON.stringify({error:`No project found for current directory.`})}],isError:!0}:{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}throw new P(M.InvalidParams,`Unknown migration: "${n.name}". Available: ${i.map(e=>e.name).join(`, `)}`)}if(t.params.name===`pin_memory`||t.params.name===`unpin_memory`){let n=J(H,t.params.arguments),r=t.params.name===`pin_memory`;try{let t=e.repo.setPin(n.id,r);if(r){let{hash:n}=await b(),r=e.repo.getPinnedCharCount(n);if(r>o&&!v()){let e={...t,pinBudgetWarning:`Pinned memories now use ${r} characters (threshold: ${o}). Consider unpinning older memories or enabling synthesis to compress them.`};return{content:[{type:`text`,text:JSON.stringify(e)}]}}}return{content:[{type:`text`,text:JSON.stringify(t)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(t.params.name===`get_memory_summary`)try{let{hash:t}=await b();return{content:[{type:`text`,text:JSON.stringify(e.repo.stats(t))}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`list_flagged_memories`)try{let{hash:t}=await b(),n=e.repo.listFlagged(t);return{content:[{type:`text`,text:JSON.stringify(n)}]}}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}if(t.params.name===`resolve_review`){let n=J(U,t.params.arguments);try{return e.repo.findById(n.id)===void 0?{content:[{type:`text`,text:`Memory not found: ${n.id}`}],isError:!0}:(e.repo.resolveReviewEvents(n.id),{content:[{type:`text`,text:JSON.stringify({success:!0,id:n.id})}]})}catch(e){return{content:[{type:`text`,text:e instanceof Error?e.message:String(e)}],isError:!0}}}throw Error(`Unknown tool: ${t.params.name}`)}),t}async function X(){let e;try{e=q()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: failed to initialise core: ${t}\n`),process.exit(1)}if(e.synthEngine!==void 0)try{await e.synthEngine.init()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`membank: synthesis engine init failed: ${t}\n`)}let t=async()=>{e.synthEngine!==void 0&&await e.synthEngine.shutdown(),process.exit(0)};process.on(`SIGTERM`,()=>{t()}),process.on(`SIGINT`,()=>{t()});let n=Y(e),r=new E;await n.connect(r)}async function Z(r){if(!v())throw Error(`Synthesis is not enabled. Run: membank config set synthesis.enabled true`);let i=e.open(),a=new t,o=m(i),c=p(i,o),l=new s(i,a,c),u=g(i),d=h(K(c,l),{enabled:!0}),f=r;if(r===`global`)f=n;else if(!/^[0-9a-f]{16}$/.test(r)){let e=o.getByName(r);e!==void 0&&(f=e.scopeHash)}try{return await C(f,{synthRepo:u,agentRunner:d})}finally{i.close()}}async function Q(n){let r=e.open();try{let e=new t,i=p(r,m(r)),a=new s(r,e,i),o=f(r),c=d(G(i,a,e)),l=u(),h=n.projectHash??(await b()).hash;return await x({sessionId:n.sessionId,transcriptPath:n.transcriptPath,projectHash:h},{repo:o,transcripts:l,agent:c,config:{}})}finally{r.close()}}export{Q as runExtraction,Z as runSynthesis,X as startServer};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@membank/mcp",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
25
25
|
"commander": "^14.0.3",
|
|
26
26
|
"zod": "^4.4.3",
|
|
27
|
-
"@membank/core": "0.
|
|
27
|
+
"@membank/core": "0.12.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^25.6.0",
|