AutoMem returns "Unauthorized" when called through CodeMode's MCP proxy, but works perfectly when called directly via Claude Code's MCP or curl.
# Direct curl to backend - WORKS
curl -X POST http://127.0.0.1:8001/memory \
-H "Authorization: Bearer mem_7163ec31424b3e9d74b986811fd310aa" \
-d '{"content":"test","tags":["test"]}'
# ✅ Returns: {"memory_id":"...","status":"success"}
# Direct MCP call from Claude Code - WORKS
mcp__automem__store_memory({content:"test",tags:["test"]})
# ✅ Success// Through CodeMode MCP proxy - FAILS
mcp.automem.store_memory({content:"test",tags:["test"]})
// ❌ Error: Unauthorized- User code execution → CodeMode MCP server (
execute_codetool) - CodeMode runtime → Queues MCP call with
__mcpCallTool() - Executor → Processes queue via
mcpManager.callTool() - MCPAggregator → Routes to AutoMem connection
- StdioClientTransport → Spawns AutoMem MCP client process
- AutoMem MCP client → Reads
AUTOMEM_API_KEYfrom env - AutoMem MCP client → Sends
Authorization: Bearer ${AUTOMEM_API_KEY} - AutoMem backend → Validates against
AUTOMEM_API_TOKEN
AUTOMEM_API_TOKEN=mem_7163ec31424b3e9d74b986811fd310aa # ✅ Correct{
"automem": {
"env": {
"AUTOMEM_ENDPOINT": "http://127.0.0.1:8001",
"AUTOMEM_API_KEY": "mem_7163ec31424b3e9d74b986811fd310aa" # ✅ Correct
}
}
}const mergedEnv = { ...process.env, ...(config.env || {}) }; // ✅ Merges env vars- Added debug logging in
aggregator.ts:147-151to log AutoMem env vars - Logs go to stderr, not visible in tool results
$ ps aux | grep automem
# 8 AutoMem MCP processes running! ⚠️
# PIDs: 63004, 45647, 23631, 45627, 45329, 41839, 32257, 32154Multiple AutoMem instances may be interfering with each other, or one of them is using incorrect/missing env vars.
- Kill all AutoMem processes and restart clean
- Verify debug logs show correct env vars being passed
- Check if MCP client is actually receiving the env vars
- Add logging to AutoMem MCP client to see what token it's sending
- Verify StdioClientTransport is passing env correctly to child process
- services/codemode-unified/src/mcp/aggregator.ts
- services/codemode-unified/src/executor.ts
- services/codemode-unified/.mcp.json
- services/automem/app.py
- /Users/danieliser/Projects/mcp-automem/dist/index.js
🔴 BLOCKED - Cannot use AutoMem through CodeMode until auth issue resolved