feat: serve collar tools over mcp #12

Open
krishsax wants to merge 1 commit from krishsax/mcp-server into main AGit
Member

Summary

Adds collar mcp, a Model Context Protocol server over stdio, so clients that cannot run shell commands (Claude Desktop, claude.ai connectors, IDE assistants) can use Collar.

  • Each tool runs this same binary with fixed arguments and --json, and returns its stdout. Tools therefore share the CLI's validation, host-bound credentials, field selection, and error behavior, and child output never mixes with the protocol stream.
  • Read-only by default: status, pr_list, pr_view, pr_diff, pr_checks, issue_list, issue_view, actions_list, actions_jobs, actions_logs, kennel_status, kennel_logs, kennel_preview, docs_search, docs_view, repo_view, and api_get (always --method=GET).
  • --allow-writes adds pr_comment, pr_review, issue_create, and issue_comment. Write tools are neither listed nor callable without it, carry readOnlyHint: false, and are never retried.
  • Global options (--host, -R, --config, --cache-dir, --no-config) are forwarded; -R before mcp sets the default repository and a tool's repo argument overrides it.
  • Option values are passed as --flag=value and positionals after --, so remote or model-supplied text cannot become an option. Arguments are type-checked against each tool's schema, and unknown arguments are rejected.
  • A non-zero exit returns isError: true with stderr and any JSON stdout, so pr_checks still reports the failing statuses. Output over 256 KiB is truncated with a note.
  • No new dependencies: the JSON-RPC handling is about 150 lines on serde_json, keeping the binary blocking and synchronous.

Docs: new "Connect an MCP client" section in docs/agents.md; the command reference is regenerated. The skill remains the recommended path for agents that can run commands.

Not included: long-running waits (kennel wait, actions watch), which would block the stdio loop and are better added later with progress notifications.

Validation

  • cargo clippy --all-targets -- -D warnings and treefmt pass.
  • New unit tests in src/mcp.rs cover argument boundaries, validation, write opt-in, protocol errors, and truncation.
  • New tests/cases/mcp.rs runs collar mcp against the fixture server: initialize, notification handling, tool listing without writes, a pr_view call with field selection, a rejected write call, and an error result that does not echo secrets.
  • Manually tested read tools against git.cmu.dev (pr_list, pr_checks, docs_search).
  • On macOS (aarch64-darwin) the cli test binary aborts with "failed to initiate panic, error 5" on any test that panics, on main as well. Running each test in its own process: 144 of 146 pass. The two failures are existing environment tests that compare /var against /private/var temp paths. The cargo-test hook was skipped for this commit for that reason.
## Summary Adds `collar mcp`, a Model Context Protocol server over stdio, so clients that cannot run shell commands (Claude Desktop, claude.ai connectors, IDE assistants) can use Collar. - Each tool runs this same binary with fixed arguments and `--json`, and returns its stdout. Tools therefore share the CLI's validation, host-bound credentials, field selection, and error behavior, and child output never mixes with the protocol stream. - Read-only by default: `status`, `pr_list`, `pr_view`, `pr_diff`, `pr_checks`, `issue_list`, `issue_view`, `actions_list`, `actions_jobs`, `actions_logs`, `kennel_status`, `kennel_logs`, `kennel_preview`, `docs_search`, `docs_view`, `repo_view`, and `api_get` (always `--method=GET`). - `--allow-writes` adds `pr_comment`, `pr_review`, `issue_create`, and `issue_comment`. Write tools are neither listed nor callable without it, carry `readOnlyHint: false`, and are never retried. - Global options (`--host`, `-R`, `--config`, `--cache-dir`, `--no-config`) are forwarded; `-R` before `mcp` sets the default repository and a tool's `repo` argument overrides it. - Option values are passed as `--flag=value` and positionals after `--`, so remote or model-supplied text cannot become an option. Arguments are type-checked against each tool's schema, and unknown arguments are rejected. - A non-zero exit returns `isError: true` with stderr and any JSON stdout, so `pr_checks` still reports the failing statuses. Output over 256 KiB is truncated with a note. - No new dependencies: the JSON-RPC handling is about 150 lines on `serde_json`, keeping the binary blocking and synchronous. Docs: new "Connect an MCP client" section in `docs/agents.md`; the command reference is regenerated. The skill remains the recommended path for agents that can run commands. Not included: long-running waits (`kennel wait`, `actions watch`), which would block the stdio loop and are better added later with progress notifications. ## Validation - `cargo clippy --all-targets -- -D warnings` and `treefmt` pass. - New unit tests in `src/mcp.rs` cover argument boundaries, validation, write opt-in, protocol errors, and truncation. - New `tests/cases/mcp.rs` runs `collar mcp` against the fixture server: initialize, notification handling, tool listing without writes, a `pr_view` call with field selection, a rejected write call, and an error result that does not echo secrets. - Manually tested read tools against git.cmu.dev (`pr_list`, `pr_checks`, `docs_search`). - On macOS (aarch64-darwin) the `cli` test binary aborts with "failed to initiate panic, error 5" on any test that panics, on `main` as well. Running each test in its own process: 144 of 146 pass. The two failures are existing `environment` tests that compare `/var` against `/private/var` temp paths. The `cargo-test` hook was skipped for this commit for that reason.
feat: serve collar tools over mcp
All checks were successful
nixbot/nix-eval evaluation succeeded in 2m 20s (1 warning)
kennel/deploy deployment healthy
CI / checks-1 (pull_request) Successful in 17s
CI / checks (pull_request) Successful in 0s
nixbot/nix-build 5 attributes built
bfe987930a
Owner

Kennel Deployments

Service URL
docs https://collar-docs-pr-12.scottylabs.net

Last updated for commit bfe9879.

<!-- kennel-deployment --> ### Kennel Deployments | Service | URL | | --- | --- | | docs | https://collar-docs-pr-12.scottylabs.net | Last updated for commit `bfe9879`.
All checks were successful
nixbot/nix-eval evaluation succeeded in 2m 20s (1 warning)
Required
Details
kennel/deploy deployment healthy
Required
CI / checks-1 (pull_request) Successful in 17s
Required
Details
CI / checks (pull_request) Successful in 0s
Required
Details
nixbot/nix-build 5 attributes built
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/12/head:krishsax/mcp-server'
git switch 'krishsax/mcp-server'
Sign in to join this conversation.
No description provided.