Skip to content

fix(mcp): slots flag guard, error detail, and dropped tool params#894

Open
rohitg00 wants to merge 2 commits into
mainfrom
fix/mcp-slots-and-param-plumbing
Open

fix(mcp): slots flag guard, error detail, and dropped tool params#894
rohitg00 wants to merge 2 commits into
mainfrom
fix/mcp-slots-and-param-plumbing

Conversation

@rohitg00

@rohitg00 rohitg00 commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Closes #888.

Slot tools dispatched to mem::slot-* functions that are only registered when AGENTMEMORY_SLOTS is enabled, so disabled installs got an opaque Internal error instead of guidance. The MCP dispatch now returns the same structured error/flag/enableHow body the REST endpoints already use, and tools/list stops advertising slot tools while the flag is off, so clients no longer see tools that fail by construction.

Also in this change: the dispatch catch-all now includes the underlying error message; memory_save accepts array-typed concepts and files (was string-only split, arrays silently became empty); the standalone shim plumbs the project parameter through validation, the proxied remember body, and the local fallback record; memory_sessions takes a limit (default 20, max 100) and returns the most recent sessions sorted by startedAt descending instead of the full unbounded list.

Tested by test/mcp-tools-call.test.ts plus new cases in the surface default and standalone proxy suites.

Summary by CodeRabbit

  • New Features

    • Optional project parameter for memory save; memory sessions accept a limit and return most-recent first.
  • Improvements

    • Slot-related memory tools are hidden when slots are disabled.
    • Tool error responses include more descriptive internal messages.
    • Parsing of concept/file inputs accepts both arrays and comma-separated strings.
  • Tests

    • Added tests covering slot gating, project forwarding, parsing behavior, and session limits.
  • Documentation

    • Updated tools reference for memory_sessions parameters.

Slot tools dispatched to mem::slot-* functions that are only registered
when AGENTMEMORY_SLOTS is enabled, so disabled installs got an opaque
Internal error instead of guidance. The MCP dispatch now returns the same
structured error/flag/enableHow body the REST endpoints already use, and
tools/list stops advertising slot tools while the flag is off.

The dispatch catch-all now includes the underlying error message so real
failures are diagnosable instead of a bare Internal error.

memory_save dropped array-typed concepts and files (string-only split)
and the standalone shim dropped the project parameter in validation, the
proxied remember body, and the local fallback record. Both now plumb
through.

memory_sessions returned every session unbounded; it now accepts a limit
(default 20, max 100) and returns the most recent sessions sorted by
startedAt descending.

Covered by test/mcp-tools-call.test.ts plus new cases in the surface
default and standalone proxy suites.
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agentmemory Ready Ready Preview, Comment Jun 10, 2026 10:55pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 11b91900-0846-4f2f-9b4a-4d880d0c8697

📥 Commits

Reviewing files that changed from the base of the PR and between 680de73 and 0ff0309.

📒 Files selected for processing (1)
  • plugin/skills/agentmemory-mcp-tools/REFERENCE.md

📝 Walkthrough

Walkthrough

This PR gates slot tools in the MCP surface and call path, adds optional project to memory_save and forwards it through proxy/local save, normalizes CSV inputs for concepts/files, paginates and sorts memory_sessions, and surfaces trigger error messages. Tests added/updated to cover these behaviors.

Changes

MCP Tool Improvements

Layer / File(s) Summary
Slot Tool Visibility & Gating
src/mcp/tools-registry.ts, src/mcp/server.ts, test/mcp-surface-default.test.ts
Tool registry exports SLOT_TOOL_NAMES and filters slot tools from getVisibleTools() when isSlotsEnabled() is false. Server handler short-circuits slot tool calls with a 200 isError payload when slots are disabled; surface tests validate env setup and visibility.
Memory Save Project & CSV Parsing
src/mcp/standalone.ts, src/mcp/server.ts, test/mcp-standalone-proxy.test.ts, test/mcp-tools-call.test.ts
memory_save accepts optional project (validated, proxied to /agentmemory/remember, and persisted in local fallback). concepts and files parsing now use parseCsvList to accept arrays or comma-separated strings; tests cover forwarding and parsing.
Memory Sessions Sorting & Pagination
src/mcp/tools-registry.ts, src/mcp/server.ts, plugin/skills/agentmemory-mcp-tools/REFERENCE.md, test/mcp-tools-call.test.ts
memory_sessions input schema gains optional limit (1–100, default 20). Handler lists typed sessions, sorts by startedAt descending, and slices to the bounded limit; docs and tests updated.
Error Reporting & Test Infrastructure
src/mcp/server.ts, test/mcp-tools-call.test.ts
MCP call catch-all now includes the thrown error message in the returned error field. Tests add a call-dispatch harness (mockKV, mockSdk), register endpoints per-test, and validate dispatch, gating, parsing, pagination, and error propagation.
Proxy Project Field Forwarding Test
test/mcp-standalone-proxy.test.ts
New test verifies the standalone proxy forwards project in memory_save requests.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ToolsRegistry
  participant MCPServer
  participant SDK
  participant KV

  Client->>ToolsRegistry: getVisibleTools()
  ToolsRegistry->>ToolsRegistry: filter out SLOT_TOOL_NAMES if slots disabled
  Client->>MCPServer: mcp::tools::call(name, args)
  MCPServer->>MCPServer: if name in SLOT_TOOL_NAMES && !isSlotsEnabled() -> return isError
  alt slot call allowed
    MCPServer->>SDK: trigger appropriate mem::... function (or proxy)
    SDK->>KV: read/write as needed (e.g., sessions, remember)
    SDK-->>MCPServer: trigger response
    MCPServer-->>Client: return tool output
  else proxy/local memory_save
    MCPServer->>KV: persist with optional project
    MCPServer-->>Client: return saved response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hopped through slots and found them closed,

