Skip to content

feat: add get_session MCP tool to resolve memory_session_id to Claude Code session#1639

Closed
skypper wants to merge 2 commits intothedotmack:mainfrom
skypper:feature/get-session-mcp-tool
Closed

feat: add get_session MCP tool to resolve memory_session_id to Claude Code session#1639
skypper wants to merge 2 commits intothedotmack:mainfrom
skypper:feature/get-session-mcp-tool

Conversation

@skypper
Copy link
Copy Markdown

@skypper skypper commented Apr 7, 2026

Summary

Usage

After get_observations() returns results containing memory_session_id, Claude can now call:

get_session(memory_session_ids=["d308ed77-fefb-4abf-9566-b3e7711ed420"])

And get back the Claude Code session ID and name the user can actually recognise and navigate to.

Test plan

  • Call search() + get_observations() to find observations with a known memory_session_id
  • Call get_session(memory_session_ids=[...]) and verify content_session_id and custom_title are returned correctly
  • Test with multiple IDs in one call
  • Test with an unknown memory_session_id — should return an empty array

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

Summary by CodeRabbit

  • New Features
    • Added a batch session retrieval tool: users can query multiple sessions at once and receive consolidated session metadata (IDs, titles, project, start time, status) as formatted JSON.

Walkthrough

Added a new MCP tool, get_session, that accepts memory_session_ids and queries the Worker /api/sdk-sessions/batch endpoint to return mapped session metadata (content_session_id, custom_title, project, started_at, status) as MCP text content.

Changes

Cohort / File(s) Summary
New MCP tool
src/servers/mcp-server.ts
Registered get_session tool with input schema memory_session_ids: string[] (required, no additional props). Handler POSTs { memorySessionIds: memory_session_ids } to /api/sdk-sessions/batch, validates response, maps session fields into a metadata array, and returns it as a single MCP text content item.

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)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hop, hop — a lookup fresh and neat,
I fetch the sessions, link each heartbeat.
From memory IDs to titles bright,
I hop the path and shed some light,
Trail to sessions found — a rabbit's delight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a new MCP tool named get_session that resolves memory_session_id to Claude Code session information.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the new get_session MCP tool and providing usage examples and test plans.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #1638: a new MCP tool that resolves memory_session_id to Claude Code session metadata (content_session_id, custom_title, project, started_at, status) via the existing /api/sdk-sessions/batch endpoint.
Out of Scope Changes check ✅ Passed All changes are in scope: only adds the get_session MCP tool handler and schema to mcp-server.ts as specified in #1638, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f01228 and cbef129.

📒 Files selected for processing (2)
  • plugin/scripts/mcp-server.cjs
  • src/servers/mcp-server.ts

Comment thread src/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.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/servers/mcp-server.ts (1)

237-244: Consider enforcing at least one memory_session_id in schema.

The PR objective says “one or more” IDs; adding minItems: 1 prevents 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

📥 Commits

Reviewing files that changed from the base of the PR and between cbef129 and 7c35d92.

📒 Files selected for processing (2)
  • plugin/scripts/mcp-server.cjs
  • src/servers/mcp-server.ts

@skypper
Copy link
Copy Markdown
Author

skypper commented Apr 7, 2026

@thedotmack hey, would love a review when you get a chance! 👋

@thedotmack
Copy link
Copy Markdown
Owner

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.

@thedotmack thedotmack closed this Apr 15, 2026
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.

Add MCP tool to resolve memory_session_id → Claude Code session ID and name

2 participants