Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions apps/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,47 +50,52 @@ export class SupermemoryMCP extends McpAgent<Env, unknown, Props> {
}
}

await this.refreshContainerTags() // Fetch available projects for schema descriptions
await this.refreshContainerTags()

const containerTagDescription = this.getContainerTagDescription()
const hasRootContainerTag = !!this.props?.containerTag

const memorySchema = z.object({
content: z
.string()
.max(200000, "Content exceeds maximum length of 200,000 characters")
.describe("The memory content to save or forget"),
action: z.enum(["save", "forget"]).optional().default("save"),
const containerTagField = {
containerTag: z
.string()
.max(128, "Container tag exceeds maximum length")
.describe(containerTagDescription)
.describe(this.getContainerTagDescription())
.optional(),
}

const memorySchema = z.object({
content: z
.string()
.max(
200000,
"Content exceeds maximum length of 200,000 characters",
)
.describe("The memory content to save or forget"),
action: z
.enum(["save", "forget"])
.optional()
.default("save"),
...(hasRootContainerTag ? {} : containerTagField),
})

const recallSchema = z.object({
query: z
.string()
.max(1000, "Query exceeds maximum length of 1,000 characters")
.max(
1000,
"Query exceeds maximum length of 1,000 characters",
)
.describe("The search query to find relevant memories"),
includeProfile: z.boolean().optional().default(true),
containerTag: z
.string()
.max(128, "Container tag exceeds maximum length")
.describe(containerTagDescription)
.optional(),
...(hasRootContainerTag ? {} : containerTagField),
})

const contextPromptSchema = z.object({
containerTag: z
.string()
.max(128, "Container tag exceeds maximum length")
.describe(containerTagDescription)
.optional(),
includeRecent: z
.boolean()
.optional()
.default(true)
.describe("Include recent activity in the profile"),
...(hasRootContainerTag ? {} : containerTagField),
})

type ContextPromptArgs = z.infer<typeof contextPromptSchema>
Expand Down Expand Up @@ -289,7 +294,8 @@ export class SupermemoryMCP extends McpAgent<Env, unknown, Props> {
// @ts-expect-error - zod type inference issue with MCP SDK
async (args: ContextPromptArgs) => {
try {
const { containerTag, includeRecent = true } = args
const { includeRecent = true } = args
const containerTag = (args as { containerTag?: string }).containerTag
const client = this.getClient(containerTag)
const profileResult = await client.getProfile()

Expand Down Expand Up @@ -384,9 +390,10 @@ export class SupermemoryMCP extends McpAgent<Env, unknown, Props> {
containerTag?: string
}) {
const { content, action = "save", containerTag } = args
const effectiveContainerTag = containerTag || this.props?.containerTag

try {
const client = this.getClient(containerTag)
const client = this.getClient(effectiveContainerTag)
const clientInfo = await this.getClientInfo()

if (action === "forget") {
Expand Down
Loading