Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcp-rust-analyzer

MCP server exposing rust-analyzer as tools for Claude Code — semantic code navigation without grepping. Saves time and tokens.

Tools

Tool What it does
symbols Search for symbols by name across the workspace
hover Get type information and docs at a file position
definition Jump to where a symbol is defined
references Find all references to a symbol
implementations Find all trait/method implementations
symbol_references Find a symbol by name + get all references (one call)
document_symbols List all symbols in a file (structural overview)

Prerequisites

Install rust-analyzer:

# Via rustup (recommended)
rustup component add rust-analyzer

# Via Homebrew (macOS)
brew install rust-analyzer

Setup

1. Install the package

git clone https://github.com/riccajason/mcp-rust-analyzer.git
cd mcp-rust-analyzer

python3 -m venv .venv
.venv/bin/pip install -e .

2. Configure Claude Code

Add to your project's .mcp.json:

{
  "mcpServers": {
    "rust-analyzer": {
      "command": "/path/to/mcp-rust-analyzer/.venv/bin/python3",
      "args": ["-m", "mcp_rust_analyzer"],
      "env": {
        "WORKSPACE_ROOT": "/path/to/your/rust/project"
      }
    }
  }
}

3. Restart Claude Code

The MCP server starts when Claude Code connects. First connection takes ~20 seconds while rust-analyzer indexes the workspace. Subsequent tool calls are instant.

Configuration

Environment variables

Variable Default Description
WORKSPACE_ROOT Current directory Path to the Rust project root
RUST_ANALYZER_PATH rust-analyzer Path to the rust-analyzer binary

VS Code settings

The server automatically reads .vscode/settings.json in your workspace and forwards any rust-analyzer.* settings. Projects with custom targets (embedded, no_std, cross-compilation) work without extra configuration:

{
  "rust-analyzer.cargo.target": "x86_64-unknown-none",
  "rust-analyzer.check.allTargets": false
}

How it works

Claude Code  ──MCP/stdio──>  mcp-rust-analyzer  ──LSP/JSON-RPC──>  rust-analyzer

The server spawns rust-analyzer as a subprocess, speaks the Language Server Protocol over its stdio, and translates MCP tool calls into LSP requests. rust-analyzer stays warm between calls — no re-indexing per query.

File changes are tracked via mtime. When a file is modified between tool calls, the server pushes the update to rust-analyzer automatically.

License

MIT

About

MCP server exposing rust-analyzer as tools for Claude Code - semantic code navigation without grepping - saves time and tokens!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages