fix(mcp): default container to authenticated userId when x-sm-project is absent (#792)#864
Open
teddyoweh wants to merge 1 commit intosupermemoryai:mainfrom
Open
Conversation
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.
Summary
Fixes #792. MCP sessions previously fell back to the hardcoded
sm_project_defaultcontainer insideSupermemoryClientwhen clients did not forward thex-sm-projectheader. Users who query their own container directly via/v3and/v4search (the userId-as-containerTag pattern documented inapps/docs/install.md) therefore could not see memories written through MCP — producing the empty-results symptom reported in the issue (direct API searches, MCPrecallover OAuth, and hybridsearchModeall returning nothing while MCP writes succeeded).MCP reads and writes are already symmetric through
getClient(containerTag)inserver.ts, so the divergence was purely in the default. This PR shifts the default for MCP sessions toauthUser.userId, while still honoring an explicitx-sm-projectheader when clients do forward one.Changes
apps/mcp/src/index.ts: rename the header capture toheaderContainerTag; after auth validation, computeconst containerTag = headerContainerTag || authUser.userIdand thread it throughctx.propsbefore handing off to the MCP handler. Comment added explaining the rationale and linking to Claude Code plugin writes memories but recall/search returns empty — API key and OAuth both affected #792.1 file changed, +9 / -1.
Test plan
NODE_OPTIONS="--max-old-space-size=8192" tsc --noEmitfromapps/mcp/→ zero new errors introduced onsrc/index.ts. Pre-existing errors inserver.ts(SDK type duplication) andui/mcp-app.ts(DOM types /@types/d3-force-3dmissing) are unchanged by this PR.x-sm-project, write a memory via thememorytool, then query/v3/searchwithcontainerTag: <userId>— the write should now be visible. Same memory should also be returned by MCPrecallinside the session.x-sm-project: my-project— behavior should be unchanged (writes and reads land inmy-project).