Rust Analyzer MCP server

Integrates with rust-analyzer via LSP to provide intelligent Rust code analysis, generation, refactoring, and project management through 19 specialized tools including symbol navigation, diagnostics, automated refactoring, struct/enum generation, test creation, and type hierarchy analysis.
Back to servers
Setup instructions
Provider
Dex
Release date
Jul 13, 2025
Language
Python
Stats
17 stars

Rust MCP Server is a comprehensive tool that bridges AI assistants with rust-analyzer, enabling intelligent code analysis and generation through the Model Context Protocol (MCP). This integration allows AI tools like Claude to work with Rust code more effectively using natural language commands.

Prerequisites

  • Rust toolchain (1.70+)
  • rust-analyzer installed (defaults to ~/.cargo/bin/rust-analyzer)
  • An MCP-compatible client (Claude, Roo, etc.)

Installation

  1. Clone the repository and build the server:
git clone https://github.com/dexwritescode/rust-mcp.git
cd rust-mcp
cargo build --release
  1. The server binary will be available at target/release/rustmcp

Configuration

Environment Variables

The server supports the following environment variable:

  • RUST_ANALYZER_PATH - Path to rust-analyzer binary (default: ~/.cargo/bin/rust-analyzer)

Claude Desktop Configuration

Add to your Claude Desktop MCP configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "rust-analyzer": {
      "command": "/path/to/rust-mcp/target/release/rustmcp",
      "args": [],
      "env": {
        "RUST_ANALYZER_PATH": "/custom/path/to/rust-analyzer"
      }
    }
  }
}

For default rust-analyzer location, you can omit the env section.

Roo Configuration

Add to your Roo configuration file (typically ~/.roo/config.json):

{
  "mcp_servers": [
    {
      "name": "rust-analyzer",
      "command": "/path/to/rust-mcp/target/release/rustmcp",
      "args": [],
      "env": {
        "RUST_ANALYZER_PATH": "/custom/path/to/rust-analyzer"
      }
    }
  ]
}

Other MCP Clients

For any MCP-compatible client, configure it to run:

/path/to/rust-mcp/target/release/rustmcp

Available Tools

Code Analysis

  • find_definition - Navigate to symbol definitions
  • find_references - Find all symbol uses
  • get_diagnostics - Get compiler errors/warnings with fixes
  • workspace_symbols - Search project symbols

Code Generation

  • generate_struct - Create structs with derives and constructors
  • generate_enum - Create enums with variants
  • generate_trait_impl - Generate trait implementations with stubs
  • generate_tests - Create unit or integration test templates

Refactoring

  • rename_symbol - Rename with scope awareness
  • extract_function - Extract code into functions
  • inline_function - Inline function calls
  • organize_imports - Sort and organize use statements
  • format_code - Apply rustfmt formatting

Quality Assurance

  • apply_clippy_suggestions - Apply clippy automatic fixes
  • validate_lifetimes - Check lifetime and borrow checker issues

Project Management

  • analyze_manifest - Parse and analyze Cargo.toml
  • run_cargo_check - Execute cargo check with error parsing

Advanced Features

  • get_type_hierarchy - Get type relationships for symbols
  • suggest_dependencies - Recommend crates based on code patterns
  • create_module - Create new Rust modules with visibility control
  • move_items - Move code items between files
  • change_signature - Modify function signatures safely

Usage Examples

Once configured, you can use the tools through your AI assistant with natural language prompts:

Code Analysis Examples

"Find all references to the `Config` struct in this Rust project"
"Show me the definition of the `parse_args` function"
"Check for compiler errors in src/main.rs"
"Search for all symbols matching 'user' in the workspace"

Code Generation Examples

"Generate a struct called `User` with fields: name (String), age (u32), email (String), with Debug and Clone derives"
"Create an enum called `HttpStatus` with variants: Ok, NotFound, ServerError"
"Generate unit tests for the `calculate_total` function"
"Generate a Display trait implementation for the User struct"

Refactoring Examples

"Rename the variable `data` to `user_input` throughout the codebase"
"Extract this code block into a separate function called `validate_input`"
"Inline the `helper_function` call on line 42"
"Organize all import statements in src/lib.rs"
"Format all the code in src/lib.rs"

Troubleshooting

rust-analyzer Not Found

Ensure rust-analyzer is installed and accessible. The server will look for rust-analyzer in:

  1. The path specified by the RUST_ANALYZER_PATH environment variable
  2. Default location: ~/.cargo/bin/rust-analyzer

To use a custom path, set the environment variable:

export RUST_ANALYZER_PATH=/custom/path/to/rust-analyzer

MCP Connection Issues

  • Verify the server binary path in your MCP client configuration
  • Check that the binary has execute permissions: chmod +x target/release/rustmcp
  • Ensure no other processes are using the same MCP server name

LSP Communication Errors

  • Verify rust-analyzer works independently: rust-analyzer --version
  • Check that your Rust project has a valid Cargo.toml
  • Ensure the workspace path is correct when calling tools

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "rust-analyzer" '{"command":"/path/to/rust-mcp/target/release/rustmcp","args":[]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "rust-analyzer": {
            "command": "/path/to/rust-mcp/target/release/rustmcp",
            "args": []
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "rust-analyzer": {
            "command": "/path/to/rust-mcp/target/release/rustmcp",
            "args": []
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later