feat(mcp): support metadata in add_memory (#1748)

This commit is contained in:
Rishi Gupta 2026-10-12 16:39:44 -07:00 • committed by Mahesh Sanikommu
parent 26a2fd6f17
commit e2af9e0205
4 changed files with 7 additions and 3 deletions

View file

@ -48,7 +48,7 @@ Your assistant chooses these tools automatically. Use this table when you need t
| --- | --- | --- | --- |
| `search_memory` | Semantic recall from one space | `query` (required), `containerTag` | Matching memories |
| `get_profile` | Stable and recent profile context for one space | `containerTag` | Profile facts |
| `add_memory` | Save information | `content` (required), `namespace` | Save confirmation |
| `add_memory` | Save information | `content` (required), `namespace`, optional `metadata` | Save confirmation |
| `forget_memory` | Forget outdated information | `content` (required), `namespace` | Forget confirmation |
| `list_documents` | Browse stored source documents and their summaries | `page`, `limit`, `containerTag` | Document IDs, titles, types, status, dates, and summaries |
| `get_document` | Read the available content of one document | `documentId` (required) | Document metadata, summary, and available content |

View file

@ -22,10 +22,12 @@ describeWithAuth("MCP - space scoping", () => {
const plainTools = (await plain.client.listTools()).tools
expect(propsOf(plainTools, "add_memory")).toHaveProperty("namespace")
expect(propsOf(plainTools, "add_memory")).toHaveProperty("metadata")
expect(propsOf(plainTools, "search_memory")).toHaveProperty("namespace")
expect(propsOf(plainTools, "get_profile")).toHaveProperty("namespace")
expect(propsOf(scopedTools, "add_memory")).toHaveProperty("namespace")
expect(propsOf(scopedTools, "add_memory")).toHaveProperty("metadata")
expect(propsOf(scopedTools, "search_memory")).toHaveProperty("namespace")
expect(propsOf(scopedTools, "get_profile")).toHaveProperty("namespace")
} finally {

View file

@ -196,11 +196,12 @@ export class SupermemoryClient {
async createMemory(
content: string,
metadata?: Record<string, unknown>,
): Promise<{ id: string; status: string; namespace: string }> {
try {
const result = await this.client.add(this.namespace, {
content,
metadata: { sm_source: MCP_SOURCE },
metadata: { ...metadata, sm_source: MCP_SOURCE },
})
return {
id: result.id,

View file

@ -25,6 +25,7 @@ export function register(deps: ToolDeps) {
),
namespace: optionalNamespaceSchema,
...legacyNamespaceInput,
metadata: z.record(z.string(), z.unknown()).optional().describe("Optional metadata to attach to the saved memory"),
})
deps.server.registerTool(
@ -42,7 +43,7 @@ export function register(deps: ToolDeps) {
const namespace = await deps.resolveNamespace(namespaceArg(args))
const client = deps.getClient(namespace)
const result = await client.createMemory(args.content)
const result = await client.createMemory(args.content, args.metadata)
const message = `Memory saved (ID: ${result.id}, space: ${result.namespace})`
const structuredContent: AddMemoryOutput = withLegacyNamespace({
action: "save",