feat: add get_session MCP tool to resolve memory_session_id to Claude Code session#1639
feat: add get_session MCP tool to resolve memory_session_id to Claude Code session#1639skypper wants to merge 2 commits intothedotmack:mainfrom
Conversation
… Code session Closes thedotmack#1638
Summary by CodeRabbit
WalkthroughAdded a new MCP tool, Changes
Sequence Diagram(s)sequenceDiagram
participant Claude as Claude (MCP Client)
participant MCP as MCP Server (get_session tool)
participant Worker as Worker API (/api/sdk-sessions/batch)
Claude->>MCP: call get_session(memory_session_ids)
MCP->>Worker: POST /api/sdk-sessions/batch\n{ memorySessionIds: [...] }
Worker-->>MCP: 200 OK with SDK sessions JSON array
MCP->>MCP: map fields -> metadata array\n(content_session_id, custom_title, project, started_at, status)
MCP-->>Claude: return MCP `text` with JSON.stringify(metadata)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/servers/mcp-server.ts`:
- Around line 233-248: The handler currently returns the raw batch response from
callWorkerAPIPost('/api/sdk-sessions/batch', { memorySessionIds:
args.memory_session_ids }) which can include prompt content (e.g., user_prompt)
from SessionStore; change the handler to post-process the worker response and
return only metadata fields—filter out user_prompt and any prompt/text fields
and map each item to a safe metadata object (e.g., memory_session_id,
claude_session_id, name, created_at or other non-content columns) before
returning to the caller so the tool adheres to a metadata-only contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0a3d520a-a2ad-4acf-a005-5b043ea17017
📒 Files selected for processing (2)
plugin/scripts/mcp-server.cjssrc/servers/mcp-server.ts
Only return metadata fields (memory_session_id, content_session_id, custom_title, project, started_at, status) to avoid leaking prompt content and reduce token usage.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/servers/mcp-server.ts (1)
237-244: Consider enforcing at least onememory_session_idin schema.The PR objective says “one or more” IDs; adding
minItems: 1prevents empty no-op calls and tightens contract validation.Suggested schema tweak
memory_session_ids: { type: 'array', items: { type: 'string' }, + minItems: 1, description: 'Array of memory_session_id values from get_observations results' }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/servers/mcp-server.ts` around lines 237 - 244, The JSON schema for the property memory_session_ids currently allows an empty array even though the PR intends “one or more” IDs; update the schema for memory_session_ids (the object with type: 'array' and items: { type: 'string' }) to enforce at least one element by adding minItems: 1 so required: ['memory_session_ids'] combined with additionalProperties: false prevents empty/no-op calls.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/servers/mcp-server.ts`:
- Around line 237-244: The JSON schema for the property memory_session_ids
currently allows an empty array even though the PR intends “one or more” IDs;
update the schema for memory_session_ids (the object with type: 'array' and
items: { type: 'string' }) to enforce at least one element by adding minItems: 1
so required: ['memory_session_ids'] combined with additionalProperties: false
prevents empty/no-op calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e5393ee1-431c-4fc2-b16d-0b5a91aa4033
📒 Files selected for processing (2)
plugin/scripts/mcp-server.cjssrc/servers/mcp-server.ts
|
@thedotmack hey, would love a review when you get a chance! 👋 |
|
Closed during the April 2026 backlog cleanup. The feature ask is now tracked in #1971, which is the single canonical issue for prioritization. Thanks for the suggestion — your context is captured there. |
Summary
get_sessionMCP tool that resolves one or morememory_session_idvalues to their corresponding Claude Code session metadata (content_session_id,custom_title,project,started_at,status)/api/sdk-sessions/batchendpoint — no new backend code neededUsage
After
get_observations()returns results containingmemory_session_id, Claude can now call:And get back the Claude Code session ID and name the user can actually recognise and navigate to.
Test plan
search()+get_observations()to find observations with a knownmemory_session_idget_session(memory_session_ids=[...])and verifycontent_session_idandcustom_titleare returned correctlymemory_session_id— should return an empty array