Sponsored by Deepsite.site

Rust MCP Server

Created By
lh7 months ago
Model Context Protocol server for Rust development tools (clippy, rustfmt, cargo check, cargo test)
Content

Rust MCP Server

A Model Context Protocol (MCP) server that provides essential Rust development tools for AI assistants and IDEs. This server enables real-time syntax checking, linting, formatting, testing, and building of Rust projects through the standardized MCP interface.

Features

Available Tools

  1. cargo_check - Syntax and type validation

    • Validates Rust code syntax and type checking
    • Supports workspace-wide checking
    • Provides detailed error messages and suggestions
  2. cargo_clippy - Code linting

    • Catches common mistakes and suggests improvements
    • Supports automatic fixes where possible
    • Configurable lint levels and rules
  3. rustfmt - Code formatting

    • Formats Rust code according to style guidelines
    • Can check formatting without applying changes
    • Supports individual file or project-wide formatting
  4. cargo_test - Test execution

    • Runs Rust tests with detailed output
    • Supports specific test patterns and packages
    • Configurable output capture for debugging
  5. cargo_build - Project building

    • Builds Rust projects in debug or release mode
    • Supports workspace builds
    • Provides build status and error details

Installation

Prerequisites

  • Rust toolchain (rustc, cargo, clippy, rustfmt)
  • Tokio async runtime support

Build from source

git clone https://github.com/lh/rust-mcp-server
cd rust-mcp-server
cargo build --release

Claude Code Integration

Quick Install

# Clone and build the server
git clone https://github.com/lh/rust-mcp-server
cd rust-mcp-server
cargo build --release

# Add to Claude Code (adjust the project path as needed)
claude mcp add rust-tools -s user -- $(pwd)/target/release/rust-mcp-server --project-path ~/Code

# Verify installation
claude mcp list | grep rust-tools

Alternative Installation Methods

Using absolute path:

claude mcp add rust-tools -s user -- /path/to/rust-mcp-server/target/release/rust-mcp-server --project-path /path/to/your/rust/projects

Project-specific installation:

# Navigate to your Rust project
cd /path/to/your/rust/project

# Add the server with current directory as project path
claude mcp add rust-tools -s project -- /path/to/rust-mcp-server/target/release/rust-mcp-server --project-path .

Verify Connection

After installation, restart Claude Code and check the server status:

/mcp

You should see rust-tools: connected in the list.

Usage

Command Line

# Run in current directory
./target/release/rust-mcp-server

# Specify project path
./target/release/rust-mcp-server --project-path /path/to/rust/project

Using with Claude Code

Once installed, you can use natural language to invoke Rust tools:

  • "Check this Rust code for errors" → runs cargo check
  • "Lint my Rust project" → runs cargo clippy
  • "Format this Rust file" → runs rustfmt
  • "Run the tests" → runs cargo test
  • "Build the project in release mode" → runs cargo build --release

MCP Integration

The server communicates via JSON-RPC over stdin/stdout following the MCP protocol:

Initialize

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {}
}

List Available Tools

{
  "jsonrpc": "2.0", 
  "id": 2,
  "method": "tools/list"
}

Execute Tool

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "cargo_check",
    "arguments": {
      "workspace": true
    }
  }
}

Tool Parameters

cargo_check

{
  "target": "",        // Optional specific target
  "workspace": false   // Check all workspace packages
}

cargo_clippy

{
  "fix": false,        // Auto-apply fixes
  "workspace": false,  // Run on all packages
  "deny": []          // Lint levels to deny
}

rustfmt

{
  "file": "",         // Specific file to format
  "check": false      // Check without applying
}

cargo_test

{
  "test_name": "",    // Specific test pattern
  "package": "",      // Specific package
  "workspace": false, // Test all packages
  "nocapture": false  // Don't capture output
}

cargo_build

{
  "release": false,   // Build in release mode
  "workspace": false  // Build all packages
}

Output Format

All tools return standardized JSON responses:

{
  "success": true,
  "exit_code": 0,
  "stdout": "compilation output...",
  "stderr": "warnings and errors...",
  "command": "cargo check"
}

Integration Examples

Claude Code Integration

This server is designed to work seamlessly with AI assistants like Claude Code, providing real-time feedback during code development:

  1. Syntax Validation: Automatically check code as it's written
  2. Lint Suggestions: Get improvement suggestions and apply fixes
  3. Code Formatting: Ensure consistent code style
  4. Test Execution: Validate changes don't break existing functionality
  5. Build Verification: Confirm project compiles successfully

VS Code Extension

Can be integrated with VS Code through MCP to provide enhanced Rust development experience alongside existing language servers.

Error Handling

The server provides detailed error information for:

  • Invalid tool names
  • Missing required parameters
  • Compilation errors
  • Process execution failures
  • File system errors

Troubleshooting

Server Not Connecting

If you see connection errors in Claude Code:

  1. Ensure the binary is built:

    cd /path/to/rust-mcp-server
    cargo build --release
    ls -la target/release/rust-mcp-server  # Should exist and be executable
    
  2. Check the -- separator:

    # ✅ Correct
    claude mcp add rust-tools -- /path/to/rust-mcp-server/target/release/rust-mcp-server
    
    # ❌ Incorrect (missing --)
    claude mcp add rust-tools /path/to/rust-mcp-server/target/release/rust-mcp-server
    
  3. Test the server manually:

    cd /path/to/rust-mcp-server
    python3 test_server.py
    
  4. Check logs: Look for error messages when running claude --mcp-debug

Common Issues

  • "cargo: command not found": Ensure Rust is installed and in your PATH
  • "failed to find cargo.toml": Make sure --project-path points to a Rust project
  • Server disconnects immediately: Check that the binary path is absolute, not relative
  • Server connects but no tools available: This was a bug in v0.1.0 where the server included "error": null in successful responses, violating JSON-RPC 2.0 spec. Fixed in v0.1.1.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License

Changelog

v0.1.1 (fix/json-rpc-error-field)

  • Fixed JSON-RPC 2.0 compliance issue where error: null was incorrectly included in successful responses
  • This fix resolves connection issues with Claude Code where the server would connect but tools wouldn't be available
  • Added #[serde(skip_serializing_if = "Option::is_none")] to the error field in McpResponse

v0.1.0

  • Initial release
  • Core MCP server implementation
  • Support for cargo check, clippy, rustfmt, test, and build
  • JSON-RPC communication over stdin/stdout
  • Configurable project path
  • Comprehensive error handling
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Serper MCP ServerA Serper MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
DeepChatYour AI Partner on Desktop
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Playwright McpPlaywright MCP server
CursorThe AI Code Editor
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Amap Maps高德地图官方 MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs