fix(memory): expand leading ~ in MEMORY_FILE_PATH to the home directory#4447
Open
ameyypawar wants to merge 1 commit into
Open
fix(memory): expand leading ~ in MEMORY_FILE_PATH to the home directory#4447ameyypawar wants to merge 1 commit into
ameyypawar wants to merge 1 commit into
Conversation
MCP clients pass MEMORY_FILE_PATH from JSON config, where no shell
expands a leading "~". Because path.isAbsolute("~/memory.jsonl") is
false, the value was joined onto the package directory, so the server
persisted to a literal "~" folder inside the install instead of the
user's intended location.
Add an expandHome() helper that mirrors the one already used by the
filesystem server (src/filesystem/path-utils.ts) and apply it in
ensureMemoryFilePath() before the existing absolute/relative resolution.
Absolute paths, relative paths, and a "~" not at the start are
unaffected. Adds unit tests for expandHome plus an end-to-end test
through ensureMemoryFilePath.
Addresses modelcontextprotocol#1600
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
@modelcontextprotocol/server-memoryignores aMEMORY_FILE_PATHthat begins with~(e.g.~/memory.jsonl). MCP clients pass this variable from JSON config (Claude Desktop, Cursor, Roo Cline, VS Code), where no shell performs tilde expansion. Becausepath.isAbsolute("~/memory.jsonl")isfalse,ensureMemoryFilePath()joined the value onto the package directory, so the server persisted to a literal~folder inside the install instead of the user's intended location.Addresses #1600.
Change
src/memory/index.ts: add anexpandHome()helper and call it inensureMemoryFilePath()before the existing absolute/relative resolution. A leading~or~/expands toos.homedir(); absolute paths, relative paths, and a~that is not at the start are unchanged.The helper mirrors the one already used by the filesystem server (
src/filesystem/path-utils.ts), keeping tilde handling consistent across the official servers.Tests
src/memory/__tests__/file-path.test.ts:expandHomeunit tests: bare~,~/…, a~not followed by a separator (unchanged), and absolute/relative passthrough.ensureMemoryFilePathend-to-end:~/custom-memory.jsonlresolves underos.homedir().Verified locally on this branch:
npm test→ 56/56 passing,npm run build(tsc) clean.Scope
Tilde expansion only. The
${workspaceFolder}variable substitution discussed in #1846 is a client-side concern, and #1481 is about the JSONL storage format — neither is addressed here.