Provides rust-analyzer integration for MCP clients to analyze and transform Rust code.
Configuration
View docs{
"mcpServers": {
"dexwritescode-rust-mcp": {
"url": "https://example-mcp-server.local/mcp",
"headers": {
"RUST_ANALYZER_PATH": "/custom/path/to/rust-analyzer"
}
}
}
}You can run a local MCP server that integrates rust-analyzer capabilities with your Rust projects, enabling AI assistants to analyze, refactor, and generate code through a stable protocol. This server accepts commands from an MCP client and performs advanced Rust analysis and transformations without manual string handling, improving accuracy and speed.
You connect to the local MCP server via an MCP client that communicates over stdio. Start the server, then load your Rust workspace in your editor or AI assistant. You can ask the assistant to find definitions, generate code, refactor, format, run clippy suggestions, verify lifetimes, and manage Cargo manifests. The server exposes a comprehensive set of tools that work together with rust-analyzer to provide intelligent code insights and automated changes.
Prerequisites you need before installing include the Rust toolchain (Rust 1.70+), rust-analyzer installed (defaults to ~/.cargo/bin/rust-analyzer), and an MCP-compatible client you plan to use.
Step-by-step commands to set up and run the server locally are as follows.
# Prerequisites
# Install Rust toolchain if you don\'t have it
# Follow standard Rust installation instructions for your OS
# Build the MCP server from source
cargo build --release
# Run the MCP server (stdio transport)
./target/release/rustmcpConfigure your MCP client to start the local server using the binary produced by the build. The server runs in stdio mode and should be launched with the appropriate environment variables if you customize rust-analyzer path.
{
"mcpServers": {
"rust_analyzer": {
"command": "/path/to/rust-mcp/target/release/rustmcp",
"args": [],
"env": {
"RUST_ANALYZER_PATH": "/custom/path/to/rust-analyzer"
}
}
}
}With the server running, you can ask for code insights and transformations like generating a Rust struct with derives, finding a symbol definition, or organizing imports across your workspace. The tools are designed to be used together through your MCP client to keep your Rust projects consistent and idiomatic.
If you encounter issues, ensure rust-analyzer is accessible at the path you configured and that Cargo manifests are valid for your workspace. Verify that the MCP server binary has execute permissions and that you started the server in the correct working directory for your project.
Keep rust-analyzer up to date and monitor the interplay between rust-analyzer and the MCP server to avoid version mismatches. Regularly rebuild the server when you update its dependencies and test critical code-generation and refactoring flows on representative projects to prevent regressions.
Rust-analyzer Not Found: Ensure rust-analyzer is installed and accessible at the path specified by RUST_ANALYZER_PATH or the default location. MCP Connection Issues: Confirm the server binary path, ensure it is executable, and verify no conflicting processes are using the same MCP server name. LSP Communication Errors: Verify rust-analyzer works independently and that your workspace includes a valid Cargo.toml.
To run and test locally during development, use the provided cargo run flow and test individual tools by interacting with the MCP protocol through the standard input and output streams. You can add new tools by implementing them in the designated modules and wiring them into the dispatcher to expose additional capabilities to your clients.
Navigate to symbol definitions within the workspace.
Find all usages of a symbol across the project.
Return compiler errors and warnings with suggested fixes.
Search for symbols across the workspace.
Create a new struct with optional derives and constructors.
Create an enum with specified variants.
Generate a trait implementation with stubs.
Create unit or integration test templates.
Rename a symbol with scope awareness.
Extract a code block into a separate function.
Inline a function call at the chosen location.
Sort and organize use/import statements.
Apply rustfmt formatting across selected code.
Apply automatic fixes suggested by Clippy.
Check lifetime and borrow checker issues.
Parse and analyze Cargo.toml for dependencies and features.
Execute cargo check and report compilation issues.
Show type relationships for a symbol.
Recommend crates based on code patterns.
Create new Rust modules with visibility control.
Move code items between files.
Modify function signatures safely.