mcp-rust-analyzer
mcp-rust-analyzer is a powerful code analysis tool for the Rust programming language. It provides real-time error checking and code completion features, helping developers improve code quality. This makes Rust development more efficient and enjoyable.
GitHub Stars
3
User Rating
Not Rated
Favorites
0
Views
17
Forks
0
Issues
0
MCP Rust Analyzer
π¦ An intelligent Model Context Protocol (MCP) server that provides comprehensive Rust code analysis, refactoring, and navigation capabilities through rust-analyzer integration.
β¨ Features
π Code Analysis
- Hover Information: Get detailed type information and documentation
- Find References: Locate all usage of symbols across your project
- Go to Implementation: Navigate to trait implementations
- Symbol Analysis: Deep dive into symbol definitions and relationships
β‘ Auto-completion & Navigation
- Smart Completions: Context-aware code completions
- Signature Help: Function parameter assistance
- Diagnostics: Real-time error detection and suggestions
π§ Refactoring Tools
- Rename Symbol: Safe rename across entire codebase
- Extract Function: Extract code into reusable functions
- Organize Imports: Clean up and optimize import statements
π Project Metrics
- Code Statistics: Lines of code, complexity metrics
- Dependency Analysis: Analyze Cargo.toml dependencies
- Dead Code Detection: Find unused code in your project
- Project Structure: Analyze module organization
π― Smart Templates
- Code Snippets: Pre-built templates for common patterns
- Match Expressions: Generate match arms automatically
- Test Functions: Quick test function templates
π Intelligent Operation Modes
- Claude Code CLI: Automatic direct mode for maximum compatibility
- Manual Terminal: Smart daemon/client system for optimal performance
- TTY Detection: Automatically chooses the best mode based on context
π Installation
Prerequisites
- Rust toolchain (1.70+)
rust-analyzer
component:rustup component add rust-analyzer
Install from Source
git clone https://github.com/pedrozoalencar/mcp-rust-analyzer.git
cd mcp-rust-analyzer
cargo build --release
# Add to PATH (permanent)
echo 'export PATH="/path/to/mcp-rust-analyzer/target/release:$PATH"' >> ~/.bashrc
source ~/.bashrc
π Usage
With Claude Code CLI
- Add MCP Server:
claude mcp add rust-analyzer mcp-rust-analyzer
- Verify Installation:
claude mcp list
claude mcp test rust-analyzer
- Use in Any Rust Project:
cd your-rust-project/
claude # Automatically detects and analyzes Rust code!
Manual Usage (Advanced)
Daemon Mode (Recommended for Manual Use)
# Start daemon for current project
mcp-rust-analyzer --daemon
# Check daemon status
mcp-rust-analyzer --status
# Stop daemon
mcp-rust-analyzer --stop
# Use client (auto-connects to daemon)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | mcp-rust-analyzer
Direct Mode
# Direct stdin/stdout mode
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | mcp-rust-analyzer --server
π οΈ Architecture
Intelligent Mode Detection
- Claude Code CLI: Automatically uses direct mode for maximum compatibility
- Manual Terminal: Uses smart daemon/client system for optimal performance
- TTY Detection: Automatically chooses the best mode based on context
Dual Operation Modes
Daemon/Client System (Manual Use)
- Background Daemon: Persistent HTTP server per project
- Auto-Port Selection: Finds available ports automatically
- State Management: Tracks daemons across multiple projects
- Auto-Start: Client automatically starts daemon if needed
Direct Mode (Claude Code CLI)
- Zero Configuration: Works out-of-the-box
- LSP Integration: Full rust-analyzer capabilities
- Fast Startup: Optimized for MCP protocol
LSP Integration
- Background Initialization: Non-blocking rust-analyzer startup
- Smart Caching: Reuses LSP connections for performance
- Error Handling: Graceful fallbacks when LSP unavailable
π Available Tools
Tool | Description |
---|---|
project_structure |
Analyze project module organization |
code_metrics |
Get code statistics and metrics |
analyze_dependencies |
View dependency graph |
complete |
Get code completions at a position |
get_hover |
Get type/documentation info |
find_references |
Find all symbol references |
rename |
Rename symbols safely |
signature_help |
Get function signature help |
get_diagnostics |
Get compiler diagnostics |
analyze_symbol |
Analyze a symbol by name |
find_implementations |
Find trait implementations |
expand_snippet |
Expand code snippets |
find_dead_code |
Detect unused code |
suggest_improvements |
Get optimization suggestions |
Resources
The server exposes these resources:
rust-analyzer://project/structure
- Project structurerust-analyzer://project/diagnostics
- All diagnosticsrust-analyzer://project/dependencies
- Dependency graphrust-analyzer://project/symbols
- Workspace symbols
Prompts
Pre-configured prompts for common tasks:
analyze_code
- Comprehensive code analysisrefactor_code
- Guided refactoringexplain_error
- Error explanation with fixesoptimize_code
- Performance optimization
Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Claude Code ββββββΆβ MCP Server ββββββΆβ rust-analyzer β
β (Host) βββββββ (This Project) βββββββ (LSP) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
JSON-RPC Rust API LSP Protocol
Development
Project Structure
src/
βββ main.rs # Entry point
βββ server.rs # MCP server implementation
βββ analyzer.rs # rust-analyzer integration
βββ lsp_client.rs # LSP client for rust-analyzer
βββ commands/ # Command handlers
βββ analysis.rs # Code analysis commands
βββ completion.rs # IntelliSense commands
βββ metrics.rs # Metrics and structure
βββ refactor.rs # Refactoring commands
Running Tests
# Run unit tests
cargo test
# Run integration tests
cargo test --test '*'
# Test MCP protocol compliance
./test_mcp_complete.sh
Debug Mode
# Run with debug logging
RUST_LOG=debug cargo run
# Test individual commands
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | cargo run
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Guidelines
- Follow Rust naming conventions
- Add tests for new features
- Update documentation
- Ensure all tests pass
- Format code with
cargo fmt
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on the Model Context Protocol specification
- Powered by rust-analyzer
- Inspired by the need for better AI-assisted Rust development
Made with β€οΈ for the Rust community
0
Followers
0
Repositories
0
Gists
0
Total Contributions
π Terraform Model Context Protocol (MCP) Tool - An experimental CLI tool that enables AI assistants to manage and operate Terraform environments. Supports reading Terraform configurations, analyzing plans, applying configurations, and managing state with Claude Desktop integration. β‘οΈ
echokit_server is a high-performance server software built in Rust, offering efficient data processing and API management. Designed for developers, it boasts high scalability and adaptability for various applications. It is particularly well-suited for real-time data processing and microservices architecture.