Skip to content

search_code always returns 0 results — rg invoked without explicit path #250

@hemil-bhavsar-ubs

Description

@hemil-bhavsar-ubs

Bug: search_code always returns 0 results — rg invoked without explicit path

Repository: DeusData/codebase-memory-mcp
Version: v0.6.0 (April 6, 2026)
Platform: Windows 11 (reproduced; likely platform-agnostic)


Summary

mcp__codebase-memory-mcp__search_code always returns { total: 0, results: [] } regardless of the pattern or project, even on a fully indexed repository with 2,862 nodes.

Steps to Reproduce

  1. Index a repository with index_repository (full mode, confirmed 2,862 nodes / 6,678 edges)
  2. Call search_code with any pattern — e.g. search_code(project="...", pattern="submitRecords")
  3. Observe: returns { total: 0, results: [], raw_match_count: 0 }
  4. Confirm the pattern exists in the repo by running rg "submitRecords" directly in the repo root — matches found immediately

Root Cause

The binary invokes rg (ripgrep) without passing an explicit file path or directory argument. When rg is spawned as a child process without a path and its stdin is not a terminal (i.e. it is piped/spawned programmatically), it attempts to read from stdin rather than scanning the filesystem. Since stdin is empty in this context, rg exits with no matches.

The fix is straightforward: pass the repository root path explicitly as the final argument when invoking rg inside search_code.

Incorrect invocation (current):

rg --json --no-heading <pattern>

Correct invocation:

rg --json --no-heading <pattern> <repo_root_path>

Workaround

As a workaround we replicated the intended behavior in a local Node.js script that reads the SQLite DB directly and passes the repo root path explicitly to rg:

const rgArgs = ['--json', '--no-heading', pattern, repoRoot];
spawnSync('rg', rgArgs, { encoding: 'utf8' });

This produces the expected results — matching lines enriched with their containing function from the graph.

Impact

search_code is completely non-functional in any environment where the MCP server is spawned programmatically (i.e. all normal Claude Code / MCP client usage). The tool appears in documentation and is referenced in agent prompts but silently returns empty results for every query, making it a silent failure with no error surfaced to the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edges

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions