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
38 changes: 31 additions & 7 deletions apps/mcp/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,39 @@ export class SupermemoryClient {
}
}

// Delete/forget memory by searching first
// Delete/forget memory - try exact match first, then semantic search
async forgetMemory(
content: string,
): Promise<{ success: boolean; message: string; containerTag: string }> {
try {
// First search for the memory
const searchResult = await this.search(content, 5)
// Try exact content matching first
try {
const result = await this.client.memories.forget({
content: content,
containerTag: this.containerTag,
})

return {
success: true,
message: `Successfully forgot memory (exact match) with ID: ${result.id}`,
containerTag: this.containerTag,
}
} catch (error: any) {
// If not 404, it's a real error - re-throw it
if (error?.status !== 404) {
throw error
Comment on lines +167 to +177
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code incorrectly assumes this.client.memories.forget() returns an object with an id. Accessing result.id will cause a TypeError because the function likely returns void.
Severity: HIGH

Suggested Fix

Remove the assignment of the return value from this.client.memories.forget() to the result variable. Update the success message to indicate successful deletion without referencing a non-existent result.id, as the function does not appear to return any value.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/mcp/src/client.ts#L164-L177

Potential issue: The code calls `this.client.memories.forget()` and assigns its return
value to `result`, then attempts to access `result.id`. Evidence from other parts of the
codebase suggests that `memories.forget()` returns `void` or `undefined`. This
discrepancy will cause a `TypeError` when `result.id` is accessed. The existing `catch`
block is not designed to handle a `TypeError`, so the function will throw an unhandled
error even when the memory deletion operation succeeds, breaking the intended
functionality of this new code path.

}
// Otherwise continue to semantic search fallback
}

// Fallback to semantic search if exact match fails
const SIMILARITY_THRESHOLD = 0.85 // High threshold - only very similar memories
const searchResult = await this.search(content, 5, SIMILARITY_THRESHOLD)

if (searchResult.results.length === 0) {
return {
success: false,
message: "No matching memory found to forget.",
message: `No matching memory found to forget. Tried exact match and semantic search with similarity threshold ${SIMILARITY_THRESHOLD}.`,
containerTag: this.containerTag,
}
}
Expand All @@ -176,10 +197,12 @@ export class SupermemoryClient {
return {
success: false,
message:
"No matching memory found to forget (only document chunks matched).",
"No matching memory found to forget (only document chunks matched in semantic search).",
containerTag: this.containerTag,
}
}

// Delete using the ID from semantic search
await this.client.memories.forget({
id: memoryToDelete.id,
containerTag: this.containerTag,
Expand All @@ -189,7 +212,7 @@ export class SupermemoryClient {
getMemoryText(memoryToDelete) || memoryToDelete.content || ""
return {
success: true,
message: `Forgot: "${limitByChars(memoryText, 100)}"`,
message: `Forgot similar memory (semantic match, similarity: ${memoryToDelete.similarity.toFixed(2)}): "${limitByChars(memoryText, 100)}"`,
containerTag: this.containerTag,
}
} catch (error) {
Expand All @@ -198,13 +221,14 @@ export class SupermemoryClient {
}

// Search memories using SDK
async search(query: string, limit = 10): Promise<SearchResult> {
async search(query: string, limit = 10, threshold?: number): Promise<SearchResult> {
try {
const result = await this.client.search.memories({
q: query,
limit,
containerTag: this.containerTag,
searchMode: "hybrid",
threshold, // Optional threshold parameter
})

// Normalize and limit response size — preserve memory vs chunk distinction
Expand Down
Loading