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

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "key": { "description": "Unique key for this memory", "type": "string" }, "project": { "description": "Optional project scope for organizing memories", "type": "string" }, "value": { "description": "Value to store", "type": "string" } }, "required": [ "key", "value" ], "type": "object" }

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)); } }

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