A Model Context Protocol (MCP) server written in Rust that provides AI-assisted code analysis tools for Rust projects. This server enables AI agents to perform advanced code analysis, navigation, and refactoring suggestions on Rust codebases.
- File Analysis: Parse and check Rust files for syntax errors
- Workspace Indexing: Build comprehensive call graphs, type usage graphs, and module dependency graphs
- Code Navigation: Find definitions and references of symbols
- Code Smell Detection: Identify unused functions, long functions, high complexity code, and god objects
- Refactoring Suggestions: Automated suggestions for code improvements
The server uses:
- rmcp crate for MCP protocol handling
- syn for Rust AST parsing
- tokio for async operations
- Thread-safe caching with RwLock
- Visitor pattern for AST traversal
This project includes Docker support for easy deployment:
- Multi-stage Dockerfile: Optimized build process with separate build and runtime stages
- Nightly Rust: Uses Rust nightly for compatibility with latest MCP SDK features (edition 2024)
- Docker Compose: Simple orchestration for development and production
- Minimal runtime image: Based on Debian slim for smaller image size
- No exposed ports: MCP communication happens via stdio within containers
- Docker and Docker Compose (for Docker Hub usage)
- Git (optional, for development)
- Rust 1.70+ (only if building from source)
Note: For most users, Docker is the only requirement. The Docker image uses Rust nightly to support the latest MCP SDK features.
# Method 1: Direct run (downloads automatically)
docker run --rm -i mytheclipse/rust-mcp-server:latest
# Method 2: Pull first, then run
docker pull mytheclipse/rust-mcp-server:latest
docker run --rm -i mytheclipse/rust-mcp-server:latest
# Method 3: Using Docker Compose
docker run --rm -i -v $(pwd):/workspace mytheclipse/rust-mcp-server:latest# Clone repository
git clone https://github.com/MythEclipse/rust-mcp-server.git
cd rust-mcp-server
# Run with Docker Compose (recommended for development)
docker-compose up --build
# Or build and run manually
docker build -t rust-mcp-server .
docker run --rm -i rust-mcp-serverIf you prefer to build from source:
- Rust 1.70+ (2024 edition)
- Cargo
git clone https://github.com/MythEclipse/rust-mcp-server.git
cd rust-mcp-server
cargo build --release
./target/release/rust-mcp-server# Run the latest version from Docker Hub
docker run --rm -i mytheclipse/rust-mcp-server:latest
# Run with workspace volume mounting (for file analysis)
docker run --rm -i -v $(pwd):/workspace mytheclipse/rust-mcp-server:latest
# Run in background
docker run -d --name rust-mcp-server mytheclipse/rust-mcp-server:latest
# Stop background container
docker stop rust-mcp-server && docker rm rust-mcp-server# Clone repository (for development)
git clone https://github.com/MythEclipse/rust-mcp-server.git
cd rust-mcp-server
# Run with hot reload
docker-compose up --build
# Run in background
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose downIf you built from source:
# Run the compiled binary
./target/release/rust-mcp-server
# Or run with Cargo
cargo runThis server implements the Model Context Protocol (MCP) and communicates using JSON-RPC 2.0 over stdio. It's designed to be integrated with MCP-compatible clients like AI coding assistants.
Parse and check a Rust file for syntax errors.
Parameters:
path: Absolute path to the Rust file to check
Example MCP Call:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "check_file",
"arguments": {
"path": "/path/to/your/file.rs"
}
}
}Example Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "File parsed successfully with no syntax errors."
}
]
}
}Index all Rust files in a directory and build comprehensive analysis graphs.
Parameters:
root: Root directory path to index
Example MCP Call:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "index_workspace",
"arguments": {
"root": "/path/to/rust/project"
}
}
}Returns:
- Call graph (function relationships)
- Type usage graph (where types are used)
- Module dependency graph
- Function information (complexity, line count, parameters)
- Struct and enum information
- Unused function detection
- Refactoring suggestions
Find the definition location of a symbol.
Parameters:
name: Symbol name to find definition for
Example MCP Call:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "goto_definition",
"arguments": {
"name": "MyStruct"
}
}
}Find all references to a symbol.
Parameters:
name: Symbol name to find references for
Example MCP Call:
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "find_references",
"arguments": {
"name": "my_function"
}
}
}- Start the MCP server:
cargo run- Index your workspace (in another terminal or MCP client):
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "index_workspace",
"arguments": {
"root": "/home/user/my-rust-project"
}
}
}- Check for syntax errors in a specific file:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "check_file",
"arguments": {
"path": "/home/user/my-rust-project/src/main.rs"
}
}
}- Find where a function is defined:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "goto_definition",
"arguments": {
"name": "process_data"
}
}
}The server is designed to work with AI coding assistants that support MCP. Here's how it typically integrates:
- The AI assistant starts the MCP server as a subprocess
- Communication happens via stdio using JSON-RPC 2.0
- The assistant can call tools to analyze code, navigate, and get suggestions
- Results are used to provide intelligent code assistance
You can test the server manually using tools like socat or by writing a simple client. For development purposes, you can also use the built-in tests:
# Run all tests
cargo test
# Run specific tool tests
cargo test test_index_workspace
cargo test test_check_fileWhen you index a workspace, the server returns comprehensive analysis including:
Function Analysis:
- Functions longer than 50 lines
- Functions with complexity > 10
- Functions with > 5 parameters
Structural Analysis:
- Structs with > 10 fields
- Enums with > 10 variants
Dependency Analysis:
- Functions calling > 10 other functions
- Functions called by > 10 other functions
- Structs used in > 10 places (god objects)
Unused Code:
- Private functions that are never called
The server returns structured errors for invalid requests:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "Invalid params",
"data": {
"details": "Path does not exist"
}
}
}# Build the Docker image
docker build -t rust-mcp-server .
# Or use Docker Compose
docker-compose buildcargo build# Run tests in Docker container (for development)
docker run --rm -v $(pwd):/app mytheclipse/rust-mcp-server:latest cargo testcargo test- Make changes to the code
- Test locally:
cargo test - Build Docker image:
docker build -t rust-mcp-server . - Test the Docker image:
docker run rust-mcp-server
The server performs several types of code analysis:
-
Function Analysis
- Line count detection (>50 lines flagged)
- Cyclomatic complexity calculation (>10 flagged)
- Parameter count analysis (>5 parameters flagged)
-
Structural Analysis
- Large struct detection (>10 fields)
- Large enum detection (>10 variants)
-
Dependency Analysis
- Functions calling too many others (>10 callees)
- Functions called by too many others (>10 callers)
- God object detection (structs used in >10 places)
-
Unused Code Detection
- Private functions that are never called
To use this MCP server with MCP-compatible clients, configure it to run the Docker container:
{
"mcpServers": {
"rust-mcp-server": {
"command": "docker",
"args": ["run", "--rm", "mytheclipse/rust-mcp-server:latest"]
}
}
}{
"mcpServers": {
"rust-mcp-server": {
"command": "docker",
"args": ["run", "--rm", "mytheclipse/rust-mcp-server:latest"]
}
}
}If you prefer using Docker Compose:
{
"mcpServers": {
"rust-mcp-server": {
"command": "docker-compose",
"args": ["exec", "rust-mcp-server", "rust-mcp-server"],
"cwd": "/path/to/rust-mcp-server"
}
}
}command: The executable to run (dockerordocker-compose)args: Array of arguments to pass to the commandcwd: Current Working Directory - only needed for docker-compose setup, should point to the directory containingdocker-compose.yml
The server doesn't require any environment variables for basic operation. However, you can set:
RUST_LOG: Set logging level (e.g.,info,debug,trace)
# Build the image locally
docker build -t rust-mcp-server .
# Pull from Docker Hub
docker pull mytheclipse/rust-mcp-server:latest
# Run with custom environment variables
docker run -e RUST_LOG=debug mytheclipse/rust-mcp-server:latest
# Run with volume mounts (if you need to access host files)
docker run -v /host/path:/container/path mytheclipse/rust-mcp-server:latestFor detailed instructions on how to push this image to Docker Hub, see DOCKER_HUB_DEPLOYMENT.md.
The official Docker Hub repository is: mytheclipse/rust-mcp-server
The server uses default configurations and doesn't require additional setup. All analysis is performed on-demand when tools are called.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure
cargo testpasses - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.