Skip to content

fix(mcp): forward smart_search expandIds to the proxy as an array#837

Open
MarvinFS wants to merge 2 commits into
rohitg00:mainfrom
MarvinFS:fix/440-smart-search-proxy-expandids
Open

fix(mcp): forward smart_search expandIds to the proxy as an array#837
MarvinFS wants to merge 2 commits into
rohitg00:mainfrom
MarvinFS:fix/440-smart-search-proxy-expandids

Conversation

@MarvinFS
Copy link
Copy Markdown

@MarvinFS MarvinFS commented Jun 5, 2026

The standalone MCP shim accepted memory_smart_search's expandIds argument but never forwarded it to the server: validate() dropped it and handleProxy() omitted it from the POST body, so a caller asking to expand observation IDs silently received an unexpanded compact search.

This forwards expandIds to POST /agentmemory/smart-search as an array. The daemon schema is expandIds: z.array(z.string()), so a comma-joined string fails Zod validation and surfaces as HTTP 500. normalizeList() already accepts both the tool schema's comma-separated string and a raw array, so sdk.trigger and MCP-host callers both work. memory_recall shares the validator branch and is gated out by the tool-name check.

Tests

Three cases in test/mcp-standalone-proxy.test.ts assert the wire body is { query, limit, expandIds: ["a","b"] } for a comma string, an array passthrough, and omission.

Closes #440.

Summary by CodeRabbit

  • New Features

    • Smart search now accepts an optional expandIds input (comma-separated string or array) and forwards it when performing smart-search requests.
  • Tests

    • Added tests verifying expandIds is normalized and forwarded for smart-search, omitted when absent, and not forwarded for recall requests.

The standalone shim accepted memory_smart_search's expandIds argument but
never forwarded it: validate() dropped it and handleProxy() omitted it from
the POST body, so callers asking to expand observation IDs silently got an
unexpanded compact search.

Forward it now, as an ARRAY. The daemon's /agentmemory/smart-search schema
is `expandIds: z.array(z.string())`, so a comma-joined string fails Zod
validation and surfaces as HTTP 500. normalizeList() accepts both the tool
schema's comma-separated string and a raw array, so sdk.trigger and MCP-host
callers both work. memory_recall shares the validator branch and is gated out
by the tool-name check.

Closes rohitg00#440.

Signed-off-by: MarvinFS <7998636+MarvinFS@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

@MarvinFS is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range.

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: 59f561f6-9371-4db6-b716-627df8203047

📥 Commits

Reviewing files that changed from the base of the PR and between ee28049 and 819b2db.

📒 Files selected for processing (1)
  • test/mcp-standalone-proxy.test.ts

📝 Walkthrough

Walkthrough

Adds optional expandIds handling for the memory_smart_search MCP tool: validator normalizes and sets an expandIds array only for memory_smart_search, and the proxy forwards expandIds as an array to /agentmemory/smart-search when present.

Changes

expandIds parameter support

Layer / File(s) Summary
Type contract and argument validation
src/mcp/standalone.ts
Validated interface adds optional expandIds?: string[]; validation extracts and normalizes expandIds from input args for memory_smart_search, accepting comma-separated strings or array-like inputs.
Proxy forwarding and test coverage
src/mcp/standalone.ts, test/mcp-standalone-proxy.test.ts
Proxy handler includes expandIds in the POST body sent to /agentmemory/smart-search when present; tests verify comma-string → array serialization, array passthrough, omission behavior, and that memory_recall does not forward expandIds.

Sequence Diagram

sequenceDiagram
  participant Client
  participant MCPStandalone
  participant AgentMemoryDaemon
  Client->>MCPStandalone: tool call (memory_smart_search, arguments including expandIds)
  MCPStandalone->>MCPStandalone: validate & normalize expandIds (string→array or passthrough)
  MCPStandalone->>AgentMemoryDaemon: POST /agentmemory/smart-search { query, limit, expandIds }
  AgentMemoryDaemon-->>MCPStandalone: response
  MCPStandalone-->>Client: proxied response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 I hop on code with keen delight,

