@hasna/mementos 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/mcp/index.js +75 -15
  2. package/package.json +1 -1
package/dist/mcp/index.js CHANGED
@@ -4936,7 +4936,7 @@ function formatMemory(m) {
4936
4936
  return parts.join(`
4937
4937
  `);
4938
4938
  }
4939
- server.tool("memory_save", "Save a memory (create or upsert). Use scope 'global' for all agents, 'shared' for project-level, 'private' for single agent.", {
4939
+ server.tool("memory_save", "Save/upsert a memory. scope: global=all agents, shared=project, private=single agent.", {
4940
4940
  key: exports_external.string().describe("Unique key for the memory"),
4941
4941
  value: exports_external.string().describe("Memory content/value"),
4942
4942
  scope: exports_external.enum(["global", "shared", "private"]).optional().describe("Memory scope (default: private)"),
@@ -4954,8 +4954,7 @@ server.tool("memory_save", "Save a memory (create or upsert). Use scope 'global'
4954
4954
  try {
4955
4955
  ensureAutoProject();
4956
4956
  const memory = createMemory(args);
4957
- return { content: [{ type: "text", text: `Memory saved:
4958
- ${formatMemory(memory)}` }] };
4957
+ return { content: [{ type: "text", text: `Saved: ${memory.key} (${memory.id.slice(0, 8)})` }] };
4959
4958
  } catch (e) {
4960
4959
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
4961
4960
  }
@@ -4997,7 +4996,7 @@ ${formatMemory(best.memory)}`
4997
4996
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
4998
4997
  }
4999
4998
  });
5000
- server.tool("memory_list", "List memories with optional filters", {
4999
+ server.tool("memory_list", "List memories. Default: compact lines. full=true for complete JSON objects.", {
5001
5000
  scope: exports_external.enum(["global", "shared", "private"]).optional(),
5002
5001
  category: exports_external.enum(["preference", "fact", "knowledge", "history"]).optional(),
5003
5002
  tags: exports_external.array(exports_external.string()).optional(),
@@ -5007,20 +5006,36 @@ server.tool("memory_list", "List memories with optional filters", {
5007
5006
  project_id: exports_external.string().optional(),
5008
5007
  session_id: exports_external.string().optional(),
5009
5008
  status: exports_external.enum(["active", "archived", "expired"]).optional(),
5010
- limit: exports_external.coerce.number().optional().describe("Max results (default: 50)"),
5011
- offset: exports_external.coerce.number().optional()
5009
+ limit: exports_external.coerce.number().optional().describe("Max results (default: 10)"),
5010
+ offset: exports_external.coerce.number().optional(),
5011
+ full: exports_external.boolean().optional().describe("Return full Memory objects as JSON instead of compact lines"),
5012
+ fields: exports_external.array(exports_external.string()).optional().describe("Filter fields in full mode: e.g. ['key','value','importance']")
5012
5013
  }, async (args) => {
5013
5014
  try {
5015
+ const { full, fields, ...filterArgs } = args;
5014
5016
  const filter = {
5015
- ...args,
5016
- limit: args.limit || 50
5017
+ ...filterArgs,
5018
+ limit: filterArgs.limit || 10
5017
5019
  };
5018
5020
  const memories = listMemories(filter);
5019
5021
  if (memories.length === 0) {
5020
- return { content: [{ type: "text", text: "No memories found matching filters." }] };
5022
+ return { content: [{ type: "text", text: "No memories found." }] };
5023
+ }
5024
+ if (full) {
5025
+ const compact = memories.map((m) => {
5026
+ const obj = Object.fromEntries(Object.entries(m).filter(([k, v]) => {
5027
+ if (v === null || v === undefined)
5028
+ return false;
5029
+ if (fields && fields.length > 0)
5030
+ return fields.includes(k);
5031
+ return true;
5032
+ }));
5033
+ return obj;
5034
+ });
5035
+ return { content: [{ type: "text", text: JSON.stringify(compact, null, 2) }] };
5021
5036
  }
5022
- const lines = memories.map((m, i) => `${i + 1}. [${m.scope}/${m.category}] ${m.key} = ${m.value.slice(0, 100)}${m.value.length > 100 ? "..." : ""} (importance: ${m.importance}, id: ${m.id.slice(0, 8)})`);
5023
- return { content: [{ type: "text", text: `${memories.length} memor${memories.length === 1 ? "y" : "ies"} found:
5037
+ const lines = memories.map((m, i) => `${i + 1}. [${m.scope}/${m.category}] ${m.key} = ${m.value.slice(0, 100)}${m.value.length > 100 ? "..." : ""} (imp:${m.importance} id:${m.id.slice(0, 8)})`);
5038
+ return { content: [{ type: "text", text: `${memories.length} memories:
5024
5039
  ${lines.join(`
5025
5040
  `)}` }] };
5026
5041
  } catch (e) {
@@ -5195,7 +5210,7 @@ server.tool("memory_import", "Import memories from JSON array", {
5195
5210
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
5196
5211
  }
5197
5212
  });
5198
- server.tool("memory_inject", "Get formatted memory context for injection into agent system prompts. Selects most relevant memories by scope, importance, and recency.", {
5213
+ server.tool("memory_inject", "Get memory context for system prompt injection. Selects by scope, importance, recency.", {
5199
5214
  agent_id: exports_external.string().optional().describe("Agent ID for scope filtering"),
5200
5215
  project_id: exports_external.string().optional().describe("Project ID for scope filtering"),
5201
5216
  session_id: exports_external.string().optional().describe("Session ID for scope filtering"),
@@ -5274,7 +5289,7 @@ ${lines.join(`
5274
5289
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
5275
5290
  }
5276
5291
  });
5277
- server.tool("register_agent", "Register an agent and get a short UUID. Idempotent: same name returns existing agent.", {
5292
+ server.tool("register_agent", "Register an agent. Idempotent \u2014 same name returns existing agent.", {
5278
5293
  name: exports_external.string().describe("Agent name"),
5279
5294
  description: exports_external.string().optional().describe("Agent description"),
5280
5295
  role: exports_external.string().optional().describe("Agent role")
@@ -5334,7 +5349,7 @@ Last seen: ${agent.last_seen_at}`
5334
5349
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
5335
5350
  }
5336
5351
  });
5337
- server.tool("update_agent", "Update an agent's name, description, role, or metadata. Agents can update themselves.", {
5352
+ server.tool("update_agent", "Update agent name, description, role, or metadata.", {
5338
5353
  id: exports_external.string().describe("Agent ID or name"),
5339
5354
  name: exports_external.string().optional().describe("New agent name"),
5340
5355
  description: exports_external.string().optional().describe("New description"),
@@ -5442,7 +5457,7 @@ server.tool("clean_expired", "Remove expired memories from the database", {}, as
5442
5457
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
5443
5458
  }
5444
5459
  });
5445
- server.tool("memory_context", "Get all memories relevant to the current context. Smart selection by scope visibility, importance, and recency.", {
5460
+ server.tool("memory_context", "Get memories relevant to current context, filtered by scope/importance/recency.", {
5446
5461
  agent_id: exports_external.string().optional(),
5447
5462
  project_id: exports_external.string().optional(),
5448
5463
  scope: exports_external.enum(["global", "shared", "private"]).optional().describe("Limit to specific scope"),
@@ -5467,6 +5482,51 @@ server.tool("memory_context", "Get all memories relevant to the current context.
5467
5482
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
5468
5483
  }
5469
5484
  });
5485
+ var TOOL_REGISTRY = [
5486
+ { name: "memory_save", description: "Save/upsert a memory. scope: global=all agents, shared=project, private=single agent.", category: "memory" },
5487
+ { name: "memory_recall", description: "Recall a memory by key. Returns the best matching active memory.", category: "memory" },
5488
+ { name: "memory_list", description: "List memories. Default: compact lines. full=true for complete JSON objects.", category: "memory" },
5489
+ { name: "memory_update", description: "Update a memory's metadata (value, importance, tags, etc.)", category: "memory" },
5490
+ { name: "memory_forget", description: "Delete a memory by ID or key", category: "memory" },
5491
+ { name: "memory_search", description: "Search memories by keyword across key, value, summary, and tags", category: "memory" },
5492
+ { name: "memory_stats", description: "Get aggregate statistics about stored memories", category: "memory" },
5493
+ { name: "memory_export", description: "Export memories as JSON", category: "memory" },
5494
+ { name: "memory_import", description: "Import memories from JSON array", category: "memory" },
5495
+ { name: "memory_inject", description: "Get memory context for system prompt injection. Selects by scope, importance, recency.", category: "memory" },
5496
+ { name: "memory_context", description: "Get memories relevant to current context, filtered by scope/importance/recency.", category: "memory" },
5497
+ { name: "register_agent", description: "Register an agent. Idempotent \u2014 same name returns existing agent.", category: "agent" },
5498
+ { name: "list_agents", description: "List all registered agents", category: "agent" },
5499
+ { name: "get_agent", description: "Get agent details by ID or name", category: "agent" },
5500
+ { name: "update_agent", description: "Update agent name, description, role, or metadata.", category: "agent" },
5501
+ { name: "register_project", description: "Register a project for memory scoping", category: "project" },
5502
+ { name: "list_projects", description: "List all registered projects", category: "project" },
5503
+ { name: "bulk_forget", description: "Delete multiple memories by IDs", category: "bulk" },
5504
+ { name: "bulk_update", description: "Update multiple memories with the same changes", category: "bulk" },
5505
+ { name: "clean_expired", description: "Remove expired memories from the database", category: "utility" },
5506
+ { name: "search_tools", description: "Search available tools by name or keyword. Returns names only.", category: "meta" },
5507
+ { name: "describe_tools", description: "Get full schemas for specific tools by name.", category: "meta" }
5508
+ ];
5509
+ server.tool("search_tools", "Search available tools by name or keyword. Returns names only.", {
5510
+ query: exports_external.string().describe("Search term to match against tool names and descriptions"),
5511
+ category: exports_external.enum(["memory", "agent", "project", "bulk", "utility", "meta"]).optional()
5512
+ }, async (args) => {
5513
+ const q = args.query.toLowerCase();
5514
+ const results = TOOL_REGISTRY.filter((t) => (!args.category || t.category === args.category) && (t.name.includes(q) || t.description.toLowerCase().includes(q)));
5515
+ if (results.length === 0)
5516
+ return { content: [{ type: "text", text: "No tools found." }] };
5517
+ return { content: [{ type: "text", text: results.map((t) => `${t.name} [${t.category}]`).join(`
5518
+ `) }] };
5519
+ });
5520
+ server.tool("describe_tools", "Get full schemas for specific tools by name.", {
5521
+ names: exports_external.array(exports_external.string()).describe("Tool names to describe")
5522
+ }, async (args) => {
5523
+ const found = TOOL_REGISTRY.filter((t) => args.names.includes(t.name));
5524
+ if (found.length === 0)
5525
+ return { content: [{ type: "text", text: "No matching tools." }] };
5526
+ const lines = found.map((t) => `**${t.name}** [${t.category}]: ${t.description}`);
5527
+ return { content: [{ type: "text", text: lines.join(`
5528
+ `) }] };
5529
+ });
5470
5530
  server.resource("memories", "mementos://memories", { description: "All active memories", mimeType: "application/json" }, async () => {
5471
5531
  const memories = listMemories({ status: "active", limit: 1000 });
5472
5532
  return { contents: [{ uri: "mementos://memories", text: JSON.stringify(memories, null, 2), mimeType: "application/json" }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/mementos",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",