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.
~/.cargo/bin/rust-analyzer
)git clone https://github.com/dexwritescode/rust-mcp.git
cd rust-mcp
cargo build --release
target/release/rustmcp
The server supports the following environment variable:
RUST_ANALYZER_PATH
- Path to rust-analyzer binary (default: ~/.cargo/bin/rust-analyzer
)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.
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"
}
}
]
}
For any MCP-compatible client, configure it to run:
/path/to/rust-mcp/target/release/rustmcp
Once configured, you can use the tools through your AI assistant with natural language prompts:
"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"
"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"
"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"
Ensure rust-analyzer is installed and accessible. The server will look for rust-analyzer in:
RUST_ANALYZER_PATH
environment variable~/.cargo/bin/rust-analyzer
To use a custom path, set the environment variable:
export RUST_ANALYZER_PATH=/custom/path/to/rust-analyzer
chmod +x target/release/rustmcp
rust-analyzer --version
Cargo.toml
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.
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.
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": []
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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