Skip to main content
Glama

save_memory

Store key-value pairs in persistent memory to save user preferences, project decisions, and session context for future use.

Instructions

Save a key-value pair to persistent memory. Use this to remember user preferences, project decisions, or important context across sessions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesUnique key for this memory
valueYesValue to store
projectNoOptional project scope for organizing memories

Implementation Reference

  • The main handler function for the 'save_memory' tool. It ensures the memory file exists, reads the current data, updates it with the new key-value pair (including optional project and timestamp), writes back to the JSON file at ~/.code-mcp-memory.json, and returns a confirmation message.
    export async function saveMemoryHandler(args: any) {
        await ensureMemoryFile();
        const data = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8"));
        data[args.key] = { value: args.value, project: args.project, timestamp: new Date().toISOString() };
        await fs.writeFile(MEMORY_FILE, JSON.stringify(data, null, 2));
        return { content: [{ type: "text", text: `Saved memory: ${args.key}` }] };
  • Zod-based input schema definition for the 'save_memory' tool, specifying required 'key' and 'value' strings, and optional 'project' string.
    export const saveMemorySchema = {
        name: "save_memory",
        description: "Save a key-value pair to persistent memory. Use this to remember user preferences, project decisions, or important context across sessions.",
        inputSchema: z.object({
            key: z.string().describe("Unique key for this memory"),
            value: z.string().describe("Value to store"),
            project: z.string().optional().describe("Optional project scope for organizing memories")
        })
    };
  • src/index.ts:89-89 (registration)
    Registration of the 'save_memory' tool in the toolRegistry Map used by the stdio MCP server (index.ts).
    ["save_memory", { schema: saveMemorySchema, handler: saveMemoryHandler }],
  • src/server.ts:98-98 (registration)
    Registration of the 'save_memory' tool in the toolRegistry Map used by the HTTP MCP server (server.ts).
    ["save_memory", { schema: saveMemorySchema, handler: saveMemoryHandler }],
  • Helper function to ensure the persistent memory JSON file exists, creating an empty object if not.
    async function ensureMemoryFile() {
        try {
            await fs.access(MEMORY_FILE);
        } catch {
            await fs.writeFile(MEMORY_FILE, JSON.stringify({}, null, 2));
        }
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It discloses the tool's purpose (saving to persistent memory) and scope (across sessions), which is basic behavioral context. However, it doesn't mention potential limitations like storage limits, overwrite behavior if key exists, or authentication needs. The description doesn't contradict any annotations (none exist).

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?

The description is two sentences, front-loaded with the core purpose and followed by usage examples. Every sentence adds value: the first defines the action, the second provides concrete applications. There is no wasted text or redundancy.

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

Completeness3/5

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

Given no annotations, no output schema, and 3 parameters with full schema coverage, the description is minimally adequate. It covers the tool's purpose and basic usage but lacks details on behavioral traits (e.g., persistence guarantees, error handling) and doesn't explain return values. For a write operation with no structured safety hints, more context would be helpful.

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 description coverage is 100%, with all parameters ('key', 'value', 'project') well-documented in the schema. The description adds no additional parameter semantics beyond what's in the schema (e.g., no format examples or constraints). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't need to.

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

Purpose4/5

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

The description clearly states the verb ('save') and resource ('key-value pair to persistent memory'), with specific examples of what to store (user preferences, project decisions, important context). It distinguishes from siblings like 'clear_memory', 'list_memories', and 'read_memory' by focusing on creation/persistence. However, it doesn't explicitly contrast with all siblings (e.g., 'track_project' might overlap).

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 provides implied usage through examples ('use this to remember...'), giving context for when to apply the tool. It doesn't explicitly state when NOT to use it or name alternatives (e.g., 'track_project' for project-specific data). No misleading guidance is present, but explicit sibling differentiation is lacking.

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/millsydotdev/Code-MCP'

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