home / mcp / cargo mcp server

Cargo MCP Server

Provides safe, cargo-oriented MCP operations like build, test, lint, and run inside a controlled context.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "jbr-cargo-mcp": {
      "command": "/path/to/cargo-mcp/cargo-mcp",
      "args": [
        "serve"
      ],
      "env": {
        "CARGO_MCP_DEFAULT_TOOLCHAIN": "YOUR_TOOLCHAIN"
      }
    }
  }
}

You can safely access and orchestrate Rust project operations from your editor or IDE through a dedicated MCP server. It exposes common Cargo tasks in a controlled environment, enabling you to run checks, format, test, build, and more without leaving your workspace.

How to use

Connect your MCP client to the Cargo MCP Server you configured. Use the client’s MCP configuration to point at the local or remote server and enable the desired tools. You can run checks, format, lint, build, bench, add or remove dependencies, clean artifacts, and execute binaries in the context of your Rust project. All commands run against the target project directory and only whitelisted Cargo operations are allowed for safety.

How to install

Prerequisites: you need a Rust toolchain installed on your system. Ensure you have Rust and Cargo available in your shell.

Install the MCP server command for Cargo by running the following command in your terminal.

cargo install cargo-mcp

Additional notes on configuration and usage

The server exposes a set of Cargo tools that you can invoke through the MCP client. Each tool supports a configurable environment via the cargo_env parameter and can specify a rust toolchain through the toolchain parameter.

Troubleshooting and tips

If you encounter issues connecting to the server, verify the MCP client configuration matches the server’s address and that the cargo-mcp toolchain is available in the environment. Ensure your current directory contains Cargo.toml so path validation can confirm a valid Rust project.

Available tools

cargo_check

Verify code compiles without producing executables by running cargo check in the target project.

cargo_clippy

Run the Clippy linter to provide code quality suggestions and potential fixes.

cargo_test

Execute the project's tests using cargo test.

cargo_fmt_check

Check code formatting without modifying files using cargo fmt -- --check.

cargo_build

Build the project in either debug or release mode using cargo build or cargo build --release.

cargo_bench

Run benchmark suites with cargo bench to measure performance.

cargo_add

Add dependencies to Cargo.toml using cargo add.

cargo_remove

Remove dependencies from Cargo.toml using cargo remove.

cargo_update

Update dependencies to the latest compatible versions with cargo update.

cargo_clean

Remove artifacts produced by Cargo to reclaim space with cargo clean.

cargo_run

Run a binary or example package using cargo run.