Content
# Rust-Analyz-MCP
A lightweight bridge server designed to make Rust-Analyzer available via Model Context Protocol (MCP), specializing in autonomous development of AI agents.
Designed and developed by ADASIM.
AI agents can directly grasp Rust's type system, documentation, and compilation errors, accelerating development.
## For AI Agents
Prompts for agents (AI) to use this tool efficiently (token-efficient) are available in [SKILL.md](./SKILL.md).
**Please read this file before starting development.**
## Features
- **Agent Autonomous Optimization**: Outputs are summarized to the extreme to allow AI to perform symbol exploration, project diagnosis, and reference resolution with minimal tokens.
- **Smart Rooting**: Automatically detects the appropriate `Cargo.toml` from the target file and operates without setting in multi-project environments.
- **No Environment Variables Required**: Prioritizing communication stability, all debug logs are isolated to `stderr`. `stdout` guarantees pure JSON communication.
## Provided Tools (6 types)
### 1. `get_workspace_diagnostics` (Recommended)
Gets compilation errors and warnings for the entire workspace, summarizes and returns important ones. Ideal for "status reporting" to AI.
### 2. `get_diagnostics`
Gets diagnostic information related to the currently open file.
### 3. `get_symbols`
Gets a list of definitions such as structs, functions, and enums in a specified file. Helps grasp the overall picture of the code.
### 4. `hover`
Gets type information and documentation for a symbol at a specific position.
### 5. `get_definition`
Identifies the definition source (file name, line, column) of a symbol.
### 6. `get_references`
Gets a list of where a specific symbol is used in the project.
## Setup
### 0. Prerequisites
- **Rust Build Toolchain** ([install with rustup](https://rustup.rs/))
- **`rust-analyzer` component itself** (required as a parsing engine):
```powershell
rustup component add rust-analyzer
```
### 1. Installation (One-time Installation)
Can be remotely installed, built, and placed with a single command from GitHub.
```powershell
cargo install --git https://github.com/adasima/rust-analyz-mcp --force
```
*(The above command will automatically place `rust-analyz-mcp.exe` in `$HOME/.cargo/bin/`)*
### 2. Agent Configuration
Adding the following to the agent's configuration file (e.g., `mcp_config.json`) will make it work:
```json
"mcpServers": {
"rust-analyz-mcp": {
"command": "rust-analyz-mcp"
}
}
```
### 3. Fully Automated Installation and Configuration (All Tools at Once)
To install all tools at once and configure them automatically, run the following one-liner:
```powershell
Invoke-RestMethod "https://raw.githubusercontent.com/adasima/ai-workshop/main/mcp_installer.ps1" | Invoke-Expression
```