- Home
- MCP servers
- Rust
Rust
- rust
22
GitHub Stars
rust
Language
6 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
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.
How to use
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.
How to install
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/rustmcp
Configuration and environment
Configure 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"
}
}
}
}
Usage examples with your assistant
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.
Notes on troubleshooting
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.
Security and maintenance tips
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.
Troubleshooting
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.
Development
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.
Available tools
find_definition
Navigate to symbol definitions within the workspace.
find_references
Find all usages of a symbol across the project.
get_diagnostics
Return compiler errors and warnings with suggested fixes.
workspace_symbols
Search for symbols across the workspace.
generate_struct
Create a new struct with optional derives and constructors.
generate_enum
Create an enum with specified variants.
generate_trait_impl
Generate a trait implementation with stubs.
generate_tests
Create unit or integration test templates.
rename_symbol
Rename a symbol with scope awareness.
extract_function
Extract a code block into a separate function.
inline_function
Inline a function call at the chosen location.
organize_imports
Sort and organize use/import statements.
format_code
Apply rustfmt formatting across selected code.
apply_clippy_suggestions
Apply automatic fixes suggested by Clippy.
validate_lifetimes
Check lifetime and borrow checker issues.
analyze_manifest
Parse and analyze Cargo.toml for dependencies and features.
run_cargo_check
Execute cargo check and report compilation issues.
get_type_hierarchy
Show type relationships for a symbol.
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.