fix(mcp): forward smart_search expandIds to the proxy as an array#837
fix(mcp): forward smart_search expandIds to the proxy as an array#837MarvinFS wants to merge 2 commits into
Conversation
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>
|
@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. |
|
Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds optional ChangesexpandIds parameter support
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (1)
test/mcp-standalone-proxy.test.ts (1)
78-130: ⚡ Quick winConsider adding a test that memory_recall ignores expandIds.
The tool-name gate in standalone.ts:151 ensures
memory_recallnever forwardsexpandIds, 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
📒 Files selected for processing (2)
src/mcp/standalone.tstest/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>
|
Added the suggested guard in 819b2db: a test asserting |
The standalone MCP shim accepted
memory_smart_search'sexpandIdsargument but never forwarded it to the server:validate()dropped it andhandleProxy()omitted it from the POST body, so a caller asking to expand observation IDs silently received an unexpanded compact search.This forwards
expandIdstoPOST /agentmemory/smart-searchas an array. The daemon schema isexpandIds: 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, sosdk.triggerand MCP-host callers both work.memory_recallshares the validator branch and is gated out by the tool-name check.Tests
Three cases in
test/mcp-standalone-proxy.test.tsassert 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
Tests