expandIds turned to arrays, just right,
String or list, we tidy the trace,
Forwarded onward to memory's place,
Now searches bloom with fuller sight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for forwarding expandIds to the proxy as an array for memory_smart_search.
Linked Issues check ✅ Passed The PR addresses one of three defects from issue #440: extracting and forwarding expandIds for memory_smart_search with proper array normalization, enabling the compact-then-expand flow via MCP.
Out of Scope Changes check ✅ Passed All changes are scoped to memory_smart_search expandIds forwarding. Memory_recall is correctly gated to prevent expandIds leakage, and no unrelated modifications are present.

✏️ 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.

🧹 Nitpick comments (1)
test/mcp-standalone-proxy.test.ts (1)

78-130: ⚡ Quick win

Consider adding a test that memory_recall ignores expandIds.

The tool-name gate in standalone.ts:151 ensures memory_recall never forwards expandIds, even if a caller provides it. A test verifying this behavior would guard against regression if the shared case branch is refactored.

Suggested test case
it("memory_recall does not forward expandIds even when provided", async () => {
  let recallBody: Record<string, unknown> | undefined;
  installFetch((url, init) => {
    if (url.endsWith("/agentmemory/livez")) return new Response("ok", { status: 200 });
    if (url.endsWith("/agentmemory/search")) {
      recallBody = init?.body ? JSON.parse(init.body as string) : undefined;
      return new Response(JSON.stringify({ mode: "full", facts: [] }), { status: 200 });
    }
    return new Response("not found", { status: 404 });
  });
  await handleToolCall("memory_recall", {
    query: "test",
    expandIds: "obs_1, obs_2",
  });
  expect(recallBody).not.toHaveProperty("expandIds");
});
🤖 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 `@test/mcp-standalone-proxy.test.ts` around lines 78 - 130, Add a new unit test
that verifies the memory_recall tool never forwards expandIds: use installFetch
to intercept calls to the daemon endpoint that memory_recall uses (matching the
existing tests' pattern), call handleToolCall("memory_recall", { query: "test",
expandIds: "obs_1, obs_2" }), capture the JSON body sent to the
/agentmemory/search handler, and assert that the captured recallBody does not
have the expandIds property; this mirrors the existing memory_smart_search tests
and protects the tool-name gate logic in standalone.ts (the branch that prevents
forwarding expandIds for memory_recall).
🤖 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.

Nitpick comments:
In `@test/mcp-standalone-proxy.test.ts`:
- Around line 78-130: Add a new unit test that verifies the memory_recall tool
never forwards expandIds: use installFetch to intercept calls to the daemon
endpoint that memory_recall uses (matching the existing tests' pattern), call
handleToolCall("memory_recall", { query: "test", expandIds: "obs_1, obs_2" }),
capture the JSON body sent to the /agentmemory/search handler, and assert that
the captured recallBody does not have the expandIds property; this mirrors the
existing memory_smart_search tests and protects the tool-name gate logic in
standalone.ts (the branch that prevents forwarding expandIds for memory_recall).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04bba558-1613-45bf-80b7-9ccd352c5d24

📥 Commits

Reviewing files that changed from the base of the PR and between a323fb0 and ee28049.

📒 Files selected for processing (2)
  • src/mcp/standalone.ts
  • test/mcp-standalone-proxy.test.ts

The tool-name gate keeps expandIds on memory_smart_search only. Lock that
in so a future refactor of the shared validate/proxy branch cannot start
leaking expandIds onto the recall path.

Signed-off-by: MarvinFS <7998636+MarvinFS@users.noreply.github.com>
@MarvinFS
Copy link
Copy Markdown
Author

MarvinFS commented Jun 5, 2026

Added the suggested guard in 819b2db: a test asserting memory_recall drops expandIds even when it is supplied, locking in the tool-name gate against a future refactor of the shared validate/proxy branch.

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 memory_recall is aliased to smart-search and drops format param - full content unreachable via MCP

1 participant