Cargo MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
pip install -e .
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add cargo-mcp -- node "<FULL_PATH_TO_CARGO_MCP>/dist/index.js"

Replace <FULL_PATH_TO_CARGO_MCP>/dist/index.js with the actual folder you prepared in step 1.

README.md

Provides a suite of tools for running Cargo commands in Rust projects.

Cargo MCP Server

A Model Context Protocol (MCP) server that provides tools for running Cargo commands. This server allows AI agents to interact with Rust projects through Cargo, enabling automated builds, tests, documentation generation, and more.

Features

The server provides the following Cargo tools:

  • cargo_build - Build a Rust project with Cargo
  • cargo_test - Run tests for a Rust project
  • cargo_run - Run a Rust binary
  • cargo_check - Check a project for errors without building
  • cargo_clippy - Run Clippy linter
  • cargo_fmt - Format Rust code using rustfmt
  • cargo_doc - Generate documentation
  • cargo_clean - Clean build artifacts
  • cargo_tree - Display dependency tree
  • cargo_update - Update dependencies in Cargo.lock
  • cargo_bench - Run benchmarks

Installation

Prerequisites

  • Python 3.8 or higher
  • Rust and Cargo installed on your system
  • Access to install Python packages

Install from source

  1. Clone this repository:
git clone <repository-url>
cd cargo-mcp
  1. Install the package:
pip install -e .

Usage

With Claude Desktop

Add the server to your claude_desktop_config.json:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "cargo-mcp": {
      "command": "cargo-mcp"
    }
  }
}

With other MCP clients

The server can be used with any MCP-compatible client. Start the server using:

cargo-mcp

Testing with MCP Inspector

You can test the server using the MCP Inspector:

npx @modelcontextprotocol/inspector cargo-mcp

Tool Documentation

cargo_build

Build a Rust project with Cargo.

Parameters:

  • release (boolean, optional): Build in release mode with optimizations
  • features (array, optional): List of features to activate
  • target (string, optional): Build for the given target triple
  • workspace_path (string, optional): Path to the workspace root (auto-detected if not provided)

cargo_test

Run tests for a Rust project.

Parameters:

  • test_name (string, optional): Name of specific test to run
  • release (boolean, optional): Run tests in release mode
  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

cargo_run

Run a Rust binary.

Parameters:

  • bin_name (string, optional): Name of the binary to run (for multi-binary projects)
  • args (array, optional): Arguments to pass to the binary
  • release (boolean, optional): Run in release mode
  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

cargo_check

Check a Rust project for errors without building it.

Parameters:

  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

cargo_clippy

Run Clippy linter on a Rust project.

Parameters:

  • fix (boolean, optional): Automatically apply suggested fixes
  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

cargo_fmt

Format Rust code using rustfmt.

Parameters:

  • check (boolean, optional): Check if files are formatted without modifying them
  • workspace_path (string, optional): Path to the workspace root

cargo_doc

Generate documentation for a Rust project.

Parameters:

  • open (boolean, optional): Open documentation in browser after generation
  • no_deps (boolean, optional): Don't build documentation for dependencies
  • workspace_path (string, optional): Path to the workspace root

cargo_clean

Clean build artifacts.

Parameters:

  • workspace_path (string, optional): Path to the workspace root

cargo_tree

Display dependency tree.

Parameters:

  • package (string, optional): Package to display tree for
  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

cargo_update

Update dependencies in Cargo.lock.

Parameters:

  • package (string, optional): Specific package to update
  • workspace_path (string, optional): Path to the workspace root

cargo_bench

Run benchmarks.

Parameters:

  • bench_name (string, optional): Name of specific benchmark to run
  • features (array, optional): List of features to activate
  • workspace_path (string, optional): Path to the workspace root

Project Structure Detection

The server automatically detects Rust projects by searching for Cargo.toml files. It walks up the directory tree from the current working directory to find the nearest Cargo.toml file and uses that directory as the workspace root.

You can override this behavior by providing the workspace_path parameter to any too

Tools (11)

cargo_buildBuild a Rust project with Cargo.
cargo_testRun tests for a Rust project.
cargo_runRun a Rust binary.
cargo_checkCheck a Rust project for errors without building it.
cargo_clippyRun Clippy linter on a Rust project.
cargo_fmtFormat Rust code using rustfmt.
cargo_docGenerate documentation for a Rust project.
cargo_cleanClean build artifacts.
cargo_treeDisplay dependency tree.
cargo_updateUpdate dependencies in Cargo.lock.
cargo_benchRun benchmarks.

Configuration

claude_desktop_config.json
{"mcpServers": {"cargo-mcp": {"command": "cargo-mcp"}}}

Try it

Run the tests for my current Rust project to ensure everything is working.
Can you run cargo clippy on this project and apply any suggested fixes?
Generate the documentation for my project and open it in the browser.
Check my project for compilation errors without performing a full build.
Show me the dependency tree for this Rust project.

Frequently Asked Questions

What are the key features of Cargo MCP Server?

Automated Rust project builds and testing. Integrated linting with Clippy and code formatting with rustfmt. Automatic project detection via Cargo.toml discovery. Dependency management and documentation generation. Support for running benchmarks and specific project binaries.

What can I use Cargo MCP Server for?

Automating CI/CD tasks directly from an AI-assisted development environment. Quickly identifying and fixing code style issues in Rust projects. Generating and reviewing project documentation during development. Debugging dependency issues by inspecting the project tree. Running specific test suites or benchmarks during iterative coding.

How do I install Cargo MCP Server?

Install Cargo MCP Server by running: pip install -e .

What MCP clients work with Cargo MCP Server?

Cargo MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Cargo MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare