Install
$ agentstack add mcp-dexwritescode-rust-mcp ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
[](https://github.com/dexwritescode/rust-mcp/actions/workflows/ci.yml)
Rust MCP Server
A comprehensive Model Context Protocol (MCP) server that provides rust-analyzer integration for LLM-assisted Rust development. This server enables AI tools like Claude to work with Rust code idiomatically through rust-analyzer's Language Server Protocol capabilities, avoiding string manipulation and providing intelligent code analysis and refactoring.
Quick Start
- Build:
cargo build --release - Configure your MCP client to use
target/release/rustmcp - Use through AI assistants with natural language prompts like "Generate a User struct with Debug and Clone derives"
Features - Complete Tool Suite (19 Tools)
Code Analysis (4 tools)
find_definition- Navigate to symbol definitionsfind_references- Find all symbol usesget_diagnostics- Get compiler errors/warnings with fixesworkspace_symbols- Search project symbols
Code Generation (4 tools)
generate_struct- Create structs with derives and constructorsgenerate_enum- Create enums with variantsgenerate_trait_impl- Generate trait implementations with stubsgenerate_tests- Create unit or integration test templates
Refactoring (5 tools)
rename_symbol- Rename with scope awarenessextract_function- Extract code into functionsinline_function- Inline function callsorganize_imports- Sort and organize use statementsformat_code- Apply rustfmt formatting
Quality Assurance (2 tools)
apply_clippy_suggestions- Apply clippy automatic fixesvalidate_lifetimes- Check lifetime and borrow checker issues
Project Management (2 tools)
analyze_manifest- Parse and analyze Cargo.tomlrun_cargo_check- Execute cargo check with error parsing
Advanced Features (4 tools)
get_type_hierarchy- Get type relationships for symbolssuggest_dependencies- Recommend crates based on code patternscreate_module- Create new Rust modules with visibility controlmove_items- Move code items between files
Additional Advanced Tools
change_signature- Modify function signatures safely
Prerequisites
- Rust toolchain (1.70+)
- rust-analyzer installed (defaults to
~/.cargo/bin/rust-analyzer) - An MCP-compatible client (Claude, Roo, etc.)
Installation
- Clone this repository:
git clone
cd rust-mcp
- Build the server:
cargo build --release
- The server binary will be available at
target/release/rustmcp
Configuration
Environment Variables
The server supports the following environment variables:
RUST_ANALYZER_PATH- Path to rust-analyzer binary (default:~/.cargo/bin/rust-analyzer)
You can set this when running the server:
RUST_ANALYZER_PATH=/usr/local/bin/rust-analyzer ./target/release/rustmcp
Or set it in your MCP client configuration (see examples below).
Claude Desktop
Add the following 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"
}
}
}
}
If rust-analyzer is in the default location (~/.cargo/bin/rust-analyzer), you can omit the env section:
{
"mcpServers": {
"rust-analyzer": {
"command": "/path/to/rust-mcp/target/release/rustmcp",
"args": []
}
}
}
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"
}
}
]
}
For default rust-analyzer location, you can use an empty env object:
{
"mcp_servers": [
{
"name": "rust-analyzer",
"command": "/path/to/rust-mcp/target/release/rustmcp",
"args": [],
"env": {}
}
]
}
Other MCP Clients
For any MCP-compatible client, configure it to run:
/path/to/rust-mcp/target/release/rustmcp
The server uses stdio transport and will be ready to accept MCP protocol messages.
Usage Examples
Once configured, you can use the tools through your AI assistant. Here are some example prompts:
Code Analysis
"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
"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
"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"
Quality Assurance
"Run clippy and apply all automatic fixes to improve code quality"
"Check for any lifetime or borrow checker issues in src/auth.rs"
Project Management
"Analyze the Cargo.toml file and show dependency information"
"Run cargo check and report any compilation errors"
Advanced Features
"Show me the type hierarchy for the symbol at line 15, character 8 in src/main.rs"
"Suggest crate dependencies for HTTP client functionality in this workspace"
"Create a new public module called 'auth' in src/auth.rs"
"Move the User struct and validate_user function from src/main.rs to src/user.rs"
"Change the signature of the process_data function to accept a reference instead of ownership"
Architecture
The server is built with a modular architecture:
src/main.rs- Entry point and server initializationsrc/lib.rs- Module declarationssrc/server/- MCP server implementationhandler.rs- Tool handlers and MCP server logic using rmcp crateparameters.rs- Parameter type definitions for all toolssrc/analyzer/- rust-analyzer LSP client integrationclient.rs- LSP client implementation and protocol handlingsrc/tools/- Modular tool implementationstypes.rs- Tool dispatcher and definitionsanalysis.rs- Code analysis tools (finddefinition, findreferences, etc.)generation.rs- Code generation tools (generatestruct, generateenum, etc.)refactoring.rs- Refactoring tools (renamesymbol, extractfunction, etc.)formatting.rs- Code formatting toolsquality.rs- Quality assurance tools (clippy, lifetimes)cargo.rs- Project management toolsnavigation.rs- Navigation tools (workspace_symbols)advanced.rs- Advanced features (type hierarchy, dependencies, modules)
Development
Running in Development
cargo run
Testing Individual Tools
The server exposes all tools through the MCP protocol. For debugging, you can:
- Run the server:
cargo run - Send MCP messages via stdin (JSON-RPC format)
- Check server logs and responses
Adding New Tools
- Create the tool implementation function in the appropriate
src/tools/*.rsfile - Add parameter struct to
src/server/parameters.rs - Add the tool to the
execute_toolmatch statement insrc/tools/types.rs - Add tool definition to
get_tools()function insrc/tools/types.rs - Add the corresponding
#[tool]method toRustMcpServerinsrc/server/handler.rs - Add analyzer client method to
src/analyzer/client.rsif needed
Troubleshooting
rust-analyzer Not Found
Ensure rust-analyzer is installed and accessible. The server will look for rust-analyzer in the following order:
- The path specified by the
RUST_ANALYZER_PATHenvironment variable - Default location:
~/.cargo/bin/rust-analyzer
To use a custom path, set the environment variable:
export RUST_ANALYZER_PATH=/custom/path/to/rust-analyzer
Or configure it in your MCP client configuration (see Configuration section above).
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
Contributing
- Fork the repository
- Create a feature branch
- Implement your changes with tests
- Submit a pull request
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: dexwritescode
- Source: dexwritescode/rust-mcp
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.