Skip to main content
Glama

memory_save

Store facts, decisions, preferences, or lessons in long-term memory with automatic embedding for semantic retrieval.

Instructions

Save a fact, decision, preference, or lesson to long-term memory. Automatically generates an embedding for future semantic search.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe memory content — be specific and self-contained
categoryNoMemory category (default: general)
projectNoAssociated project name

Implementation Reference

  • The handler function that executes the memory_save tool logic. It generates an ID, embeds the content via Ollama, inserts a row into the SQLite memories table, and returns a confirmation string.
    export async function handleMemorySave(
      content: string,
      category: MemoryCategory = "general",
      project?: string,
    ): Promise<string> {
      const db = getDb();
      const now = Date.now();
      const id = generateId("mem");
    
      const embedding = await embed(content);
      const embeddingBuf = embedding ? embeddingToBuffer(embedding) : null;
    
      db.prepare(
        `INSERT INTO memories (id, content, category, project, created_at, updated_at, accessed_at, embedding)
         VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
      ).run(id, content, category, project ?? null, now, now, now, embeddingBuf);
    
      const projectStr = project ? ` [${project}]` : "";
      return `Saved memory ${id}${projectStr} (${category}):\n${content.slice(0, 100)}${content.length > 100 ? "..." : ""}`;
    }
  • Type definition for MemoryCategory, used as input schema for the handler function.
    export type MemoryCategory =
      | "decision"
      | "preference"
      | "fact"
      | "episode"
      | "lesson"
      | "architecture"
      | "framework"
      | "general";
  • Registration of the memory_save tool with the MCP server, including Zod schema for content, category, and project inputs.
    server.tool(
      "memory_save",
      "Save a fact, decision, preference, or lesson to long-term memory. Automatically generates an embedding for future semantic search.",
      {
        content: z.string().describe("The memory content — be specific and self-contained"),
        category: z
          .enum(["decision", "preference", "fact", "episode", "lesson", "architecture", "framework", "general"])
          .optional()
          .describe("Memory category (default: general)"),
        project: z.string().optional().describe("Associated project name"),
      },
      async ({ content, category, project }) => {
        try {
          const result = await handleMemorySave(content, category, project);
          return { content: [{ type: "text", text: result }] };
        } catch (err) {
          return {
            content: [{ type: "text", text: `Error saving memory: ${err}` }],
            isError: true,
          };
        }
      },
    );
  • Helper function that generates unique IDs with a prefix (used as 'mem-...' for memory entries).
    export function generateId(prefix: string): string {
      const ts = Date.now();
      const rand = Math.random().toString(36).slice(2, 6);
      return `${prefix}-${ts}-${rand}`;
    }
  • Helper that generates an embedding vector for memory content using Ollama's nomic-embed-text model.
    export async function embed(text: string): Promise<Float32Array | null> {
      const available = await ensureOllama();
      if (!available) return null;
    
      const client = getClient();
      const response = await client.embed({ model: MODEL, input: text });
      return new Float32Array(response.embeddings[0]);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description discloses the automatic embedding generation for semantic search, adding behavioral context. It does not cover all potential traits (e.g., overwrite behavior, permissions), but adequately describes the key function.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no fluff. The first sentence is the action, the second adds a valuable behavioral detail. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple 3-param tool with no output schema, the description is fairly complete. It could mention return values or duplication behavior, but overall it provides sufficient context given the low complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds no additional meaning beyond the schema; it only restates the purpose. No extra param details are provided.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool saves facts, decisions, preferences, or lessons to long-term memory, providing a specific verb and resource. It implicitly distinguishes from siblings like memory_search (searching) and memory_recent (listing recent memories).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for persisting important information, but lacks explicit guidance on when not to use or mention alternatives like memory_journal. It provides clear context but no exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DomDemetz/claude-soul'

If you have feedback or need assistance with the MCP directory API, please join our Discord server