# scan_crate

Fast regex search through Rust crate source code. Supports crates.io, GitHub repos, and local paths.

## Features

*   **Multiple sources:** Automatically detects and fetches from:
    *   crates.io registry
    *   GitHub/git repositories  
    *   Local directories
    *   Workspace dependencies (via `cargo metadata`)
*   **Smart caching:** Uses existing Cargo cache when available, maintains its own cache for other sources
*   **Regex search:** Powered by `ripgrep` for fast pattern matching
*   **MCP server:** Integrates with AI assistants via Model Context Protocol
*   **CLI tool:** Direct command-line usage

## Installation

### From crates.io (Recommended)

```bash
cargo install scan_crate

# Requires ripgrep
# macOS: brew install ripgrep
# Linux: apt-get install ripgrep
```

### From source

```bash
git clone https://github.com/verse-pbc/scan_crate.git
cd scan_crate
cargo build --release
```

## Claude Code Plugin

scan_crate includes a Claude Code plugin that enables automatic crate exploration when you ask questions about Rust libraries.

### Plugin Installation

**Important:** You must install the binary first, then the plugin.

**Step 1: Install the binary**

Since this is a pre-release version, you need to specify the version:

```bash
cargo install scan_crate --version 0.1.0-alpha.2
```

Or install from source:

```bash
cargo install --git https://github.com/verse-pbc/scan_crate.git
```

**Step 2: Install the plugin in Claude Code**

```bash
/plugin install https://github.com/verse-pbc/scan_crate.git
```

**Step 3: Restart Claude Code**

The plugin will automatically check if `scan_crate` is installed and show a helpful message if it's missing.

### What the Plugin Does

Once installed, Claude will automatically use scan_crate when you:

- Ask about Rust libraries: "How does serde work?"
- Analyze dependencies: "What's in our Cargo.toml?"
- Discover APIs: "Show me tokio's Runtime API"
- Search for implementations: "Find examples of Serialize trait"

The plugin includes the **rust-crate-explorer** skill that teaches Claude when to proactively scan crates, so you don't need to manually request searches.

### Manual MCP Configuration

If not using the plugin, you can configure the MCP server directly in `~/.claude.json`:

```json
{
  "mcpServers": {
    "scan-crate": {
      "command": "scan_crate",
      "args": ["--mcp"]
    }
  }
}
```

## Usage

### CLI Examples

```bash
# Search crates.io package
scan_crate --crate-spec "serde@1.0.130" --query "Serialize"

# Search GitHub repository
scan_crate --crate-spec "https://github.com/rust-lang/cargo.git@0.70.0" --query "cargo_metadata"

# Search local directory
scan_crate --crate-spec "./" --query "TODO"

# Case-sensitive search
scan_crate --crate-spec "tokio" --query "Runtime" --case-sensitive
```

### MCP Server for Other Editors

For MCP clients other than Claude Code (e.g., Cursor), configure in your editor's MCP settings:

```json
{
    "mcpServers": {
        "scan-crate": {
            "command": "scan_crate",
            "args": ["--mcp"]
        }
    }
}
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.