Skip to content

Replace global MCP_MODE with struct-based config propagation #28

@momokun7

Description

@momokun7

Source: Code quality review 2026-03-31 (Score: 52/100)
Category: Rust Code Quality (10/20)
Priority: 4/5

Problem

// mcp.rs:8
static MCP_MODE: AtomicBool = AtomicBool::new(false);

is_mcp_mode() is referenced across search.rs, lib.rs, candidates.rs, and mcp_tools.rs to suppress stderr output. Global mutable state hurts testability and blocks future multi-instance support (searching multiple repos in one process).

Proposed Solution

Add a config field to Xgrep struct:

pub struct Xgrep {
    root: PathBuf,
    index_path: PathBuf,
    config: Config,
}

pub struct Config {
    pub quiet: bool,  // suppresses stderr warnings
}

Replace all is_mcp_mode() calls with self.config.quiet checks. MCP server sets quiet: true when constructing Xgrep.

Why Now

Small refactor now prevents entrenching the global state pattern as more features are added.

Estimated effort: 1-2 hours

Metadata

Metadata

Assignees

Labels

area/mcpMCP server, tool definitionstype/refactorCode improvement without behavior change

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions