Command Line Interface (CLI)
Relevant source files
The following files were used as context for generating this wiki page:
The Command Line Interface (CLI) for MCB (Memory Context Browser) serves as the primary entry point for users and agents to interact with the high-performance MCP server. It provides tools for semantic code search, architecture validation, and server management. The CLI is designed to facilitate persistent memory and deep codebase understanding through a standardized protocol, allowing for seamless integration with MCP-compatible clients like Claude Desktop.
Sources: README.md:1-15, AGENTS.md:144-150
CLI Architecture and Command Structure
The CLI is built using clap for argument parsing and follows a modular structure where commands are routed to specific handlers within the workspace crates. The entry point resides in the mcb crate, which acts as a facade binary for the underlying infrastructure and domain logic.
Command Execution Flow
The following diagram illustrates how the CLI processes a user request from the initial command input to the execution of domain logic.
The CLI routes specific subcommands to specialized engines, such as mcb-validate for architecture rules or mcb-server for protocol handling.
Sources: README.md:88-100, AGENTS.md:214-230, crates/mcb-infrastructure/Cargo.toml:39
Subcommand Families
The CLI interface exposes public tools grouped into operation families. These are accessible either through direct CLI subcommands or through the MCP protocol native interface.
| Family | CLI Subcommand / Tool | Description |
|---|---|---|
| Server | serve | Starts the MCP server with --stdio or HTTP transport. |
| Validation | validate | Runs architecture rule enforcement and code analysis. |
| Search | search_code | Natural language queries over indexed codebases. |
| Index | index_repo | Triggers repository-level indexing and vector embeddings. |
| Development | check, fix | Utilities for formatting, linting, and quality gates. |
Sources: README.md:58-75, AGENTS.md:162-175
Primary CLI Commands
The Serve Command
The serve command is the core operational mode for integration with AI agents. It initializes the multi-provider architecture, setting up connections to embedding providers (e.g., OpenAI, Ollama) and vector stores (e.g., Qdrant, Milvus).
- Flags:
--stdiois commonly used for direct piping to MCP clients. - Integration: Primarily used by adding the
mcbcommand andservearguments to client configurations likeclaude_desktop_config.json.
Sources: README.md:46-55, AGENTS.md:157-160
The Validate Command
The validate command interfaces with the mcb-validate crate. It performs static analysis against predefined architecture rules (e.g., Clean Architecture enforcement) and code quality metrics like the Maintainability Index.
- Logic: The CLI utilizes a
YamlRuleExecutorto route linting codes (from Ruff or Clippy) and metrics analysis (via Tree-sitter) to the validation engine. - Source Citations: Implementation details for these validation routines are found in the
mcb-validatetests and utility modules.
Sources: AGENTS.md:214-220, crates/mcb-validate/tests/utils/mod.rs:18-35
This sequence shows the interaction between the CLI and the internal validation engine during an architecture check.
Sources: crates/mcb-validate/tests/utils/mod.rs:18-30, AGENTS.md:214-225
Development and Operational Commands
Operations are managed through a Makefile that abstracts complex CLI calls into canonical verbs. These commands are backed by a monopoly script (scripts/lib/mcb.sh) to ensure consistent execution across different environments.
Canonical Development Verbs
make build: Compiles the binary, typically in release mode for production use.make test: Runs unit, integration, and E2E tests across workspace crates.make check: A compound gate performing formatting, linting, and architecture validation.make setup: Installs pre-commit hooks and external tools (e.g.,adr).
Sources: README.md:118-125, AGENTS.md:162-175
Implementation Details in Fixtures
As seen in the rustlings fixture included in the codebase, CLI tools often involve state management through files like info.toml and Cargo.toml. The new command in that context demonstrates directory creation and git initialization logic integrated directly into the CLI workflow.
Sources: crates/mcb-validate/tests/fixtures/rustlings/src/dev/new.rs:32-50, crates/mcb-validate/tests/fixtures/rustlings/src/main.rs:33-55
Summary
The MCB CLI is a comprehensive toolset providing a high-performance interface for codebase interaction. It bridges the gap between raw source code and AI agents by exposing complex operations—such as semantic search, AST-aware analysis, and Clean Architecture validation—through a standardized, command-driven interface. Its structure ensures that developers can maintain codebase health via validation commands while simultaneously providing agents with the context they need via the serve command.