Skip to content

memory_lesson_save MCP tool drops sourceIds: lessons saved over MCP can never link to their source session #1657

Closed as duplicate

Description

@onelaview

Summary

memory_lesson_save over MCP cannot record where a lesson came from. Every lesson saved through the MCP tool ends up with "source": "manual" and "sourceIds": [], so the viewer shows "No sources recorded. This lesson was saved by hand without sourceIds…" even when the agent saving it knows exactly which session it came from.

The underlying function and the REST endpoint already support sourceIds; only the MCP surface drops it.

Where

At c6c476d:

  • Schema — src/mcp/tools-registry.ts#L823-L839: memory_lesson_save declares content, context, confidence, project, tags. No sourceIds, so MCP clients never see the parameter.
  • Handler — src/mcp/server.ts#L1133-L1148: builds the mem::lesson-save payload from those five fields plus a hard-coded source: "manual". args.sourceIds is never forwarded, so even a client that sends it anyway loses it.
  • Function already supports it — src/functions/lessons.ts#L99-L154: mem::lesson-save accepts sourceIds, stores it on create, and merges it into an existing lesson on reinforcement.
  • REST already supports it — src/triggers/api.ts#L4010: POST /agentmemory/lessons validates sourceIds via normalizeLessonSourceIds and passes it through.

Repro

  1. Call the memory_lesson_save MCP tool with any content.
  2. Open the lesson in the viewer (#lessons/<id>) or read the raw record: "sourceIds": [].
  3. There is no MCP argument that changes this. The only way to link a source is the viewer's suggested curl -X POST /agentmemory/lessons with the same content, which also counts as a reinforcement (reinforcements 0→1, confidence bumped) rather than just attaching the source.

Expected

An agent saving a lesson over MCP can pass the session (or memory / observation / crystal) ids it came from, the same as REST callers.

Suggested fix

  • Add sourceIds to the memory_lesson_save schema in tools-registry.ts, e.g. an array of strings (or a comma-separated string, matching how tags is handled), described as "ids of the sessions, memories, observations or crystals this lesson was learned from".
  • In the server.ts handler, normalise it with the same normalizeLessonSourceIds used by the REST route and forward it in the mem::lesson-save payload. Return 400 on invalid ids, like REST does.
  • Optionally, let source stay "manual" but have the viewer show the linked sources, so a hand-saved lesson with sourceIds no longer shows the "no sources recorded" hint.

Environment

agentmemory v0.9.31 (Claude Code plugin, marketplace rohitg00/agentmemory at c6c476d), macOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions