Cargo MCP Server
Tools for managing Rust projects using the cargo command-line tool.
Cargo MCP Server
A Model Context Protocol (MCP) server that provides tools for managing Rust projects using the cargo
command-line tool.
Disclaimer
This entire repository was built with generative AI assistance, guided by human oversight throughout the development process. The code, documentation, and architecture were collaboratively developed between human direction and AI implementation.
Architecture
The server is organized into several modules for maintainability:
src/
├── main.rs # Entry point
├── lib.rs # Library exports
├── server.rs # MCP server implementation
├── tools/
│ ├── mod.rs # Tool module exports
│ ├── definitions.rs # Main tool registry
│ ├── schemas.rs # Common schema utilities
│ ├── build_tools.rs # Build-related tools (check, build, clippy, fmt)
│ ├── execution_tools.rs # Execution tools (run, test, bench)
│ ├── dependency_tools.rs # Dependency management (add, remove, update, tree)
│ ├── project_tools.rs # Project management (new, init, clean, doc)
│ ├── registry_tools.rs # Registry operations (search, info, install, uninstall)
│ ├── utility_tools.rs # Utility tools (metadata, version)
│ └── executor.rs # Command execution logic
├── types.rs # Data structures and types
└── error.rs # Error handling
Features
This MCP server provides comprehensive cargo tools organized by category:
Build Tools
- check - Analyze code without producing executables
- build - Compile the current package
- clippy - Run Clippy lints on the current package
- fmt - Format Rust code using rustfmt
Execution Tools
- run - Run a binary or example of the local package
- test - Run unit and integration tests
- bench - Run benchmarks
Dependency Management
- add - Add dependencies to a Cargo.toml manifest file
- remove - Remove dependencies from a Cargo.toml manifest file
- update - Update dependencies as recorded in the local lock file
- tree - Display a tree visualization of a dependency graph
Project Management
- new - Create a new cargo package at
- init - Create a new cargo package in an existing directory
- clean - Remove artifacts that cargo has generated in the past
- doc - Build this package's and its dependencies' documentation
Registry Operations
- search - Search packages in crates.io
- info - Display information about a package in the registry
- install - Install a Rust binary
- uninstall - Remove a Rust binary
Utility Tools
- metadata - Output the resolved dependencies of a package in machine-readable format
- version - Show version information for cargo and rust
Installation
- Clone this repository
- Build the project:
cargo build --release
- Configure your MCP client to use the server. Example configuration:
{ "mcpServers": { "cargo-mcp": { "command": "/path/to/cargo-mcp/target/release/cargo-mcp", "args": [] } } }
Usage
The server communicates via JSON-RPC over stdin/stdout. It's designed to be used with MCP-compatible clients.
Example Tool Calls
Check a project
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "check",
"arguments": {
"working_directory": "/path/to/project",
"all_targets": true
}
}
}
Build in release mode
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "build",
"arguments": {
"working_directory": "/path/to/project",
"release": true
}
}
}
Run a specific binary
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "run",
"arguments": {
"working_directory": "/path/to/project",
"bin": "my-binary"
}
}
}
Format code
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "fmt",
"arguments": {
"working_directory": "/path/to/project"
}
}
}
Run Clippy with fixes
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "clippy",
"arguments": {
"working_directory": "/path/to/project",
"fix": true,
"allow_dirty": true
}
}
}
Add a dependency
{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"working_directory": "/path/to/project",
"dependency": "serde",
"features": ["derive"]
}
}
}
Search for packages
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "search",
"arguments": {
"working_directory": "/path/to/project",
"query": "tokio",
"limit": 5
}
}
}
Run tests
{
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "test",
"arguments": {
"working_directory": "/path/to/project",
"release": true
}
}
}
Tool Parameters
Common Parameters
Most tools support these common parameters:
working_directory
(string, optional) - Working directory to run cargo inpackage
(string, optional) - Package to operate onfeatures
(array of strings, optional) - Features to activateall_features
(boolean, optional) - Activate all available featuresno_default_features
(boolean, optional) - Do not activate default featuresrelease
(boolean, optional) - Use release profiletarget
(string, optional) - Target triple
Target Selection Parameters
For check, build, clippy, test, and bench:
lib
(boolean, optional) - Only this package's librarybin
(string, optional) - Only the specified binarybins
(boolean, optional) - All binariesexample
(string, optional) - Only the specified exampleexamples
(boolean, optional) - All examplestest
(string, optional) - Only the specified test targettests
(boolean, optional) - All testsbench
(string, optional) - Only the specified bench targetbenches
(boolean, optional) - All benchesall_targets
(boolean, optional) - All targets
Build-specific Parameters
For check and build:
profile
(string, optional) - Build artifacts with the specified profilemessage_format
(string, optional) - Error format (human, short, json, etc.)workspace
(boolean, optional) - Build all packages in the workspaceexclude
(array of strings, optional) - Exclude packages from the operation
Clippy-specific Parameters
fix
(boolean, optional) - Automatically apply lint suggestionsallow_dirty
(boolean, optional) - Fix code even if working directory has changesallow_staged
(boolean, optional) - Fix code even if working directory has staged changes
Test-specific Parameters
exact
(boolean, optional) - Exactly match filters rather than by substringignored
(boolean, optional) - Run ignored testsinclude_ignored
(boolean, optional) - Run both ignored and not ignored testsjobs
(integer, optional) - Number of parallel jobsnocapture
(boolean, optional) - Don't capture stdout/stderrtest_threads
(integer, optional) - Number of threads for running tests
Dependency Management Parameters
add Parameters
dependency
(string, required) - Dependency to adddev
(boolean, optional) - Add as development dependencybuild
(boolean, optional) - Add as build dependencyoptional
(boolean, optional) - Mark the dependency as optionalrename
(string, optional) - Rename the dependencypath
(string, optional) - Filesystem path to local crategit
(string, optional) - Git repository locationbranch
(string, optional) - Git branchtag
(string, optional) - Git tagrev
(string, optional) - Git referencedefault_features
(boolean, optional) - Re-enable default featuresregistry
(string, optional) - Registry to use
remove Parameters
dependency
(string, required) - Dependency to removedev
(boolean, optional) - Remove as development dependencybuild
(boolean, optional) - Remove as build dependency
update Parameters
aggressive
(boolean, optional) - Force updating all dependenciesdry_run
(boolean, optional) - Don't actually write the lockfileprecise
(string, optional) - Update to exactly this versionworkspace
(boolean, optional) - Update all packages in workspace
tree Parameters
duplicates
(boolean, optional) - Show only dependencies with multiple versionsedges
(string, optional) - Kinds of dependencies to displayformat
(string, optional) - Format string for printing dependenciesinvert
(array of strings, optional) - Invert dependency graphno_dedupe
(boolean, optional) - Repeat shared dependenciesprefix
(string, optional) - How to display the treeprune
(array of strings, optional) - Prune packages from displaydepth
(integer, optional) - Maximum display depthcharset
(string, optional) - Character set (utf8, ascii)
Project Management Parameters
new/init Parameters
path
(string, required for new) - Path for the new packagename
(string, optional) - Package namebin_template
(boolean, optional) - Use binary templatelib_template
(boolean, optional) - Use library templateedition
(string, optional) - Edition to setregistry
(string, optional) - Registry to use
doc Parameters
open
(boolean, optional) - Open docs in browserno_deps
(boolean, optional) - Don't build documentation for dependenciesdocument_private_items
(boolean, optional) - Document private itemsjobs
(integer, optional) - Number of parallel jobs
Registry Parameters
search Parameters
query
(string, required) - Search querylimit
(integer, optional) - Limit results (default: 10, max: 100)registry
(string, optional) - Registry to use
info Parameters
query
(string, required) - Package nameregistry
(string, optional) - Registry to use
install Parameters
query
(string, optional) - Package name to installversion
(string, optional) - Specify versiongit_url
(string, optional) - Git URL to install frombranch_install
(string, optional) - Git branchtag_install
(string, optional) - Git tagrev_install
(string, optional) - Git commitpath_install
(string, optional) - Local pathbin_install
(string, optional) - Install only specified binarybins_install
(boolean, optional) - Install all binariesexample_install
(string, optional) - Install only specified exampleexamples_install
(boolean, optional) - Install all examplesforce
(boolean, optional) - Force overwriteno_track
(boolean, optional) - Don't save tracking informationlocked
(boolean, optional) - Assert Cargo.lock unchangedroot
(string, optional) - Installation directoryregistry
(string, optional) - Registry to useindex
(string, optional) - Registry indexlist
(boolean, optional) - List installed packages
uninstall Parameters
query
(string, required) - Package name to uninstallbin_install
(string, optional) - Only uninstall specified binaryroot
(string, optional) - Directory to uninstall from
Utility Parameters
metadata Parameters
no_deps
(boolean, optional) - Don't fetch dependenciesformat_version
(integer, optional) - Format version
Protocol Support
This server implements MCP protocol version 2024-11-05 and supports:
initialize
- Server initializationtools/list
- List available toolstools/call
- Execute cargo commands
Development
To contribute to this project:
- Clone the repository
- Make your changes
- Test with
cargo check
andcargo build
- Format code with
cargo fmt
- Run lints with
cargo clippy
Error Handling
The server provides detailed error messages when cargo commands fail, including both stdout and stderr output from the cargo process.
Related Servers
MKP
Model Kontext Protocol Server for Kubernetes that allows LLM-powered applications to interact with Kubernetes clusters through native Go implementation with direct API integration and comprehensive resource management.
Shadcn UI MCP Server
A powerful and flexible MCP server designed to enhance the development experience with Shadcn UI components, providing tools for component management, documentation, and installation.
AI Image Generation
Generate images using the Together AI API. Supports custom aspect ratios, save paths, and batch generation.
Debugger MCP Server
A development tool for real-time debugging, code quality monitoring, and AI insights for React/Next.js applications.
ALAPI
ALAPI MCP Tools,Call hundreds of API interfaces via MCP
Lingo.dev
Make your AI agent speak every language on the planet, using Lingo.dev Localization Engine.
UIAutomator2 MCP Server
Automate and control Android devices using the UIAutomator2 framework.
PGYER
MCP Server for PGYER platform, supports uploading, querying apps, etc.
MCP RAG Server
A Python server providing Retrieval-Augmented Generation (RAG) functionality. It indexes various document formats and requires a PostgreSQL database with pgvector.
Azure DevOps
Manage Azure DevOps projects, work items, builds, and releases.