codebase-memory-mcp
codebase-memory-mcp copied to clipboard
Bug: /tmp hardcoded in write_pattern_file breaks Windows (search_code fails)
Problem
The implementation of write_pattern_file in src/mcp/mcp.c hardcodes the temporary pattern file path to /tmp/cbm_search_<pid>.pat on both Linux and Windows builds:
#ifdef _WIN32
snprintf(tmpfile, tmpfile_sz, "/tmp/cbm_search_%d.pat", (int)_getpid());
#else
snprintf(tmpfile, tmpfile_sz, "/tmp/cbm_search_%d.pat", getpid());
#endif
On Windows, /tmp does not exist unless in a special environment like MSYS2/Cygwin, so fopen() fails and search_code returns an error like:
search failed: cannot create temp file (...)
How to Reproduce
- Run
search_code(via REST/JSON-RPC) on a Windows system (e.g., in a native CMD or PowerShell environment). - Observe error/failure when code search tries to write to
/tmp/....
Impact
- Code search functionality (
search_codeendpoint/tool) is broken on native Windows installations. - Affects any use of
write_pattern_fileunder Windows outside POSIX-shimmed environments.
Suggested Fix
- Use a platform-specific temp directory for the pattern file, e.g., via
cbm_tmpdir()or an equivalent helper that respects Windows temp conventions (%TEMP%env variable orGetTempPath). - Example:
const char *tmpdir = cbm_tmpdir(); #ifdef _WIN32 snprintf(tmpfile, tmpfile_sz, "%s/cbm_search_%d.pat", tmpdir, (int)_getpid()); #else snprintf(tmpfile, tmpfile_sz, "%s/cbm_search_%d.pat", tmpdir, getpid()); #endif
See also
src/mcp/mcp.cL3105- Other code already uses
cbm_tmpdir()as a fallback for temp/cache dirs, seecache_dir()etc.
Labels: bug, windows