I tucked a project where memory grows,
Concepts trimmed and CSVs clean,
Sessions sorted, pages seen,
Errors now speak so debuggers glow.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Changes include additional enhancements beyond #888 scope: memory_save accepts project parameter [standalone.ts], memory_save handles array-typed concepts/files [server.ts], and memory_sessions accepts limit parameter with sorting [server.ts, tools-registry.ts]. These are related improvements to the MCP tools but extend beyond the slots-gating issue. Clarify whether the additional enhancements (project plumbing, concept/file array handling, sessions limit/sorting) were intentionally scoped into this PR or should be separated into follow-up PRs.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: slots flag guard, error detail improvements, and dropped tool params fixes.
Linked Issues check ✅ Passed All objectives from issue #888 are addressed: slot tools check isSlotsEnabled() before dispatching [server.ts], slot tools are filtered from tools/list when disabled [tools-registry.ts], and MCP error handling now includes underlying error messages [server.ts].

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-slots-and-param-plumbing

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mcp/server.ts`:
- Line 271: The limit calculation for memory_sessions uses const limit =
Math.min(asNumber(args.limit, 20) ?? 20, 100); which allows 0 or negative values
and redundantly uses ?? 20; update it to enforce a minimum of 1 and drop the
redundant fallback by using Math.max(1, Math.min(asNumber(args.limit, 20),
100))). Locate the usage in the memory_sessions handler where limit is declared
(reference symbol: asNumber and variable limit) and replace the expression so
limit is always between 1 and 100.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: a09a0762-1d4f-4be4-bc24-7d67b6260c2e

📥 Commits

Reviewing files that changed from the base of the PR and between 25e7701 and 680de73.

📒 Files selected for processing (6)
  • src/mcp/server.ts
  • src/mcp/standalone.ts
  • src/mcp/tools-registry.ts
  • test/mcp-standalone-proxy.test.ts
  • test/mcp-surface-default.test.ts
  • test/mcp-tools-call.test.ts

Comment thread src/mcp/server.ts

case "memory_sessions": {
const sessions = await kv.list(KV.sessions);
const limit = Math.min(asNumber(args.limit, 20) ?? 20, 100);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Enforce minimum limit of 1 for memory_sessions.

The limit calculation allows negative or zero values (e.g., -5 or 0), which would result in an empty array via slice(0, limit). Other tools like memory_smart_search (line 294) and memory_commits (line 1266) use Math.max(1, Math.min(...)) to enforce a minimum of 1.

Additionally, the ?? 20 is redundant since asNumber(args.limit, 20) already returns 20 when the value is not finite.

🛡️ Proposed fix
-    const limit = Math.min(asNumber(args.limit, 20) ?? 20, 100);
+    const limit = Math.max(1, Math.min(asNumber(args.limit, 20) ?? 20, 100));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const limit = Math.min(asNumber(args.limit, 20) ?? 20, 100);
const limit = Math.max(1, Math.min(asNumber(args.limit, 20) ?? 20, 100));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp/server.ts` at line 271, The limit calculation for memory_sessions
uses const limit = Math.min(asNumber(args.limit, 20) ?? 20, 100); which allows 0
or negative values and redundantly uses ?? 20; update it to enforce a minimum of
1 and drop the redundant fallback by using Math.max(1,
Math.min(asNumber(args.limit, 20), 100))). Locate the usage in the
memory_sessions handler where limit is declared (reference symbol: asNumber and
variable limit) and replace the expression so limit is always between 1 and 100.

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.

MCP call path for slot tools returns opaque "Internal error" when AGENTMEMORY_SLOTS is not enabled (v0.9.27)

1 participant