Skip to main content

Model Context Protocol server for Cargo operations

Project description

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 tool.

Error Handling

The server provides detailed error messages and logs for troubleshooting:

  • Checks if Cargo is installed and available in PATH
  • Validates that Cargo.toml exists in the target directory
  • Captures both stdout and stderr from Cargo commands
  • Provides detailed command execution information

Development

Setup

  1. Clone the repository
  2. Install development dependencies:
pip install -e ".[dev]"

Testing

Run tests using pytest:

pytest

Code Formatting

Format code using black:

black src/

Lint code using ruff:

ruff check src/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cargo_mcp-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cargo_mcp-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file cargo_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: cargo_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for cargo_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 141b3283c207081fd99e6808777e7236d627394e7f7f43626adb0b40f967c40e
MD5 ca5ae1e5c6a1710d3318a70a8b54b034
BLAKE2b-256 f8f730d6d8199dadf33edc82d5e22a420daa1591ff92bc7d0fa1369c2ca19154

See more details on using hashes here.

File details

Details for the file cargo_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cargo_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for cargo_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68efbe42889cdadb2f6745267a994f81ff439cda0ce01acea74e43ad7f7d1366
MD5 89e86a78d9201495dd6fe6052623c913
BLAKE2b-256 e6ea6d468d3c89494a039682a3e9f5e5750ca5e7196f9577ab5a928ca62f64e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page