mcp-cargo

greenwoodcm/mcp-cargo

3.1

If you are the rightful owner of mcp-cargo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

An MCP (Model Context Protocol) server that wraps the `cargo` build command with structured output options.

MCP Cargo Server

An MCP (Model Context Protocol) server that wraps the cargo build command with structured output options.

Features

  • Execute any cargo command with optional arguments
  • Specify working directory for cargo execution
  • Structured output parsing for common scenarios:
    • test_failures: Extract only failed tests and their error messages from cargo test
    • build_errors: Extract compilation errors and warnings from cargo build/cargo check
  • Raw output automatically saved to temporary files (stdout, stderr, exit_code)

Building

cargo build --release

Usage

The server implements the MCP protocol and communicates via JSON-RPC over stdin/stdout.

Tool Parameters

  • directory (optional): Directory to run cargo in
  • command (required): Cargo command (build, test, check, etc.)
  • args (optional): Array of arguments to pass to the cargo command
  • output_type (optional): Type of structured output
    • "test_failures": For cargo test - returns only failed tests with messages
    • "build_errors": For cargo build/cargo check - returns errors and warnings

Example Usage

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "cargo",
    "arguments": {
      "directory": "/path/to/project",
      "command": "test",
      "args": ["--release"],
      "output_type": "test_failures"
    }
  }
}

This would run cargo test --release in /path/to/project and return only the failed tests with their error messages.

Output Formats

All outputs include an output_dir field pointing to a temporary directory containing the raw cargo output files (stdout, stderr, exit_code).

test_failures

{
  "failed_tests": [
    {
      "test": "test_name",
      "message": "assertion failed: expected true, got false"
    }
  ],
  "output_dir": "/tmp/mcp-cargo-1234567890"
}

build_errors

{
  "errors": ["error message 1", "error message 2"],
  "warnings": ["warning message 1"],
  "output_dir": "/tmp/mcp-cargo-1234567890"
}

No output_type specified

{
  "output_dir": "/tmp/mcp-cargo-1234567890"
}