Skip to content

fix: codedb mcp stuck in loading_snapshot with files=0 when launched from unexpected cwd #502

@idea404

Description

@idea404

Problem

When codedb mcp is launched by an MCP client (opencode, Claude Code, etc.) from an unexpected cwd, or when the client does not provide usable roots, the server enters scan=loading_snapshot with files=0 and never recovers.

This produces a connected but functionally empty MCP server.

Observed behavior

cd /Users/dennis/Projects/personal
codedb snapshot        # snapshot has 17 files
codedb mcp             # files=0 scan=loading_snapshot (stuck)
codedb mcp --help      # starts MCP server instead of showing help
codedb mcp --snapshot  # silently ignored, starts server

The only workaround is wrapping the command in sh -lc "cd /path && exec codedb mcp".

Root causes

  1. Argument parsing: codedb mcp --help starts the server instead of printing help. Unknown flags like --snapshot are silently ignored.
  2. Root resolution: When root == "." and no CODEDB_ROOT is set, the server enters deferred mode and waits for MCP roots. If the client never sends roots (or sends empty roots), the 3s fallback fires — but if cwd is not indexable (e.g. /), the scan never triggers and loading_snapshot persists forever.
  3. No git root detection: Running codedb mcp from a subdirectory of a git repo does not discover the repo root.
  4. Roots handshake errors: If roots/list returns an error, missing result, or malformed roots, the deferred scan is never triggered.

Expected behavior

  1. codedb mcp --help should print help and exit
  2. codedb mcp [path] should honor the documented path argument
  3. Unknown flags should be rejected with a clear error
  4. Git root should be auto-detected from cwd
  5. Scan state should never remain stuck in loading_snapshot indefinitely
  6. MCP stdout must contain only JSON-RPC messages

Related (already closed)

These were partially addressed but the combined scenario (MCP client + unexpected cwd + no roots) still fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions