A Model Context Protocol (MCP) server that provides tools for managing Rust projects using the cargo command-line tool.
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.
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
This MCP server provides comprehensive cargo tools organized by category:
- 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
- run - Run a binary or example of the local package
- test - Run unit and integration tests
- bench - Run benchmarks
- 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
- 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
- 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
- metadata - Output the resolved dependencies of a package in machine-readable format
- version - Show version information for cargo and rust
- 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": [] } } }
The server communicates via JSON-RPC over stdin/stdout. It's designed to be used with MCP-compatible clients.
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "check",
"arguments": {
"working_directory": "/path/to/project",
"all_targets": true
}
}
}{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "build",
"arguments": {
"working_directory": "/path/to/project",
"release": true
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "run",
"arguments": {
"working_directory": "/path/to/project",
"bin": "my-binary"
}
}
}{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "fmt",
"arguments": {
"working_directory": "/path/to/project"
}
}
}{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "clippy",
"arguments": {
"working_directory": "/path/to/project",
"fix": true,
"allow_dirty": true
}
}
}{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"working_directory": "/path/to/project",
"dependency": "serde",
"features": ["derive"]
}
}
}{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "search",
"arguments": {
"working_directory": "/path/to/project",
"query": "tokio",
"limit": 5
}
}
}{
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "test",
"arguments": {
"working_directory": "/path/to/project",
"release": true
}
}
}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
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
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
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
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(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
dependency(string, required) - Dependency to removedev(boolean, optional) - Remove as development dependencybuild(boolean, optional) - Remove as build dependency
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
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)
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
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
query(string, required) - Search querylimit(integer, optional) - Limit results (default: 10, max: 100)registry(string, optional) - Registry to use
query(string, required) - Package nameregistry(string, optional) - Registry to use
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
query(string, required) - Package name to uninstallbin_install(string, optional) - Only uninstall specified binaryroot(string, optional) - Directory to uninstall from
no_deps(boolean, optional) - Don't fetch dependenciesformat_version(integer, optional) - Format version
This server implements MCP protocol version 2024-11-05 and supports:
initialize- Server initializationtools/list- List available toolstools/call- Execute cargo commands
To contribute to this project:
- Clone the repository
- Make your changes
- Test with
cargo checkandcargo build - Format code with
cargo fmt - Run lints with
cargo clippy
The server provides detailed error messages when cargo commands fail, including both stdout and stderr output from the cargo process.