supermemory/apps/mcp/src/server/tools/get-document.ts
Mahesh Sanikommu 1992356c5d feat(mcp): move the MCP server to the v5 API and supermemory 5.0
Every tool now goes through the v5 SDK with the namespace as the first argument: add, search (threshold kept at 0.6 to match v4 results), profile, list documents and memories, documents.get, namespaces.list, and file upload on /ns/{namespace}/document/file. containerTag is namespace everywhere in tool inputs, outputs, widget, README and tests, with no aliases; the stored activeContainerTag config key stays so saved spaces survive. Forget previews with a dry run and forgets the top match by id. Graph data and /v3/session stay on v3 because v5 has no replacement. The deprecated snake_case tool aliases from #1782 are kept. pnpm-lock.yaml removed; bun.lock picks up supermemory 5.0.1. Verified: check-types, 21 unit tests, and a live run of every client call against the production API in a throwaway namespace.
2026-10-07 18:37:39 -07:00

61 lines
1.9 KiB
TypeScript

import { z } from "zod"
import { formatDocument, getDocumentContent } from "../format"
import { optionalNamespaceSchema } from "../namespace"
import { READ_ONLY_TOOL_ANNOTATIONS } from "./annotations"
import {
getDocumentOutputSchema,
type GetDocumentOutput,
} from "./output-schemas"
import { textContent, type ToolDeps } from "./types"
export function register(deps: ToolDeps) {
const inputSchema = z.object({
documentId: z
.string()
.min(1, "Document ID is required")
.max(255, "Document ID exceeds maximum length")
.describe("Document ID returned by list_documents or a memory result"),
namespace: optionalNamespaceSchema,
})
deps.server.registerTool(
"get_document",
{
title: "Get Document",
description:
"Read one stored document by ID from one space, including its summary and available content. Use list_documents to discover document IDs. When the document is in a named space, resolve it with list_spaces and pass namespace; otherwise use the active space.",
inputSchema,
outputSchema: getDocumentOutputSchema,
annotations: READ_ONLY_TOOL_ANNOTATIONS,
},
async (args) => {
try {
const namespace = await deps.resolveNamespace(args.namespace)
const client = deps.getClient(namespace)
const document = await client.getDocument(args.documentId)
const { content, truncated } = getDocumentContent(document)
const structuredContent: GetDocumentOutput = {
namespace,
document: {
id: document.id,
title: document.title,
type: document.type,
status: document.system.status,
createdAt: document.system.createdAt,
updatedAt: document.system.updatedAt,
summary: document.summary,
content,
contentTruncated: truncated,
},
}
return {
content: [textContent(formatDocument(document))],
structuredContent,
}
} catch (error) {
return deps.errorResult(error)
}
},
)
}