lithtrix_memory_set
Store or update a JSON value for a memory key with optional TTL, importance, source, and confidence score. Persists AI agent memory across sessions and changes.
Instructions
Store or update a JSON value for a memory key (PUT /v1/memory/{key}). Requires LITHTRIX_API_KEY. Optional ttl (seconds), importance, source, confidence.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Memory key (1–128 chars: letters, digits, hyphen, underscore, dot, colon) | |
| value | No | JSON-serializable value (object, array, string, number, boolean, etc.) | |
| ttl | No | Optional positive TTL in seconds | |
| importance | No | Optional importance tier (default normal on API if omitted) | |
| source | No | Optional provenance label (e.g. tool name) | |
| confidence | No | Optional confidence 0–1 (default 1.0 on API) |
Implementation Reference
- tools/memory.js:114-140 (handler)The async handler function for lithtrix_memory_set. Validates API key, builds the payload (value, ttl, importance, source, confidence), sends PUT /v1/memory/{key} to the Lithtrix API, and returns the JSON response.
async ({ key, value, ttl, importance, source, confidence }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) return missingApiKeyResponse(); const payload = { value }; if (ttl !== undefined) payload.ttl = ttl; if (importance !== undefined) payload.importance = importance; if (source !== undefined) payload.source = source; if (confidence !== undefined) payload.confidence = confidence; const path = `/v1/memory/${encodeURIComponent(key)}`; let response; try { response = await fetch(new URL(path, LITHTRIX_API_URL), { method: "PUT", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); } catch (err) { return networkErrorResponse(err); } return apiJsonResponse(response); } ); - tools/memory.js:88-113 (schema)Zod schema definition for lithtrix_memory_set inputs: key (validated string), value (any JSON-serializable), optional ttl (positive int), importance (enum), source (string max 255), confidence (float 0-1).
{ key: memoryKeySchema, value: z .any() .describe( "JSON-serializable value (object, array, string, number, boolean, etc.)" ), ttl: z .number() .int() .positive() .optional() .describe("Optional positive TTL in seconds"), importance: importanceSchema, source: z .string() .max(255) .optional() .describe("Optional provenance label (e.g. tool name)"), confidence: z .number() .min(0) .max(1) .optional() .describe("Optional confidence 0–1 (default 1.0 on API)"), }, - tools/memory.js:83-140 (registration)Registration of lithtrix_memory_set via server.tool() inside the registerMemoryTools function, with tool name, description, schema, and handler.
export function registerMemoryTools(server) { server.tool( "lithtrix_memory_set", "Store or update a JSON value for a memory key (PUT /v1/memory/{key}). " + "Requires LITHTRIX_API_KEY. Optional ttl (seconds), importance, source, confidence.", { key: memoryKeySchema, value: z .any() .describe( "JSON-serializable value (object, array, string, number, boolean, etc.)" ), ttl: z .number() .int() .positive() .optional() .describe("Optional positive TTL in seconds"), importance: importanceSchema, source: z .string() .max(255) .optional() .describe("Optional provenance label (e.g. tool name)"), confidence: z .number() .min(0) .max(1) .optional() .describe("Optional confidence 0–1 (default 1.0 on API)"), }, async ({ key, value, ttl, importance, source, confidence }) => { const apiKey = process.env.LITHTRIX_API_KEY; if (!apiKey) return missingApiKeyResponse(); const payload = { value }; if (ttl !== undefined) payload.ttl = ttl; if (importance !== undefined) payload.importance = importance; if (source !== undefined) payload.source = source; if (confidence !== undefined) payload.confidence = confidence; const path = `/v1/memory/${encodeURIComponent(key)}`; let response; try { response = await fetch(new URL(path, LITHTRIX_API_URL), { method: "PUT", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); } catch (err) { return networkErrorResponse(err); } return apiJsonResponse(response); } ); - tools/memory.js:24-81 (helper)Helper functions used by the handler: missingApiKeyResponse, networkErrorResponse, and apiJsonResponse for constructing MCP content responses.
function missingApiKeyResponse() { return { content: [ { type: "text", text: JSON.stringify({ error: "LITHTRIX_API_KEY environment variable is not set. " + "Register at https://lithtrix.ai and use lithtrix_register, then set the key.", }), }, ], isError: true, }; } function networkErrorResponse(err) { return { content: [ { type: "text", text: JSON.stringify({ error: `Network error contacting Lithtrix API: ${err.message}`, }), }, ], isError: true, }; } async function apiJsonResponse(response) { let body; try { body = await response.json(); } catch { body = { message: `Invalid JSON (HTTP ${response.status})` }; } if (!response.ok) { return { content: [ { type: "text", text: JSON.stringify({ error: body.message ?? `Lithtrix API error (HTTP ${response.status})`, error_code: body.error_code ?? "UNKNOWN", status: body.status, }), }, ], isError: true, }; } return { content: [{ type: "text", text: JSON.stringify(body, null, 2) }], }; } - index.js:33-52 (registration)Import and invocation that registers all memory tools (including lithtrix_memory_set) on the MCP server instance.
import { registerMemoryTools } from "./tools/memory.js"; import { registerBlobTools } from "./tools/blobs.js"; import { registerParseTools } from "./tools/parse.js"; import { registerFeedbackTool } from "./tools/feedback.js"; import { registerBrowseTool } from "./tools/browse.js"; import { registerCommonsTool } from "./tools/commons.js"; const server = new McpServer({ name: "lithtrix", version: "0.9.0", }); registerSearchTool(server); registerRegisterTool(server); registerMemoryTools(server); registerBlobTools(server); registerParseTools(server); registerFeedbackTool(server); registerBrowseTool(server); registerCommonsTool(server);