mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-30 01:51:28 +00:00
feat(mcp): add get_profile and use snake_case for public tools (#1665)
This commit is contained in:
parent
a92c21b2dc
commit
c927c98f2c
27 changed files with 163 additions and 96 deletions
|
|
@ -46,25 +46,27 @@ Your assistant chooses these tools automatically. Use this table when you need t
|
|||
|
||||
| Tool | Use it for | Inputs | Result |
|
||||
| --- | --- | --- | --- |
|
||||
| `search_memory` | Semantic recall from one space, with optional profile context | `query` (required), `includeProfile`, `containerTag` | Profile context and matching memories |
|
||||
| `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 or forget outdated information | `content` (required), `action` (`save` or `forget`), `containerTag` | Save or forget confirmation |
|
||||
| `listDocuments` | Browse stored source documents and their summaries | `page`, `limit`, `containerTag` | Document IDs, titles, types, status, dates, and summaries |
|
||||
| `getDocument` | Read the available content of one document | `documentId` (required) | Document metadata, summary, and available content |
|
||||
| `listMemories` | Browse recent extracted memory entries and their source document IDs | `page`, `limit`, `containerTag` | Memory IDs, text, versions, and source document IDs |
|
||||
| `listSpaces` | List accessible spaces and resolve a space name to its key | None | Formatted list plus structured `spaces` and `count` fields |
|
||||
| `whoAmI` | Inspect the authenticated account, permissions, scope, and active space | None | Account and access context |
|
||||
| `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 |
|
||||
| `list_memories` | Browse recent extracted memory entries and their source document IDs | `page`, `limit`, `containerTag` | Memory IDs, text, versions, and source document IDs |
|
||||
| `list_spaces` | List accessible spaces and resolve a space name to its key | None | Formatted list plus structured `spaces` and `count` fields |
|
||||
| `who_am_i` | Inspect the authenticated account, permissions, scope, and active space | None | Account and access context |
|
||||
|
||||
### Search
|
||||
|
||||
`search_memory` accepts a natural-language query and returns semantically relevant memories. By default, it also includes stable and recent profile context from the same space. Set `includeProfile` to `false` when only matching memories are needed.
|
||||
`search_memory` accepts a natural-language query and returns semantically relevant memories. It does not include the space profile. Use `get_profile` when the assistant needs stable facts or recent context that search did not return.
|
||||
|
||||
Use the retrieval tools for different questions:
|
||||
|
||||
- Use `search_memory` to answer a question from remembered context.
|
||||
- Use `listDocuments` to discover stored sources, then `getDocument` to read one source in full.
|
||||
- Use `listMemories` to inspect the extracted memory entries themselves, including their IDs and source document IDs.
|
||||
- Use `get_profile` for who-the-user-is, preferences, and recent context.
|
||||
- Use `list_documents` to discover stored sources, then `get_document` to read one source in full.
|
||||
- Use `list_memories` to inspect the extracted memory entries themselves, including their IDs and source document IDs.
|
||||
|
||||
`listDocuments` and `listMemories` default to 10 results per page and accept up to 50.
|
||||
`list_documents` and `list_memories` default to 10 results per page and accept up to 50.
|
||||
|
||||
### Save or forget
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ If the content is already final, the assistant should use `add_memory`. If you w
|
|||
|
||||
### Access control
|
||||
|
||||
`whoAmI` returns the current identity, role, access type, granted scope, and active space. `listSpaces` returns only spaces the authenticated account can access, with names, keys, document and memory counts, and recent activity.
|
||||
`who_am_i` returns the current identity, role, access type, granted scope, and active space. `list_spaces` returns only spaces the authenticated account can access, with names, keys, document and memory counts, and recent activity.
|
||||
|
||||
## Interactive widgets
|
||||
|
||||
|
|
@ -138,7 +140,7 @@ Supported types include text, Markdown, PDF, Word, CSV, common images, MP3, WAV,
|
|||
|
||||
`memory-graph` renders the selected space as an interactive graph of source documents and extracted memories.
|
||||
|
||||
When no space is named, the server automatically uses the active space or account default. If you name a specific space, the assistant calls `listSpaces` to resolve its name to a space key, then opens that space's graph.
|
||||
When no space is named, the server automatically uses the active space or account default. If you name a specific space, the assistant calls `list_spaces` to resolve its name to a space key, then opens that space's graph.
|
||||
|
||||
<img
|
||||
className="hidden dark:block"
|
||||
|
|
|
|||
|
|
@ -48,12 +48,13 @@ The client discovers the OAuth authorization server through
|
|||
|
||||
| Tool | Purpose |
|
||||
| --- | --- |
|
||||
| `search_memory` | Search memories and optionally include profile context |
|
||||
| `listDocuments` | List document metadata and summaries in a space |
|
||||
| `getDocument` | Read one document's available content by ID |
|
||||
| `listMemories` | List extracted memory entries and their source document IDs |
|
||||
| `listSpaces` | List spaces visible to the authenticated account |
|
||||
| `whoAmI` | Return identity, access, and active-space context |
|
||||
| `search_memory` | Search memories in a space |
|
||||
| `get_profile` | Get stable and recent profile context for a space |
|
||||
| `list_documents` | List document metadata and summaries in a space |
|
||||
| `get_document` | Read one document's available content by ID |
|
||||
| `list_memories` | List extracted memory entries and their source document IDs |
|
||||
| `list_spaces` | List spaces visible to the authenticated account |
|
||||
| `who_am_i` | Return identity, access, and active-space context |
|
||||
| `add_memory` | Save or forget a memory |
|
||||
|
||||
### MCP App launchers
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ import {
|
|||
const EXPECTED_TOOLS = [
|
||||
"add_memory",
|
||||
"fetch-graph-data",
|
||||
"getDocument",
|
||||
"get_document",
|
||||
"get_profile",
|
||||
"guided-save",
|
||||
"listDocuments",
|
||||
"listMemories",
|
||||
"listSpaces",
|
||||
"list_documents",
|
||||
"list_memories",
|
||||
"list_spaces",
|
||||
"memory-graph",
|
||||
"prepare-file-upload",
|
||||
"save-memory",
|
||||
|
|
@ -22,17 +23,18 @@ const EXPECTED_TOOLS = [
|
|||
"select-space",
|
||||
"set-active-tag",
|
||||
"upload-file",
|
||||
"whoAmI",
|
||||
"who_am_i",
|
||||
]
|
||||
const describeWithAuth = describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)
|
||||
|
||||
const READ_ONLY_TOOL_NAMES = [
|
||||
"search_memory",
|
||||
"listDocuments",
|
||||
"listMemories",
|
||||
"getDocument",
|
||||
"listSpaces",
|
||||
"whoAmI",
|
||||
"get_profile",
|
||||
"list_documents",
|
||||
"list_memories",
|
||||
"get_document",
|
||||
"list_spaces",
|
||||
"who_am_i",
|
||||
"memory-graph",
|
||||
]
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ describeWithAuth("MCP — discovery & identity", () => {
|
|||
}
|
||||
})
|
||||
|
||||
it("marks add_memory as mutating", async () => {
|
||||
it("marks addMemory as mutating", async () => {
|
||||
const { tools } = await s.client.listTools()
|
||||
const memory = tools.find((t) => t.name === "add_memory")
|
||||
expect(memory?.annotations).toMatchObject(MEMORY_TOOL_ANNOTATIONS)
|
||||
|
|
@ -93,7 +95,7 @@ describeWithAuth("MCP — discovery & identity", () => {
|
|||
})
|
||||
|
||||
it("whoAmI resolves to the authenticated account", async () => {
|
||||
const res = await callTool(s.client, "whoAmI")
|
||||
const res = await callTool(s.client, "who_am_i")
|
||||
expect(res.isError).toBeFalsy()
|
||||
const parsed = JSON.parse(textOf(res))
|
||||
expect(parsed.userId).toBeTruthy()
|
||||
|
|
@ -101,7 +103,7 @@ describeWithAuth("MCP — discovery & identity", () => {
|
|||
})
|
||||
|
||||
it("listSpaces returns content", async () => {
|
||||
const res = await callTool(s.client, "listSpaces")
|
||||
const res = await callTool(s.client, "list_spaces")
|
||||
expect(res.isError).toBeFalsy()
|
||||
expect(textOf(res).length).toBeGreaterThan(0)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ describeWithAuth("MCP — graph, resources & prompts", () => {
|
|||
expect(res.contents[0].text).toMatch(/# Active Space Profile/)
|
||||
expect(res.contents[0].text).toMatch(/Space:/)
|
||||
expect(res.contents[0].text).toMatch(
|
||||
/Use `listSpaces` to find the relevant space key/,
|
||||
/Use `list_spaces` to find the relevant space key/,
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -225,7 +225,6 @@ export async function recallUntil(
|
|||
for (let i = 0; i < tries; i++) {
|
||||
const res = await callTool(client, "search_memory", {
|
||||
query,
|
||||
includeProfile: false,
|
||||
...(containerTag ? { containerTag } : {}),
|
||||
})
|
||||
const txt = textOf(res)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
|
||||
const listedDocument = await waitForToolText(
|
||||
session,
|
||||
"listDocuments",
|
||||
"list_documents",
|
||||
{ page: 1, limit: 50, containerTag },
|
||||
`[${savedView.id}]`,
|
||||
20,
|
||||
|
|
@ -107,7 +107,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
|
||||
const document = await waitForToolText(
|
||||
session,
|
||||
"getDocument",
|
||||
"get_document",
|
||||
{ documentId: savedView.id },
|
||||
`Document ID: ${savedView.id}`,
|
||||
20,
|
||||
|
|
@ -115,7 +115,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
)
|
||||
expect(document, "saved document could not be read").not.toBeNull()
|
||||
|
||||
const memoriesResult = await callTool(session.client, "listMemories", {
|
||||
const memoriesResult = await callTool(session.client, "list_memories", {
|
||||
page: 1,
|
||||
limit: 10,
|
||||
containerTag: "sm_project_default",
|
||||
|
|
@ -132,7 +132,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
throw new Error("Listed memory did not include a source document")
|
||||
}
|
||||
|
||||
const sourceDocument = await callTool(session.client, "getDocument", {
|
||||
const sourceDocument = await callTool(session.client, "get_document", {
|
||||
documentId: sourceDocumentId,
|
||||
})
|
||||
expect(sourceDocument.isError).toBeFalsy()
|
||||
|
|
@ -182,7 +182,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
|
||||
const document = await waitForToolText(
|
||||
session,
|
||||
"getDocument",
|
||||
"get_document",
|
||||
{ documentId: uploaded.id },
|
||||
`Document ID: ${uploaded.id}`,
|
||||
20,
|
||||
|
|
|
|||
|
|
@ -43,21 +43,29 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)("MCP — memory behaviors", () =>
|
|||
expect(found, `recall never returned marker ${marker}`).not.toBeNull()
|
||||
}, 120_000)
|
||||
|
||||
it("recall includeProfile=true returns profile + memories sections", async () => {
|
||||
it("searchMemory does not include profile sections", async () => {
|
||||
const res = await callTool(s.client, "search_memory", {
|
||||
query: "dragonfruit",
|
||||
includeProfile: true,
|
||||
})
|
||||
expect(res.isError).toBeFalsy()
|
||||
const txt = textOf(res)
|
||||
expect(txt).toMatch(/## (Profile|Recent context|Matching memories)/)
|
||||
expect(txt).not.toMatch(/## (Profile|Stable Context|Recent [Cc]ontext)/)
|
||||
expect(txt).toMatch(/## Matching memories|No matching memories found/i)
|
||||
}, 30_000)
|
||||
|
||||
it("getProfile returns profile sections", async () => {
|
||||
const res = await callTool(s.client, "get_profile", {})
|
||||
expect(res.isError).toBeFalsy()
|
||||
const txt = textOf(res)
|
||||
expect(txt).toMatch(
|
||||
/## (Stable Context|Recent Context)|No profile facts are available/i,
|
||||
)
|
||||
}, 30_000)
|
||||
|
||||
// Hybrid search returns nearest matches even for unrelated queries — assert it responds gracefully, not empty.
|
||||
it("recall responds gracefully for an unmatched query", async () => {
|
||||
const res = await callTool(s.client, "search_memory", {
|
||||
query: `zzz-no-such-memory-${randomUUID()}`,
|
||||
includeProfile: false,
|
||||
})
|
||||
expect(res.isError).toBeFalsy()
|
||||
expect(textOf(res)).toMatch(
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ describe.skipIf(!OAUTH_REFRESH_TOKEN || !OAUTH_CLIENT_ID)(
|
|||
|
||||
it("connects to /mcp with the OAuth token and resolves identity", async () => {
|
||||
s = await connect({ token: accessToken })
|
||||
const res = await callTool(s.client, "whoAmI")
|
||||
const res = await callTool(s.client, "who_am_i")
|
||||
expect(res.isError).toBeFalsy()
|
||||
expect(JSON.parse(textOf(res)).userId).toBeTruthy()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@ describeWithAuth("MCP - space scoping", () => {
|
|||
expect(propsOf(plainTools, "search_memory")).toHaveProperty(
|
||||
"containerTag",
|
||||
)
|
||||
expect(propsOf(plainTools, "get_profile")).toHaveProperty("containerTag")
|
||||
|
||||
expect(propsOf(scopedTools, "add_memory")).toHaveProperty("containerTag")
|
||||
expect(propsOf(scopedTools, "search_memory")).toHaveProperty(
|
||||
"containerTag",
|
||||
)
|
||||
expect(propsOf(scopedTools, "get_profile")).toHaveProperty("containerTag")
|
||||
} finally {
|
||||
await scoped.close()
|
||||
await plain.close()
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ describe.skipIf(!OAUTH_CREDENTIALS_AVAILABLE)(
|
|||
|
||||
const separateSession = await connect()
|
||||
try {
|
||||
const identity = await callTool(separateSession.client, "whoAmI")
|
||||
const identity = await callTool(separateSession.client, "who_am_i")
|
||||
expect(identity.isError).toBeFalsy()
|
||||
expect(JSON.parse(textOf(identity))).toMatchObject({
|
||||
activeSpace: firstTag,
|
||||
|
|
|
|||
|
|
@ -34,11 +34,12 @@ type ClientInfoResolver = (
|
|||
|
||||
const TOOL_SURFACES: Record<string, McpToolSurface> = {
|
||||
search_memory: "model_tool",
|
||||
listDocuments: "model_tool",
|
||||
getDocument: "model_tool",
|
||||
listMemories: "model_tool",
|
||||
listSpaces: "model_tool",
|
||||
whoAmI: "model_tool",
|
||||
get_profile: "model_tool",
|
||||
list_documents: "model_tool",
|
||||
get_document: "model_tool",
|
||||
list_memories: "model_tool",
|
||||
list_spaces: "model_tool",
|
||||
who_am_i: "model_tool",
|
||||
add_memory: "model_tool",
|
||||
"select-space": "app_launcher",
|
||||
"memory-graph": "app_launcher",
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ export const containerTagSchema = z
|
|||
.string()
|
||||
.min(1, "Container tag is required")
|
||||
.max(128, "Container tag exceeds maximum length")
|
||||
.describe("Space key returned by listSpaces")
|
||||
.describe("Space key returned by list_spaces")
|
||||
|
||||
export const optionalContainerTagSchema = containerTagSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Space key to use for this call. If the user names a space, call listSpaces to resolve its key and pass it here. If no space is named, omit this field so the server uses the active space or account default.",
|
||||
"Space key to use for this call. If the user names a space, call list_spaces to resolve its key and pass it here. If no space is named, omit this field so the server uses the active space or account default.",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -60,12 +60,12 @@ export function formatDocumentsList(response: DocumentsListResponse): string {
|
|||
"",
|
||||
blocks.join("\n\n"),
|
||||
"",
|
||||
"Use getDocument with a document ID to read its content.",
|
||||
"Use get_document with a document ID to read its content.",
|
||||
]
|
||||
|
||||
if (pagination.currentPage < pagination.totalPages) {
|
||||
parts.push(
|
||||
`More available - call listDocuments with page: ${pagination.currentPage + 1}.`,
|
||||
`More available - call list_documents with page: ${pagination.currentPage + 1}.`,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ export function formatMemoryEntriesList(
|
|||
if (pagination.currentPage < pagination.totalPages) {
|
||||
parts.push(
|
||||
"",
|
||||
`More available - call listMemories with page: ${pagination.currentPage + 1}.`,
|
||||
`More available - call list_memories with page: ${pagination.currentPage + 1}.`,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export function registerProfileResource(
|
|||
|
||||
parts.push(
|
||||
"",
|
||||
"Other spaces are available. Use `listSpaces` to find the relevant space key, then use that key with space-aware tools when the user asks about another space. Keep space contexts separate unless the user asks to combine them.",
|
||||
"Other spaces are available. Use `list_spaces` to find the relevant space key, then use that key with space-aware tools when the user asks about another space. Keep space contexts separate unless the user asks to combine them.",
|
||||
)
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import { uploadStateName } from "./space-state"
|
|||
const DEFAULT_API_URL = "https://api.supermemory.ai"
|
||||
const UPLOAD_SESSION_TTL_MS = 2 * 60 * 1000
|
||||
const SERVER_INSTRUCTIONS =
|
||||
"Supermemory is the authenticated user's persistent memory and knowledge layer across conversations and spaces. Use these tools whenever the user wants to recall something they may have saved, inspect stored sources or extracted memories, remember or upload new information, check their Supermemory account or access, change their active space, or explore their memory graph, even if they do not mention Supermemory by name. Use the active or account-default space when none is named. Resolve a named space with listSpaces and pass its key to the relevant tool; change the active space only when the user explicitly asks."
|
||||
"Supermemory is the authenticated user's persistent memory and knowledge layer across conversations and spaces. Use these tools whenever the user wants to recall something they may have saved, inspect stored sources or extracted memories, remember or upload new information, check their Supermemory account or access, change their active space, or explore their memory graph, even if they do not mention Supermemory by name. Use the active or account-default space when none is named. Resolve a named space with list_spaces and pass its key to the relevant tool; change the active space only when the user explicitly asks."
|
||||
|
||||
type ClientInfo = { name: string; version?: string }
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ describe("space application state", () => {
|
|||
expect(optionalContainerTagSchema.description).toContain(
|
||||
"If the user names a space",
|
||||
)
|
||||
expect(optionalContainerTagSchema.description).toContain("listSpaces")
|
||||
expect(optionalContainerTagSchema.description).toContain("list_spaces")
|
||||
expect(optionalContainerTagSchema.description).toContain("active space")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,15 +13,15 @@ export function register(deps: ToolDeps) {
|
|||
.string()
|
||||
.min(1, "Document ID is required")
|
||||
.max(255, "Document ID exceeds maximum length")
|
||||
.describe("Document ID returned by listDocuments or a memory result"),
|
||||
.describe("Document ID returned by list_documents or a memory result"),
|
||||
})
|
||||
|
||||
deps.server.registerTool(
|
||||
"getDocument",
|
||||
"get_document",
|
||||
{
|
||||
title: "Get Document",
|
||||
description:
|
||||
"Read one stored document by ID from any space you can access, including its summary and available content. Use listDocuments to discover document IDs.",
|
||||
"Read one stored document by ID from any space you can access, including its summary and available content. Use list_documents to discover document IDs.",
|
||||
inputSchema,
|
||||
outputSchema: getDocumentOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
|
|||
63
apps/mcp/src/server/tools/get-profile.ts
Normal file
63
apps/mcp/src/server/tools/get-profile.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { z } from "zod"
|
||||
import { optionalContainerTagSchema } from "../container-tag"
|
||||
import { formatFactSection } from "../space-presentation"
|
||||
import { READ_ONLY_TOOL_ANNOTATIONS } from "./annotations"
|
||||
import { getProfileOutputSchema, type GetProfileOutput } from "./output-schemas"
|
||||
import { textContent, type ToolDeps } from "./types"
|
||||
|
||||
export function register(deps: ToolDeps) {
|
||||
const inputSchema = z.object({
|
||||
containerTag: optionalContainerTagSchema,
|
||||
})
|
||||
|
||||
deps.server.registerTool(
|
||||
"get_profile",
|
||||
{
|
||||
title: "Get Profile",
|
||||
description:
|
||||
"Get the stable and recent profile for one space — long-lived facts plus recent context. search_memory does not include this. After searching, call this if matching memories are not enough and you need who-the-user-is, preferences, or recent context. When the user names a space, resolve it with list_spaces and pass containerTag; otherwise use the active space. Use who_am_i for account identity and access, not profile facts.",
|
||||
inputSchema,
|
||||
outputSchema: getProfileOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
},
|
||||
async (args) => {
|
||||
try {
|
||||
const effectiveTag = await deps.resolveContainerTag(args.containerTag)
|
||||
const profileResult = await deps.getClient(effectiveTag).getProfile()
|
||||
const profile = {
|
||||
static: profileResult.profile.static,
|
||||
dynamic: profileResult.profile.dynamic,
|
||||
}
|
||||
|
||||
const parts = [
|
||||
...formatFactSection(
|
||||
"Stable Context",
|
||||
profile.static,
|
||||
profile.static.length,
|
||||
),
|
||||
...formatFactSection(
|
||||
"Recent Context",
|
||||
profile.dynamic,
|
||||
profile.dynamic.length,
|
||||
),
|
||||
]
|
||||
|
||||
if (parts.length === 0) {
|
||||
parts.push("No profile facts are available for this space yet.")
|
||||
}
|
||||
|
||||
const structuredContent: GetProfileOutput = {
|
||||
containerTag: effectiveTag,
|
||||
profile,
|
||||
}
|
||||
|
||||
return {
|
||||
content: [textContent(parts.join("\n"))],
|
||||
structuredContent,
|
||||
}
|
||||
} catch (error) {
|
||||
return deps.errorResult(error)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import * as addMemory from "./add-memory"
|
||||
import * as fetchGraphData from "./fetch-graph-data"
|
||||
import * as getDocument from "./get-document"
|
||||
import * as getProfile from "./get-profile"
|
||||
import * as guidedSave from "./guided-save"
|
||||
import * as listContainerTags from "./list-container-tags"
|
||||
import * as listDocuments from "./list-documents"
|
||||
|
|
@ -17,6 +18,7 @@ import * as whoAmI from "./who-am-i"
|
|||
|
||||
export function registerAllTools(deps: ToolDeps) {
|
||||
searchMemory.register(deps)
|
||||
getProfile.register(deps)
|
||||
listDocuments.register(deps)
|
||||
getDocument.register(deps)
|
||||
listMemories.register(deps)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { textContent, type ToolDeps } from "./types"
|
|||
|
||||
export function register(deps: ToolDeps) {
|
||||
deps.server.registerTool(
|
||||
"listSpaces",
|
||||
"list_spaces",
|
||||
{
|
||||
description:
|
||||
"List the spaces available to the user. Returns each space's name, key, emoji, document/memory counts, and last activity. Use this first to resolve a named space before calling a space-aware tool, or when the user asks which space may contain something. The list is auto-filtered to spaces the user can access.",
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ export function register(deps: ToolDeps) {
|
|||
})
|
||||
|
||||
deps.server.registerTool(
|
||||
"listDocuments",
|
||||
"list_documents",
|
||||
{
|
||||
title: "List Documents",
|
||||
description:
|
||||
"List documents in one space with their IDs, titles, types, processing status, dates, and summaries. This does not return full document content; use getDocument with an ID from this result to read one document. When the user names a space, resolve it with listSpaces and pass containerTag; otherwise use the active space.",
|
||||
"List documents in one space with their IDs, titles, types, processing status, dates, and summaries. This does not return full document content; use get_document with an ID from this result to read one document. When the user names a space, resolve it with list_spaces and pass containerTag; otherwise use the active space.",
|
||||
inputSchema,
|
||||
outputSchema: listDocumentsOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ export function register(deps: ToolDeps) {
|
|||
})
|
||||
|
||||
deps.server.registerTool(
|
||||
"listMemories",
|
||||
"list_memories",
|
||||
{
|
||||
title: "List Memories",
|
||||
description:
|
||||
"List the latest extracted memory entries in one space, including stable memory IDs, version information, and source document IDs. This lists memories directly, not documents. When the user names a space, resolve it with listSpaces and pass containerTag; otherwise use the active space. Use search_memory instead for semantic recall.",
|
||||
"List the latest extracted memory entries in one space, including stable memory IDs, version information, and source document IDs. This lists memories directly, not documents. When the user names a space, resolve it with list_spaces and pass containerTag; otherwise use the active space. Use search_memory instead for semantic recall.",
|
||||
inputSchema,
|
||||
outputSchema: listMemoriesOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export function register(deps: ToolDeps) {
|
|||
{
|
||||
title: "Memory Graph",
|
||||
description:
|
||||
"Render a space's memory graph directly as an interactive MCP App. This tool is the final visualization; do not create another graph, file, or artifact unless the user explicitly asks for one. If the user names a space, call listSpaces to resolve its key and pass it as containerTag. If the user does not name a space, call this tool directly and omit containerTag; the server uses the active space or account default. Do not open the space picker unless the user asks to change their active space.",
|
||||
"Render a space's memory graph directly as an interactive MCP App. This tool is the final visualization; do not create another graph, file, or artifact unless the user explicitly asks for one. If the user names a space, call list_spaces to resolve its key and pass it as containerTag. If the user does not name a space, call this tool directly and omit containerTag; the server uses the active space or account default. Do not open the space picker unless the user asks to change their active space.",
|
||||
inputSchema,
|
||||
outputSchema: graphViewSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
|
|||
|
|
@ -107,6 +107,16 @@ export const searchMemoryOutputSchema = z.object({
|
|||
|
||||
export type SearchMemoryOutput = z.infer<typeof searchMemoryOutputSchema>
|
||||
|
||||
export const getProfileOutputSchema = z.object({
|
||||
containerTag: z.string(),
|
||||
profile: z.object({
|
||||
static: z.array(z.string()),
|
||||
dynamic: z.array(z.string()),
|
||||
}),
|
||||
})
|
||||
|
||||
export type GetProfileOutput = z.infer<typeof getProfileOutputSchema>
|
||||
|
||||
export const whoAmIOutputSchema = z.object({
|
||||
userId: z.string(),
|
||||
email: z.string().optional(),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ export function register(deps: ToolDeps) {
|
|||
.string()
|
||||
.max(1000, "Query exceeds maximum length")
|
||||
.describe("The search query to find relevant memories"),
|
||||
includeProfile: z.boolean().optional().default(true),
|
||||
containerTag: optionalContainerTagSchema,
|
||||
})
|
||||
|
||||
|
|
@ -22,7 +21,7 @@ export function register(deps: ToolDeps) {
|
|||
"search_memory",
|
||||
{
|
||||
description:
|
||||
"Search memories in one space with a natural-language query. Returns relevant memories plus that space's profile summary. When the user names a space, resolve it with listSpaces and pass containerTag; otherwise use the active space.",
|
||||
"Search memories in one space with a natural-language query. Returns matching memories only — not the space profile. If you need who-the-user-is, preferences, or recent context after searching, call get_profile. When the user names a space, resolve it with list_spaces and pass containerTag; otherwise use the active space.",
|
||||
inputSchema,
|
||||
outputSchema: searchMemoryOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
@ -32,28 +31,6 @@ export function register(deps: ToolDeps) {
|
|||
const effectiveTag = await deps.resolveContainerTag(args.containerTag)
|
||||
const client = deps.getClient(effectiveTag)
|
||||
|
||||
const parts: string[] = []
|
||||
let profile: SearchMemoryOutput["profile"]
|
||||
|
||||
if (args.includeProfile !== false) {
|
||||
const profileResult = await client.getProfile(args.query)
|
||||
profile = profileResult.profile
|
||||
|
||||
if (profileResult.profile.static.length > 0) {
|
||||
parts.push("## Profile")
|
||||
for (const fact of profileResult.profile.static) {
|
||||
parts.push(`- ${fact}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (profileResult.profile.dynamic.length > 0) {
|
||||
parts.push("\n## Recent context")
|
||||
for (const fact of profileResult.profile.dynamic) {
|
||||
parts.push(`- ${fact}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const searchResult = await client.search(args.query)
|
||||
const results = searchResult.results.map((result) => ({
|
||||
id: result.id,
|
||||
|
|
@ -62,21 +39,21 @@ export function register(deps: ToolDeps) {
|
|||
...(result.title ? { title: result.title } : {}),
|
||||
}))
|
||||
|
||||
const parts: string[] = []
|
||||
if (searchResult.results.length > 0) {
|
||||
parts.push("\n## Matching memories")
|
||||
parts.push("## Matching memories")
|
||||
for (const result of searchResult.results) {
|
||||
const text = getMemoryText(result)
|
||||
const similarity = (result.similarity * 100).toFixed(0)
|
||||
parts.push(`- [${similarity}%] ${text}`)
|
||||
}
|
||||
} else {
|
||||
parts.push("\nNo matching memories found.")
|
||||
parts.push("No matching memories found.")
|
||||
}
|
||||
|
||||
const structuredContent: SearchMemoryOutput = {
|
||||
query: args.query,
|
||||
containerTag: effectiveTag,
|
||||
...(profile ? { profile } : {}),
|
||||
results,
|
||||
total: searchResult.total,
|
||||
timing: searchResult.timing,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export function register(deps: ToolDeps) {
|
|||
{
|
||||
title: "Select Space",
|
||||
description:
|
||||
"Open an interactive picker to choose or change the active Supermemory space used for future actions. Use this only when the user asks to switch, select, or change their active or default space. Do not use it merely because the user names a space for a search, list, graph, save, or upload; resolve that space with listSpaces and pass containerTag to the relevant tool instead.",
|
||||
"Open an interactive picker to choose or change the active Supermemory space used for future actions. Use this only when the user asks to switch, select, or change their active or default space. Do not use it merely because the user names a space for a search, list, graph, save, or upload; resolve that space with list_spaces and pass containerTag to the relevant tool instead.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: pickerViewSchema,
|
||||
_meta: appToolMeta(),
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import { textContent, type ToolDeps } from "./types"
|
|||
|
||||
export function register(deps: ToolDeps) {
|
||||
deps.server.registerTool(
|
||||
"whoAmI",
|
||||
"who_am_i",
|
||||
{
|
||||
description:
|
||||
"Get the current Supermemory account context, including user identity, role, access type, permissions, scope, and active space. Use this when the user asks who they are, what access they have, or which space is currently active. Use listSpaces instead when the user asks which spaces are available.",
|
||||
"Get the current Supermemory account context, including user identity, role, access type, permissions, scope, and active space. Use this when the user asks who they are, what access they have, or which space is currently active. Use list_spaces instead when the user asks which spaces are available.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: whoAmIOutputSchema,
|
||||
annotations: READ_ONLY_TOOL_ANNOTATIONS,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue