Skip to content

feat: session_end() method and end_session MCP tool - #2

Merged
helinakdogan merged 1 commit into
mainfrom
feat/session-end
Jun 8, 2026
Merged

feat: session_end() method and end_session MCP tool#2
helinakdogan merged 1 commit into
mainfrom
feat/session-end

Conversation

@helinakdogan

Copy link
Copy Markdown
Owner

Summary

  • sdk/magnet/client.pyBehavioralMemory.session_end():

    • Takes last max_messages=20 turns from the session
    • Calls LLM with prompt: "Extract key decisions, learned preferences, and important context… Format as bullet points."
    • Falls back to _auto_summarize() if LLM call fails
    • Stores summary as episode with importance=0.9 in EpisodicStore (Layer 2)
    • Also writes to Redis key magnet:session_summary:{tenant_id} with 30-day TTL
    • Returns {"status": "ok", "summary": str}
    • Also stored self._redis = redis_client in __init__ (needed for the TTL write)
  • sdk/magnet/mcp_server.pyend_session MCP tool:

    • Description: "Summarize and save current session to memory"
    • Input: user_id, project_id, messages (array)
    • Output: {"status": "ok", "summary": string}
    • Delegates to session_end() via asyncio.to_thread

Replaces Claude Code's compact feature — automatically saves what matters, forgets the rest.

Test plan

  • Call session_end(user_id, project_id, messages) — returns {"status": "ok", "summary": "..."} with bullet points
  • Redis key magnet:session_summary:{tenant_id} exists with 30-day TTL after call
  • EpisodicStore.recall() returns the session summary as a top result (importance=0.9)
  • LLM failure → graceful fallback to _auto_summarize, no exception raised
  • MCP end_session tool callable from Claude Code / Cursor via stdio

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@helinakdogan
helinakdogan merged commit 919bc23 into main Jun 8, 2026
1 check failed
@helinakdogan
helinakdogan deleted the feat/session-end branch June 8, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant