Files
supermemory/apps/mcp/src/server/tools/guided-save.ts
T
Prasanna721 7e7e820489 fix mcp app contracts (#1394)
Fixes MCP app submission metadata and makes widget delivery consistent across hosts.

- content-hash widget resources and set the production widget domain
- add typed structured outputs to direct tools and scope default-space calls
- keep graph rendering compatible with both initial results and app-side loading

Tested with `bun run check-types` and `bun run test:unit` (42 tests).
2026-08-01 06:41:17 +00:00

57 lines
1.8 KiB
TypeScript

import { z } from "zod"
import { saveViewSchema, type ViewMessage } from "../../shared/types"
import { appResultMeta, appToolMeta } from "../app-metadata"
import { effectiveContainerTagAccess } from "../auth/rbac"
import { READ_ONLY_TOOL_ANNOTATIONS } from "./annotations"
import { textContent, type ToolDeps } from "./types"
export function register(deps: ToolDeps) {
deps.server.registerTool(
"guided-save",
{
title: "Add Memory",
description:
"Open an interactive form when the user wants to draft, review, edit, or choose the target space before saving information to Supermemory. Use this when the user wants to add a memory but has not supplied final content, or explicitly wants to review supplied content before saving. If the user provides the exact content and asks to save it immediately, use add_memory instead.",
inputSchema: z.object({
prefill: z.string().optional().describe("Optional content to prefill"),
}),
outputSchema: saveViewSchema,
_meta: appToolMeta(),
annotations: READ_ONLY_TOOL_ANNOTATIONS,
},
async (args) => {
try {
const { prefill } = args
const viewId = crypto.randomUUID()
const [activeTag, tags, session] = await Promise.all([
deps.getActiveContainerTag(),
deps.getClient().listContainerTags(),
deps.getSession(),
])
const writableTags = effectiveContainerTagAccess(
tags.map((tag) => tag.containerTag),
session,
)
.filter((access) => access.permission === "write")
.map((access) => access.containerTag)
const sc: ViewMessage = {
view: "save",
viewId,
activeTag,
writableTags,
prefill,
}
return {
content: [textContent("Opening memory save form...")],
structuredContent: sc,
_meta: appResultMeta(viewId),
}
} catch (error) {
return deps.errorResult(error)
}
},
)
}