OpenMemory icon indicating copy to clipboard operation
OpenMemory copied to clipboard

[BUG] Saved memories cannot be found after the MCP server restarts

Open harpsychord opened this issue 2 months ago • 3 comments

What happened?

Description

The MCP memory server can save a memory for a specific tenant and user, but it does not retain that scope when it is restarted.

The memory remains in the database, but the restarted server searches under a default tenant and user. This makes the memory appear to be missing even though it was saved successfully.

Impact

Existing memories appear to be lost after a server restart. Callers may create duplicate memories or make decisions without relevant context.

Steps to Reproduce

  1. From the LongMemory project directory, start the MCP server with the database location but without specifying a tenant or user:

    LONGMEMORY_MCP_HTTP=true \
    LONGMEMORY_DB_PATH=./longmemory.db \
    pnpm start
    
  2. Connect to the MCP server and save a memory for a named tenant and user.

  3. Confirm that the memory can be retrieved successfully.

  4. Stop the MCP server.

  5. Start it again with the same command from step 1.

  6. Search for the memory again.

Observed Result

The server reports that the memory cannot be found.

The memory is still present in the database, but the server is searching under its default tenant and user instead of the account where the memory was saved.

Expected Result

The server should use the intended tenant and user when it starts, so memories remain available after a restart.

Proposed Fix

Have the MCP server read the configured tenant and user values during startup and use them as its memory scope. The proposed patch is attached separately.

mcp-scope.patch

Verification

Starting the server with the tenant and user explicitly provided makes the memory available:

LONGMEMORY_MCP_HTTP=true \
LONGMEMORY_DB_PATH=./longmemory.db \
LONGMEMORY_TENANT_ID=example-tenant \
LONGMEMORY_USER_ID=example-user \
pnpm start

This confirms that the problem is with the server's startup scope, not with the MCP connection or the stored memory.

Component

Backend (API/Server)

Environment

No response

Relevant log output


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

harpsychord avatar Sep 20 '26 23:09 harpsychord

Moved the proposed fix down to be above the verification. Sorry for that. GitHub's interface for opening a new issue had me breaking up my bug report and I didn't move everything down properly.

harpsychord avatar Sep 21 '26 15:09 harpsychord

Looks like the server isn't retaining the tenant and user scope on restart, which makes saved memories seem lost. I'd check how the server reads configuration on startup.

modelpath-dev avatar Sep 28 '26 13:09 modelpath-dev

Fixed on main. Root cause confirmed: load_server_config (src/server/config.ts) never read LONGMEMORY_TENANT_ID/LONGMEMORY_USER_ID from the environment, so config.memory.tenant_id/user_id were always undefined and every fallback silently defaulted to 'default' on every restart — exactly the symptom you reproduced. Both are now read into config.memory (with OM_TENANT_ID/OM_USER_ID aliases), which flows into both the plain HTTP engine and the /mcp runtime since they share the same config. Documented the two new variables in .env.example.

Appreciate the precise repro steps and the before/after verification — made this a fast, confident fix.

nullure avatar Oct 18 '26 12:10 nullure