fix(mcp): use POST /v4/memories + add test suite reproducing v3 bug#1040
Open
ZongrongLi wants to merge 3 commits into
Open
fix(mcp): use POST /v4/memories + add test suite reproducing v3 bug#1040ZongrongLi wants to merge 3 commits into
ZongrongLi wants to merge 3 commits into
Conversation
…eation The SDK's client.add() calls POST /v3/documents which uses the document upload pipeline. This pipeline fails to process plain-text memory content — all documents created this way end up with status: 'failed' and 0 memory entries. POST /v4/memories is the correct endpoint for plain-text memory creation. Memories created via v4 are immediately searchable. Before: 19/19 documents failed (0 memories) After: 22/22 memories active and searchable
The MCP client's createMemory() previously threw a raw Error for non-ok HTTP
responses. handleError() checks for a .status property to dispatch per-status
messages — without it every status came back as 'Failed to create memory: N'.
Fix: attach .status to the error object before throwing.
Test coverage (12 tests, all pass):
- Endpoint: POST /v4/memories vs POST /v3/documents (the bug)
- Payload format: {containerTag, memories: [{content, metadata}]}
- Response mapping: status, id, containerTag
- Auth header passthrough
- Error handling: 401 / 402 / 429 / 500 / network error
- Contract guard: v3 vs v4 payload shapes
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
…critical RCE (GHSA-9qr9-h5gf-34mp) Socket flagged next@16.0.3 as a Critical CVE (RCE in React flight protocol). Aligning with apps/web (^16.0.11); both now dedupe to next@16.1.6. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c08668e to
b1de8a0
Compare
ishaanxgupta
requested changes
Jun 5, 2026
Contributor
ishaanxgupta
left a comment
There was a problem hiding this comment.
Can we either remove the unrelated apps/memory-graph-playground/package.json & bun.lock churn?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Related to #792 (Claude Code plugin writes memories but recall/search returns empty — same write-path root cause for MCP users; issue #792 may also involve a separate read-path bug in the plugin)
Problem
The MCP
createMemory()method calls the SDK’sclient.memories.add(), which maps toPOST /v3/documents. This endpoint routes through the document ingestion workflow (IngestContentWorkflow) that handles extraction, summarization, chunking, and embedding — designed for URLs, PDFs, images, and file uploads.When plain text is sent through this pipeline:
"failed"Real-world impact: 19/19 documents created by the MCP end up with status=failed. Users report "memories saved but search returns empty" (#792).
Original Design Decision
The original author used
client.memories.add()because it was the only.add()method exposed by the SDK. However, the entireclient.memoriesSDK class is misnamed — it operates on/v3/documents/*endpoints (list, update, delete, get documents). It is a document resource, not a memory resource.The correct API for storing plain-text memories is
POST /v4/memories, explicitly documented inapps/docs/memory-operations.mdx:(Source: apps/docs/memory-operations.mdx, lines 15-20)
Fix (2 commits)
Commit 1: Replace
client.add()with direct fetch toPOST /v4/memoriesBefore:
After:
Commit 2: Fix HTTP error dispatch
The
!response.okbranch threw a rawErrorwithout a.statusproperty. The existinghandleError()method dispatches status codes (401=reauth, 402=upgrade, 429=backoff, 500=retry) via"status" in error— without it every failure returned the same generic message.Fix: Attach
error.status = response.statusbefore throwing.Test Coverage (12 tests, all pass)
The test suite uses vitest to mock
fetch()and verify every code path:Run with:
Verification
After the fix, 22/22 memories created via MCP are active and searchable (previously 19/19 failed). Verified on supermemory.ai web UI and through API search.
Files Changed
apps/mcp/src/client.tsapps/mcp/src/__tests__/supermemory-client.test.tsapps/mcp/vitest.config.tsapps/mcp/package.jsonbun.lock