Skip to content

[codex] Add fixed cargo MCP tools#1

Merged
qkal merged 6 commits into
mainfrom
feat/cargo-tools
May 22, 2026
Merged

[codex] Add fixed cargo MCP tools#1
qkal merged 6 commits into
mainfrom
feat/cargo-tools

Conversation

@qkal
Copy link
Copy Markdown
Owner

@qkal qkal commented May 22, 2026

Summary

  • add fixed cargo_* MCP tools for check, test, clippy, fmt --check, and metadata
  • add structured cargo arg validation, output caps, timeout/process-tree cleanup, and disabled-mode config
  • update README safety model and stop tracking generated docs artifacts

Test Plan

  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all

Summary by CodeRabbit

Release Notes

  • New Features

    • Added five new cargo tools: cargo_check, cargo_test, cargo_clippy, cargo_fmt_check, and cargo_metadata for executing cargo commands with customizable parameters (timeouts, output limits, features, targets, test filters, lock/offline flags)
    • Added --disable-cargo-tools CLI option to disable cargo tool execution
  • Documentation

    • Updated documentation with comprehensive cargo tool specifications and parameter schemas
    • Revised safety model section describing cargo execution behavior and process interactions

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Warning

Review limit reached

@qkal, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 51 minutes and 41 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 03144509-f102-44c4-8616-22d2a91e0903

📥 Commits

Reviewing files that changed from the base of the PR and between 84461a3 and 987b439.

📒 Files selected for processing (2)
  • src/cargo.rs
  • tests/cargo_tests.rs
📝 Walkthrough

Walkthrough

This PR adds fixed cargo command execution to the rust-analyzer MCP server. The implementation includes a cargo runner with concurrent output reading, timeout enforcement, and platform-specific process cleanup; five MCP tool handlers (cargo_check, cargo_test, cargo_clippy, cargo_fmt_check, cargo_metadata); configurable server-wide toggle for enabling/disabling cargo tools; comprehensive parameter validation and type-safe CLI argument building; and extensive unit and integration tests covering success paths, timeouts, output truncation, and stdin handling.

Changes

Cargo Tool Execution

Layer / File(s) Summary
Cargo runner foundation and error types
src/cargo.rs, src/error.rs, src/lib.rs, Cargo.toml
Introduces CargoCommandKind, CargoInvocation, and CargoArgs trait for typed cargo command building. Implements run_cargo with concurrent stdout/stderr reading under byte limits, wall-clock timeout with platform-specific process-tree cleanup (Unix/Windows/other), and conditional JSON metadata parsing. Adds error variants for cargo discovery and execution failures, Unix libc dependency, and exports cargo module.
Tool parameter contracts and constants
src/tools.rs
Defines four public parameter structs (CargoBuildParams, CargoTestParams, CargoFmtCheckParams, CargoMetadataParams) with serde/schema derives for optional workspace/package selection, features, targets, timeouts, and output limits. Adds constants for timeout and output size defaults/maximums.
Server configuration and MCP tool handlers
src/server.rs
Adds ServerConfig struct with cargo_tools_enabled flag and RaMcpServer::with_config constructor. Implements cargo-tool execution helpers for workspace resolution, disabled-feature blocking, invocation building, and semaphore-based serialization. Adds five MCP tool handlers and updates tool instructions.
CLI configuration for cargo tools
src/main.rs
Extends argument parsing to support --disable-cargo-tools flag. Updates main function to construct ServerConfig from arguments and pass it through server creation. Updates help text and expands Command::Serve to carry config.
Comprehensive unit and integration tests
tests/cargo_tests.rs, tests/integration_basic.rs
Unit tests validate CLI argument assembly for all command kinds, reject invalid options, verify output caps/clamping, and test UTF-8-safe truncation. Async tests exercise run_cargo against temporary crates, verify metadata parsing, timeout/cleanup with descendant termination checks, and output cap enforcement. Integration tests cover tool listings, --disable-cargo-tools blocking, help text, and cross-platform process liveness.
User-facing documentation and safety model
README.md
Updates tooling overview to list fixed cargo_* tools with --disable-cargo-tools option. Provides detailed specification of all five tools with parameter schemas and constraints. Reworks safety model to describe that cargo_* tools execute fixed commands which may run project code, produce target/ artifacts, and update Cargo.lock unless locked/frozen is set. Extends troubleshooting with cargo-specific entries.

🎯 4 (Complex) | ⏱️ ~45 minutes

In Unix and Windows land so wide,
where processes spawn and time can't hide,
a cargo runner steady and true
reads streams, cleans trees, and parses too! 🐰⚙️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Add fixed cargo MCP tools' directly and clearly summarizes the main change: adding fixed cargo MCP tools (cargo_check, cargo_test, cargo_clippy, cargo_fmt_check, cargo_metadata) to the codebase, which is the primary focus of this changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cargo-tools

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qkal qkal marked this pull request as ready for review May 22, 2026 20:41
@qkal qkal self-assigned this May 22, 2026
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 9 additional findings in Devin Review.

Open in Devin Review

Comment thread src/cargo.rs
Comment on lines +128 to +133
let mut command = StdCommand::new(&invocation.command);
command
.args(&invocation.args)
.current_dir(workspace_root)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Cargo process inherits MCP server's stdin instead of using Stdio::null()

The run_cargo function sets stdout(Stdio::piped()) and stderr(Stdio::piped()) but does not set stdin, which defaults to Stdio::inherit(). Since the MCP server's stdin is the JSON-RPC protocol transport, cargo and all its child processes (build scripts, proc macros, test binaries) inherit this file descriptor. If any subprocess reads from stdin, it will consume MCP protocol messages, causing protocol desynchronization and communication failures.

Contrast with existing rust-analyzer client setup

The existing RustAnalyzerClient::spawn at src/lsp/client.rs:66-71 correctly isolates its stdin with .stdin(std::process::Stdio::piped()). The cargo command at src/cargo.rs:128-133 is missing an equivalent isolation. The taskkill.exe helper at line 277 already uses .stdin(Stdio::null()), showing the pattern is known but was missed for the main cargo command.

Suggested change
let mut command = StdCommand::new(&invocation.command);
command
.args(&invocation.args)
.current_dir(workspace_root)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
let mut command = StdCommand::new(&invocation.command);
command
.args(&invocation.args)
.current_dir(workspace_root)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cargo.rs`:
- Around line 191-195: The TimedOut branch in the match for
OutputCollection::TimedOut should perform the same descendant cleanup as other
terminal branches: call cleanup_process_tree with the run/process identifier
used elsewhere in this function before returning truncated_output_pair(), set
timed_out = true and push the note as already done, and handle/log any error
from cleanup_process_tree similarly to the other branch implementations; locate
the OutputCollection::TimedOut arm and insert the cleanup_process_tree(...) call
(using the same process id/handle variable used by the function) prior to
returning truncated_output_pair() so long-lived child processes are cleaned up
on timeout.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7914e85c-7c0d-45a2-8bd7-15cf11e3b1f5

📥 Commits

Reviewing files that changed from the base of the PR and between 5b4657d and 84461a3.

📒 Files selected for processing (5)
  • README.md
  • src/cargo.rs
  • src/server.rs
  • tests/cargo_tests.rs
  • tests/integration_basic.rs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test (windows-latest)
🔇 Additional comments (2)
README.md (2)

241-241: LGTM!


351-352: LGTM!

Comment thread src/cargo.rs
@qkal qkal merged commit bd13199 into main May 22, 2026
4 checks passed
@qkal qkal deleted the feat/cargo-tools branch May 22, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant