Tilde Expansion Fails In Mcp Paths

Claude Code v2.1.7 · 1m 15s · Memory Service (C)

TL;DR - Session insights

  • Tilde expansion doesn’t work in MCP configurations: The ~ in paths like ~/grid/memory-service/scripts/memory-mcp fails silently because MCP spawns processes without shell expansion - must use absolute paths
  • Diagnostic debugging was methodical: AI checked script existence, service health endpoint (HTTP 200), and manual script execution before identifying the root cause - a good pattern for MCP connection troubleshooting
  • The script worked perfectly when run directly: MEMORY_SERVICE_HOST=localhost:8080 ./grid/memory-service/scripts/memory-mcp succeeded, proving the issue was purely path expansion in the config file

Session Log

  • USER: Caveat: The messages below were generated by the user while running local commands. DO NOT respond to these messages or otherwise consider them in your response unless the user explicitly asks you to.

  • USER: /mcp mcp

  • USER: Failed to reconnect to memory.

  • USER: MCP config at ~/.claude.json is failing. You are unable to connect to that MCP

  • AI: Let me check your MCP configuration to help diagnose the issue.

  • TOOL-CALL: Read {"file_path":"~/.claude.json"}

  • TOOL:

         1→{
         2→  "numStartups": 10,
         3→  "tipsHistory": {
         4→    "new-user-warmup": 8,
         5→    "plan-mode-for-complex-tasks": 8,
         6→    "terminal-setup": 7,
         7→    "memory-command": 7,
         8→    "theme-command": 7,
         9→    "status-line": 8,
        10→    "stickers-command": 8,
        11→    "prompt-queue": 8,
        12→    "enter-to-steer-in-relatime": 8,
        13→    "todo-list": 8,
        14→    "ide-upsell-external-terminal": 8,
        15→    "install-github-app": 8,
        16→    "install-slack-app": 8,
        17→    "drag-and-drop-images": 8,
        18→    "paste-images-mac": 8,
        19→    "double-esc-code-restore": 8,
        20→    "continue": 8,
        21→    "shift-tab": 8,
        22→    "image-paste": 8,
        23→    "ultrathink-keyword": 8,
        24→    "custom-agents": 8,
        25→    "desktop-app": 8,
        26→    "web-app": 8,
        27→    "mobile-app": 8,
        28→    "guest-passes": 8
        29→  },
        30→  "cachedStatsigGates": {
    [...227 more lines...]
    
  • AI: I can see your MCP configuration. The memory server is configured to use:

    • Command: ./grid/memory-service/scripts/memory-mcp
    • Environment: MEMORY_SERVICE_HOST=localhost:8080

    Let me check if the script exists and if the memory service is running.

  • TOOL-CALL: Bash {"command":"ls -la ./grid/memory-service/scripts/memory-mcp 2>&1","description":"Check if memory-mcp script exists"}

  • TOOL-CALL: Bash {"command":"curl -s -o /dev/null -w \"%{http_code}\" http://localhost:8080/health 2>&1 || echo \"Connection failed\"","description":"Check if memory service is running"}

  • TOOL: -rwxr-xr-x@ 1 user staff 10708 Jan 13 22:18 ./grid/memory-service/scripts/memory-mcp

  • TOOL: 200

  • AI: The script exists and is executable, and the memory service is responding (HTTP 200). The issue might be the ~ expansion. Let me test if the script runs correctly.

  • TOOL-CALL: Bash {"command":"MEMORY_SERVICE_HOST=localhost:8080 ./grid/memory-service/scripts/memory-mcp 2>&1 | head -20","description":"Test memory-mcp script execution"}

  • TOOL:

    [memory-mcp] Started (endpoint: http://localhost:8080/rpc)
    [memory-mcp] Shutdown
    
  • AI: The script works when run directly. The issue is that the ~ tilde in the command path doesn’t expand properly in MCP configurations (no shell expansion happens).

    Fix: Replace ~ with the full absolute path in your ~/.claude.json:

    "memory": {
      "command": "./grid/memory-service/scripts/memory-mcp",
      "env": {
        "MEMORY_SERVICE_HOST": "localhost:8080"
      }
    }
    

    Would you like me to make this change for you?