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.
An MCP server for Rust Language Server (rust-analyzer)
ดาว
36
เครื่องมือ
—
อัปไทม์
—
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 definitions
find_references - Find all symbol uses
get_diagnostics - Get compiler errors/warnings with fixes
workspace_symbols - Search project symbols
Code Generation (4 tools)
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 (5 tools)
rename_symbol - Rename with scope awareness
extract_function - Extract code into functions
inline_function - Inline function calls
organize_imports - Sort and organize use statements
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 initialization
src/lib.rs - Module declarations
src/server/ - MCP server implementation
handler.rs - Tool handlers and MCP server logic using rmcp crate
parameters.rs - Parameter type definitions for all tools