Repository navigation
feat(mcp): expose memory_forget tool so observations and sessions can actually be deleted #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9af6e8a
252d92f
5c8a362
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,6 +620,47 @@ export function registerMcpEndpoints( | |
| } | ||
| } | ||
|
|
||
| case "memory_forget": { | ||
| const sessionId = asNonEmptyString(args.sessionId); | ||
| const memoryId = asNonEmptyString(args.memoryId); | ||
| const observationIds = parseCsvList(args.observationIds); | ||
| if (observationIds.length > 0 && !sessionId) { | ||
| return { | ||
| status_code: 400, | ||
| body: { error: "observationIds requires sessionId" }, | ||
| }; | ||
| } | ||
| if (!sessionId && !memoryId) { | ||
| return { | ||
| status_code: 400, | ||
| body: { error: "sessionId or memoryId is required" }, | ||
| }; | ||
| } | ||
| try { | ||
| const result = await sdk.trigger({ function_id: "mem::forget", payload: { | ||
| ...(sessionId ? { sessionId } : {}), | ||
| ...(observationIds.length > 0 ? { observationIds } : {}), | ||
| ...(memoryId ? { memoryId } : {}), | ||
|
Comment on lines
+624
to
+643
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject malformed At Line 626, malformed Proposed fix case "memory_forget": {
const sessionId = asNonEmptyString(args.sessionId);
const memoryId = asNonEmptyString(args.memoryId);
- const observationIds = parseCsvList(args.observationIds);
+ const hasObservationIds = args.observationIds !== undefined;
+ if (
+ hasObservationIds &&
+ typeof args.observationIds !== "string" &&
+ !Array.isArray(args.observationIds)
+ ) {
+ return {
+ status_code: 400,
+ body: { error: "observationIds must be a comma-separated string or string[]" },
+ };
+ }
+ if (
+ Array.isArray(args.observationIds) &&
+ args.observationIds.some((v) => typeof v !== "string" || !v.trim())
+ ) {
+ return {
+ status_code: 400,
+ body: { error: "observationIds array must contain non-empty strings" },
+ };
+ }
+ const observationIds = parseCsvList(args.observationIds);
+ if (hasObservationIds && observationIds.length === 0) {
+ return {
+ status_code: 400,
+ body: { error: "observationIds must contain at least one ID" },
+ };
+ }
if (observationIds.length > 0 && !sessionId) {
return {
status_code: 400,
body: { error: "observationIds requires sessionId" },
};As per coding guidelines: MCP tool handlers must validate arguments with 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } }); | ||
| return { | ||
| status_code: 200, | ||
| body: { | ||
| content: [ | ||
| { type: "text", text: JSON.stringify(result, null, 2) }, | ||
| ], | ||
| }, | ||
| }; | ||
| } catch { | ||
| return { | ||
| status_code: 200, | ||
| body: { | ||
| content: [{ type: "text", text: "Forget failed" }], | ||
| isError: true, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| case "memory_snapshot_create": { | ||
| try { | ||
| const result = await sdk.trigger({ function_id: "mem::snapshot-create", payload: { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align governance-delete instructions with the actual runtime contract.
This text currently says
memoryIdscan be an array and thatreasondefaults to"plugin skill request". In current runtime behavior, MCPmemory_governance_deleteexpects a comma-separated string in this path, and backend default reason is"manual deletion".Proposed wording fix
🤖 Prompt for AI Agents