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

@MarvinFS MarvinFS commented Jun 5, 2026

Copy link
Copy Markdown

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 supports an optional expandIds input (either a comma-separated string or an array). When provided, it’s normalized and forwarded with smart-search requests, and is omitted when not set.
    • expandIds is not forwarded for recall requests.
  • Tests

    • Added coverage to verify request serialization/forwarding behavior for expandIds in proxy mode for smart-search and recall.

@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

@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

coderabbitai Bot commented Jun 5, 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: cda6c900-2eb3-489c-9287-0a85ea423ef4

📥 Commits

Reviewing files that changed from the base of the PR and between 02816fa and 6a05114.

📒 Files selected for processing (2)
  • src/mcp/standalone.ts
  • test/mcp-standalone-proxy.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/mcp-standalone-proxy.test.ts
  • src/mcp/standalone.ts

📝 Walkthrough

Walkthrough

Adds optional expandIds handling for memory_smart_search. Validation normalizes the value into an array, and proxy requests conditionally forward it to /agentmemory/smart-search; memory_recall excludes the field.

Changes

expandIds parameter support

Layer / File(s) Summary
Type contract and argument validation
src/mcp/standalone.ts
Validated arguments include optional expandIds; validation normalizes and assigns it only for memory_smart_search.
Proxy forwarding and test coverage
src/mcp/standalone.ts, test/mcp-standalone-proxy.test.ts
The proxy conditionally sends expandIds as an array, with tests covering string input, arrays, omission, and memory_recall exclusion.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue #889: The change addresses the standalone MCP shim’s expandIds handling, while the issue also describes a separate engine expansion bug.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MCPStandalone
  participant AgentMemoryDaemon
  Client->>MCPStandalone: Call memory_smart_search with expandIds
  MCPStandalone->>MCPStandalone: Normalize expandIds
  MCPStandalone->>AgentMemoryDaemon: POST /agentmemory/smart-search with expandIds array
  AgentMemoryDaemon-->>MCPStandalone: Search response
  MCPStandalone-->>Client: Proxied response
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes [#440] expandIds forwarding, but leaves memory_recall format routing and endpoint split unresolved. Also split memory_recall from smart_search in validation and proxy handling, and forward format to /agentmemory/search.
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 (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the MCP smart_search expandIds proxy fix, matching the main change.
Out of Scope Changes check ✅ Passed All changes stay within the MCP proxy/validation path and its tests, with no unrelated functionality added.
✨ 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.

@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.

🧹 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

@MarvinFS

MarvinFS commented Jun 5, 2026

Copy link
Copy Markdown
Author

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.

@MarvinFS
MarvinFS force-pushed the fix/440-smart-search-proxy-expandids branch from 819b2db to 02816fa Compare June 8, 2026 07:04
@MarvinFS

MarvinFS commented Jun 8, 2026

Copy link
Copy Markdown
Author

Gentle ping on this one. Still merges cleanly against current main. The fix is small and self-contained: the standalone proxy forwards smart_search's expandIds as a comma-joined string, but the server schema is z.array(z.string()), so any expand-by-id call returns HTTP 500. Forwarding it as an array (matching the schema) makes expand work end to end. Closes #440. Happy to adjust anything if it helps it land.

MarvinFS added 2 commits July 19, 2026 18:30
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>
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
MarvinFS force-pushed the fix/440-smart-search-proxy-expandids branch from 02816fa to 6a05114 Compare July 19, 2026 15:32
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