feat: add mcp tools#311
Conversation
Greptile SummaryThis PR adds a Confidence Score: 5/5Safe to merge — previously raised P1 concerns are resolved and only minor P2 suggestions remain. Both issues flagged in prior review rounds (misleading stop success message and src/cli/mcp.rs — minor log-line cap and eprintln suggestions only
|
| Filename | Overview |
|---|---|
| src/cli/mcp.rs | New MCP server implementation with five tool handlers; stop handler correctly pre-snapshots running daemons; minor: no upper bound on log line count n |
| src/cli/mod.rs | Registers the new Mcp subcommand in the CLI dispatcher — straightforward addition with no issues |
| Cargo.toml | Adds rmcp dependency for MCP server support; indirect dependency additions look correct |
| docs/cli/mcp.md | Generated CLI reference doc for the new mcp command — no manual edits needed |
Sequence Diagram
sequenceDiagram
participant AI as AI Assistant
participant MCP as pitchfork mcp (stdio)
participant IPC as IPC Client
participant Sup as Supervisor
AI->>MCP: initialize
MCP-->>AI: ServerInfo + tool list
AI->>MCP: call pitchfork_status
MCP->>IPC: connect(auto_start=true)
IPC->>Sup: get_all_daemons
Sup-->>IPC: daemon list
IPC-->>MCP: entries
MCP-->>AI: JSON daemon status
AI->>MCP: call pitchfork_stop({id:[...]})
MCP->>IPC: connect(auto_start=false)
IPC->>Sup: get_running_daemons (snapshot)
Sup-->>IPC: running ids
MCP->>IPC: stop_daemons(ids)
IPC->>Sup: stop
Sup-->>IPC: StopResult
MCP-->>AI: Stopped: X (based on pre-snapshot)
AI->>MCP: call pitchfork_logs({id:[...], n:50})
MCP->>MCP: read_last_n_lines from log files
MCP-->>AI: log text output
Reviews (2): Last reviewed commit: "feat: add mcp tools" | Re-trigger Greptile
There was a problem hiding this comment.
Code Review
This pull request introduces a new mcp command to the pitchfork CLI, enabling a Model Context Protocol (MCP) server to run over stdin/stdout. This server exposes daemon management functionalities (start, stop, restart, status, logs) to AI assistants via JSON-RPC. The changes involve adding several new Rust dependencies, implementing the Mcp command in src/cli/mcp.rs, and updating documentation. Review feedback highlights several areas for improvement, including handling unwrap() calls gracefully in the pitchfork_status tool, refining the pitchfork_stop success message to only report actually stopped daemons, clarifying the behavior of n=0 for log retrieval in pitchfork_logs, and logging errors when reading state files or opening log files to improve diagnostic capabilities.
| }) | ||
| .collect(); | ||
|
|
||
| let text = serde_json::to_string_pretty(&daemons).unwrap(); |
There was a problem hiding this comment.
Using unwrap() here can cause the server to panic if JSON serialization fails for any reason. While it might be unlikely with the current data structure, it's safer to handle the potential error gracefully in a server context to prevent crashes.
| let text = serde_json::to_string_pretty(&daemons).unwrap(); | |
| let text = serde_json::to_string_pretty(&daemons) | |
| .map_err(|e| internal_err(format!("Failed to serialize daemon status: {e}")))?; |
| )])); | ||
| } | ||
|
|
||
| let n = if params.n == 0 { 50 } else { params.n }; |
There was a problem hiding this comment.
The current logic treats n = 0 as a request for the default number of lines (50). This can be surprising for an API client, which would likely expect 0 lines to be returned when n=0 is specified. The #[serde(default = ...)] attribute already handles the case where n is not provided by the client. To make the API more predictable, consider removing this conditional logic and using params.n directly in the call to read_last_n_lines on line 354.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
|
@jdx ready for review! |
## 🤖 New release * `pitchfork-cli`: 2.3.0 -> 2.4.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [2.4.0](v2.3.0...v2.4.0) - 2026-04-09 ### Added - add mcp tools ([#311](#311)) - impl container mode ([#305](#305)) ### Fixed - use correct base dir for `.config/pitchfork.toml` case ([#307](#307)) - use FSEvent on macos to avoid `Too many files` ([#301](#301)) ### Other - *(deps)* lock file maintenance ([#310](#310)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk release bookkeeping only: updates version metadata and the changelog, without changing runtime code paths. > > **Overview** > Bumps `pitchfork-cli` from **2.3.0** to **2.4.0** in `Cargo.toml`/`Cargo.lock` and adds the `2.4.0` entry to `CHANGELOG.md` documenting the release contents (MCP tools, container mode, and a few fixes). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b7647a4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
addresses #304.