Skip to main content

PatchPilot MCP

PatchPilot — review the change, not the entire project

A focused review loop, not a fresh repository scan.

Version GitHub Actions GitHub stars

Python Protocol CLI License

PatchPilot helps coding agents and developers inspect explicitly supplied changes after an edit. It extracts changed line locations, highlights ordinary Python correctness and maintainability issues, strict JSON syntax and duplicate object keys, JavaScript/JSX/TypeScript/TSX grammar and conservative maintainability diagnostics, Go/Java/C#/Dart grammar diagnostics, tracks a change budget and guides targeted testing. A caller-retained manifest allows repeated reviews to skip unchanged, previously reviewed source. It does not execute project code, edit files, inspect the workspace, perform vulnerability discovery or contact external services. It can summarize metadata from externally generated SARIF reports without executing the external tools.

Review contract: your agent supplies the diff and the affected source, PatchPilot returns observations and next actions. The agent decides what to fix and runs the relevant project tests.

Quick start (3 steps)

1. Install the source in your Python 3.10+ environment:

git clone https://github.com/ahmedsaeed1-eng/patchpilot-mcp.git
cd patchpilot-mcp
python -m pip install .

2. Connect your coding assistant (Codex example):

codex mcp add patchpilot -- patchpilot-mcp
codex mcp list

3. Review your current edit in the host: select review_changed, provide the unified diff and complete affected source, then address observations and run focused project tests. For a manual local trial:

python -m patchpilot changed < examples/changed.json

Four core MCP tools

Tool Purpose
review_diff Map changed lines, budget and test targets.
review_changed Verify post-edit source against the diff; separate changed and outside-line observations.
review_source Review explicit source, choosing language and optional policy.
review_snapshot Reuse caller-retained manifest and review only changed inputs.

Other tools are optional advanced interfaces: review_python, review_json, review_javascript (specialized compatibility tools), compare_call_signature, compact_report, suggest_formatting_patch, export_sarif, and import_external_sarif. Full arguments below.

PatchPilot v0.4.1 CLI review demonstration

The demo shows actual v0.4.1 output; try changed source and compact report. The benchmark slide is labeled v0.4.0 historical evidence.

Use the same changed scope after each edit; PatchPilot cannot observe your editor or execute project tests. The host supplies inputs explicitly.

Additional MCP host configuration

The package includes the official MCP Python SDK and static grammar dependencies.

If the entry point is not available on your PATH, configure the absolute path to the Python executable in your environment and use the module invocation.

Codex MCP configuration:

[mcp_servers.patchpilot]
command = "/absolute/path/to/python"
args = ["-m", "patchpilot.server"]

Claude Desktop MCP configuration (use the same installed Python environment):

{
  "mcpServers": {
    "patchpilot": {
      "command": "/absolute/path/to/python",
      "args": ["-m", "patchpilot.server"]
    }
  }
}

Restart or reconnect the host if required. All twelve tools use stdio and expose structured JSON results.

Quick start: explicit CLI

From the checkout, Python/JSON/diff operations need only the Python standard library; Static grammar checks require the listed static parser dependencies. The caller supplies text via stdin.

python -m patchpilot diff < examples/inventory.diff
python -m patchpilot python --path inventory.py --complete-module < inventory.py
python -m patchpilot json < examples/settings.json
python -m patchpilot snapshot < examples/snapshot.json
python -m patchpilot javascript --language typescript --path examples/sample.ts < examples/sample.ts
python -m patchpilot sarif < report.json

Replace the illustrative filename with an actual affected source file. The tool itself never opens a path; redirection is performed by the calling shell. You can also install the project and call patchpilot instead of python -m patchpilot.

For a caller-controlled Git workflow, supply the particular staged diff:

git diff --cached --no-color --no-ext-diff --no-textconv | python -m patchpilot diff

If no staged changes exist, the CLI reports NO_INPUT, syntax_ok: null, and exit 3 (no review performed). The optional manual pre-commit wrapper checks for an empty staged diff first and treats that intentional no-op as success. The tool never invokes Git; that command is a separate explicit action by the caller. CLI output is JSON on stdout. Exit code 0 means there is no detected error-level finding (warnings may still exist), 1 means an error-level finding (or signature mismatch), 2 means malformed/rejected input, and 3 means missing input or incomplete review coverage without a detected error, including finding caps. Compact, external import, and formatting print projections without an error-level gate.

Empty input and encoding

Direct CLI input is decoded as strict UTF-8. Invalid bytes return a clear encoding error and status 2; they are never replaced. Direct empty stdin and empty diff/Python-fragment/JSON/JS/source requests without explicit complete-file intent return NO_INPUT with syntax_ok: null and unknown coverage. An intentional empty complete file can be identified with review_source (complete: true), an explicit snapshot/changed-file entry, or Python CLI --complete-module. An empty full Python/JS file may be valid; a full empty JSON document is invalid. Nonempty whitespace-only source is still actual supplied text, not missing input.

All direct source parsers count omitted findings; review_source reports checked_incomplete_findings when output truncation occurs. Snapshot and changed reports carry omitted_source_findings as a separately identified unclassified subset of aggregate omissions; no complete replacement stamp is issued for a truncated source. Smaller explicit scopes are needed to recover every observation.

What the review reports

Finding Severity Evidence
NO_INPUT warning fact: no source content supplied; no syntax verdict
PYTHON_SYNTAX error fact about supplied text in isolation
JS_TS_SYNTAX error selected static grammar reports a missing/error node
MUTABLE_DEFAULT warning heuristic: literal mutable function default
BARE_EXCEPT warning heuristic: broad exception handler
BUILTIN_SHADOWING info heuristic: binding shadows a builtin name
POSSIBLY_UNUSED_LOCAL info heuristic: no lexical reference in supplied function
JSON_SYNTAX error grammar error in supplied JSON text
JSON_DUPLICATE_KEY warning repeated decoded key in one JSON object
DUPLICATE_LITERAL_KEY warning fact: repeated constant dict key
CHANGE_BUDGET warning fact: changed lines or files exceed selected budget
TRAILING_WHITESPACE info fact about the added line; removal may be inappropriate
UNREACHABLE_STATEMENT warning heuristic: direct statement after unconditional terminator
DUPLICATE_DEFINITION warning heuristic: repeated sibling definition
BRANCH_COMPLEXITY warning heuristic: branch score meets or exceeds threshold
POSSIBLY_UNUSED_IMPORT info heuristic: no explicit read in complete supplied module
NO_TEST_PATH info heuristic: common test-path naming conventions

Each MCP/CLI finding contains id, code, severity, evidence, path, line, message and recommendation. JSON findings and repeated Python literal keys also include a one-based Unicode-character column. IDs deduplicate equal observations and are stable only when label, code, position and message remain equal. They are not guaranteed across line moves. A null line means the observation applies to the diff as a whole. Python checks never execute the submitted source: AST parsing and syntax compilation are used only to validate the supplied text; compiled objects are discarded.

The example diff reports two changed files, four additions, one deletion and churn of five. Its test plan points to new lines in inventory.py and tests/test_inventory.py.

Tools

review_diff

Argument Meaning Default / range
diff Unified diff text (required) text
change_budget Combined additions and removals 300 / 1–10000
file_budget Number of file sections 10 / 1–100

Returns counts, per-file added and removed line coordinates, common test paths, focused review suggestions, and budget status. The review effort label describes change size only, not security or a correctness pass. Git rename metadata, quoted UTF-8 paths with C-style escaping, file addition/deletion and mode-only changes are parsed. Each file now includes change_kind, old_mode and new_mode. Binary/copy/combined diffs remain unsupported.

review_python

Argument Meaning Default / range
source Python text (required) text
path Display label, not a file path to open snippet.py
start_line First original source line represented in snippet 1 / 1–100000000
complexity_threshold Warning threshold of simple branch score 10 / 2–50
complete_module Allow best-effort unused import hints false

The AST branch score starts at one, then counts selected control-flow branches, boolean transitions, match cases and comprehensions; nested callable bodies are scored independently.

review_javascript

Supply source, optional path, start_line (1), and language (javascript, jsx, typescript, tsx). The Tree-sitter JavaScript grammar also recognizes JSX; TypeScript/TSX use their respective grammar entry points. Returns syntax_ok, coverage, bounded diagnostic findings and coordinates. The parser checks grammar, not semantics, types, framework validity or project configuration. If an installed grammar is missing/incompatible, syntax_ok: null and coverage: unknown_parser_unavailable prevent a false pass.

Python checks now also report mutable literal defaults, bare except, builtin name shadowing and possibly unused local bindings. Unused-local hints use compiler symbol tables plus conservative closure and reflection exclusions; they do not establish dead code. No source is executed.

review_json

Supply source (strict JSON text), optional path and start_line (defaults document.json, 1). Grammar checks include arrays, objects, literals, strings and numbers, including valid large-exponent numbers. Repeated keys are identified per object using their decoded names and exact one-based line/column coordinates. The tool does not validate schemas; duplicate object keys are a warning because different readers may retain different values.

review_snapshot — incremental review

A manifest is a small source-identity record, not a storage layer or attestation. Pass a batch of explicit source entries, then retain the returned metadata-only manifest for the next invocation.

{
  "entries": [
    {"path":"inventory.py","source":"def count(): return 3"},
    {"path":"settings.json","source":"{\"quantity\":3}"}
  ],
  "complete_snapshot": true
}

Next, supply entries from the current edit and the previous response's manifest as previous_manifest. You may omit unchanged paths in a partial batch, or supply a previously computed SHA-256 digest instead of source. The tool never generates digests by opening files.

Entry field Meaning
path Logical display label, unique per batch
source Explicit UTF-8 file content or fragment
digest Optional lowercase SHA-256 of exact UTF-8 text; required without source
language Optional python, json, javascript, jsx, typescript, tsx, go, java, csharp, dart, unknown; inferred from extension otherwise
complete True for full files (default); false for fragments
start_line Original line represented by first line; default 1, must equal 1 for complete files

A supplied source and digest must match. Same-digest entries additionally need matching language, completeness, offset and review profile to skip an already reviewed file. Missing review stamp triggers analysis when source is supplied. Use recheck_unchanged: true to request another pass, and complexity_threshold to change the Python heuristic (2–50, default 10).

Status / coverage Meaning
added, changed Identity metadata differs from previous manifest
unchanged Identity metadata matches; may be checked if previously unchecked
removed Not included in an explicitly complete inventory
omitted_unknown Missing from a partial batch; prior metadata retained, current identity unknown
checked_complete / checked_fragment Source was analyzed in this call; fragment results only cover text supplied
not_rechecked Previously supplied review stamp and matching profile/digest; no analysis this call
unknown_digest_only / unknown_unsupported_language / unknown_input_limit / unknown_parser_unavailable No syntax result available

Outputs include per-file coverage, syntax status or null, finding counts, targeted test suggestions, deduplicated findings sorted by severity, and an updated metadata-only manifest.

New in 0.3: provide the previous report's open_findings array as previous_findings alongside previous_manifest. The existing findings array remains changed-only for backward compatibility. A separate open_findings array contains new findings (state: current) and supplied prior findings that remain relevant or uncertain (carried_unchanged, carried_unknown). A complete successful syntax review below the per-file finding cap replaces prior findings for that file; explicit removal clears them. Partial/unknown/invalid reviews preserve prior observations conservatively. omitted_open_findings reports the aggregate cap; preserve uncapped records separately if needed. A stamp saying reviewed: true means reviewed, not clean; stamps from callers are not independently verified. A null syntax result never means a pass.

Use complete_snapshot: true only when the supplied list represents the full inventory; otherwise omission never means deletion. Snapshot requests cap each manifest at 100 entries, each source at 256 KiB/6,000 LF-delimited lines, and combined raw source at 1 MiB. JSON nesting is capped at 100. Up to 100 distinct findings are returned per review; snapshot reports aggregate omitted findings from available per-source results. Run a focused direct review if a source's own cap is reached.

Example stdin request: examples/snapshot.json. The host can retain the returned manifest between calls; PatchPilot does not persist it.

export_sarif

Converts an explicitly supplied findings array (including snapshot open_findings) to SARIF 2.1.0. Ordinary review rule identifiers, severity, source labels/locations, evidence designation and stable fingerprints are retained. The CLI patchpilot sarif accepts a findings array or a report object from stdin and writes SARIF JSON to stdout. No reports are written to disk automatically and no vulnerabilities or security claims are generated.

What is new in 0.4

Supply the post-edit file alongside the exact diff, instead of reviewing standalone snippets alone. Added files must match the entire supplied source. Existing files require matching hunk text and coordinates; a supplied baseline additionally verifies outside-hunk text. Unknown input, missing sources and capped findings/diagnostics are not represented as a complete review. A full-file syntax error is reported even outside changed lines.

python -m patchpilot changed < examples/changed.json
python -m patchpilot source < examples/source.json
python -m patchpilot signature < examples/signature.json
python -m patchpilot changed < examples/changed.json > review.json
New MCP tool Explicit request fields Contract
review_source source, path, optional language, config_toml, complete, start_line, complexity_threshold Language-specific structured observations; syntax is nullable if unsupported/unavailable.
review_changed diff, entries, optional config_toml Entries contain path, source, optional previous_source and language. Changed-line, immutable full-file syntax, and outside-line findings are separated.
compare_call_signature call_source, signature, optional language Compares explicit simple direct calls to a supplied Python parameter or JS positional contract. No dynamic/import/type resolution.
import_external_sarif sarif_text, optional diff Normalizes already-generated SARIF metadata only. External provenance is unverified; separate locations/results retained; unresolved labels not discarded.
compact_report report, optional max_findings (1–50 per group) Prioritizes severity; retains hidden known counts, omitted unknown-severity counts and unknown coverage. Retain full reports for future review.
suggest_formatting_patch diff, entries Suggests ordinary formatting-only trailing whitespace corrections for context-validated LF Python/JSON where syntax/AST equivalence checks permit; never applies a patch.

review_changed exposes coverage_complete, findings, outside_changed_findings, suppressed_findings, policy_diagnostics, per-group omission counts and file coverage. Only a matching supplied baseline can mark an unchanged observation preexisting_verified. Without it, observations outside added lines remain outside_changed_lines_unverified; a matching baseline may instead indicate newly observed behavior. coverage_complete refers to the explicitly supplied scope, not proof that code works. Check active findings and tests separately.

Explicit rule policy

Supply this TOML string as config_toml with each relevant call. The tool does not load configuration automatically.

[review]
complexity_threshold = 12
[rules]
MUTABLE_DEFAULT = "warning"
[path_rules."tests/*".rules]
POSSIBLY_UNUSED_LOCAL = "off"

Inline # patchpilot: ignore=MUTABLE_DEFAULT reason="intentional shared default" (or an actual // comment in JS/TS) applies only to a matching heuristic on the same line. Suppressions and invalid or unmatched directives are reported. Parse errors cannot be suppressed; a factual finding cannot be disabled.

Language coverage and interoperable output

Go, Java, C# and Dart have syntax-only Tree-sitter coverage through review_source, review_changed and review_snapshot. JS/TS additionally has conservative duplicate simple lexical declarations and directly unreachable statement hints. No compiler typechecking, cross-file reference analysis or framework-specific validation. Unsupported grammars explicitly return unknown. The manually selected MCP prompt bounded_review explains the incremental workflow; it is not applied automatically. Versioned result schemas are generated without connectivity and conformance is tested over actual MCP stdio.

How it complements other tools

Tool Scope
PatchPilot Caller-supplied diff and source, changed-line context, bounded quality heuristics and retained metadata.
Ruff Python linter and formatter with a broader Python rule catalog; use separately when appropriate.
Semgrep Separate pattern analysis engine with a much larger rule ecosystem. PatchPilot does not perform its scanning or reproduce its findings.

PatchPilot is not a replacement for compilers, project tests, dedicated linters or reviewed security tools. It does not estimate provider billing or guarantee savings.

See optional workflows for manual pre-commit, a local container, MCP host configurations and handling a previously reviewed SARIF artifact. These are examples, not evidence of an executed CI, container build, or host installation.

Measured changed-only performance (v0.4.0)

On a synthetic 60-file project, two edited files, the earlier v0.4.0 benchmark compares fresh full source input with a caller-retained incremental manifest. Both paths send the same explicit diff, produce equal complete manifests and matching open-finding identities; 58 unchanged files are not freshly analyzed.

Measured input / local CLI latency Full Incremental
UTF-8 bytes 272,833 29,393
Input tokens (tiktoken 0.14.0, o200k_base) 76,427 11,149
Median local CLI wall time (11 repeats) 330.924 ms 106.526 ms

85.4% fewer measured tokenizer input tokens and a 3.11× full-to-incremental latency ratio in this synthetic workload. A one-time full baseline is required. This is not actual billed API usage, model latency, real-world accuracy, or a general guarantee. See benchmark methodology and reproducible inputs.

A separate hand-labeled check of three benign public commits (six file snapshots) matched both expected unused-import observations and reported no unexpected findings on that tiny selected sample; not a general false-positive estimate.

Instruction template for coding agents

Add the following to your project-specific Codex/Claude instructions if you want a review after every edit:

After each edit (including new code):
1. Supply only the current unified diff to PatchPilot review_diff.
2. Supply the changed full source with review_changed, and the matching
   previous_source where available. If only a fragment is available, use
   review_source with the correct offset and complete=false.
3. Review changed JSON with review_json and JS/TS/JSX/TSX with
   review_javascript. For repeated batches, carry the
   review_snapshot manifest forward and inspect previously unknown coverage.
4. Report error-level findings first; validate warnings and heuristics
   against the surrounding behavior before changing anything.
5. Fix verified problems, preserving existing behavior and scope.
   Re-run both reviews on the revised change. Run the smallest relevant
   project test set using the project's normal test tooling.
6. Finish with a summary of findings addressed, remaining limitations,
   and actual test results. Never claim tests passed unless they ran.

This is a caller-side convention, not an automatic watcher or enforcement hook. Python, JSON and JS/JSX/TS/TSX have the documented language-specific checks. Go, Java, C# and Dart have grammar-only coverage using installed parsers; other languages are unknown. Unknown coverage is not a syntax pass.

Boundaries

  • Each input is capped at 256 KiB and 6,000 lines. Diff sections: 100. Python AST: 20,000 nodes. Findings: 100. Test-plan line targets: first 30 added and first 30 removed lines per file, separately.
  • Standard text unified diffs with file headers and hunks, Git C-style quoted UTF-8 labels, rename and mode-only metadata are supported. Binary, copy, non-UTF-8 labels and combined diffs are unsupported. File labels are never opened; timestamps are supported only when tab-separated.
  • Syntactically valid code can still be wrong. Code fragments depending on omitted context may report syntax errors in isolation. Import hints are conservative, cannot resolve dynamic references or side effects, and must not be interpreted as proof of dead code.
  • No type checking, dependency analysis, whole-project context, runtime behavior validation, vulnerability discovery, test execution, automatic editing or general autoformatting. A formatting-only suggestion may remove trailing whitespace from verified changed lines without applying it.
  • Do not supply secrets or personal data. PatchPilot works with input text only, but the caller controls how text reaches its MCP host.

Development

python -m pip install ".[test]"
ruff check patchpilot tests tools benchmarks
black --check patchpilot tests tools benchmarks
python -m unittest discover -s tests -v
python tools/generate_schemas.py --check
python -m tools.self_check

The maintainer-only quality gate reviews this repository’s Python package, tests, tools and benchmark scripts at the normal threshold without an allowlist or a raised threshold. It fails on every finding, unknown coverage, omission or suppression; it is a scoped static check, not a correctness proof.

Tests cover diff parsing, exact line mapping, malformed and bounded inputs, Python syntax/context, branch score, dictionary keys, definition and import hints, JSON grammar and duplicate coordinates, changed-only snapshot behavior, profile changes, digest-only coverage, findings caps and stable IDs, CLI output and the official MCP client over a real stdio session. Static grammar checks and five Hypothesis properties (four × 75 and one × 50 generated examples). See the release evidence for actual test counts, coverage and limitations. Docker, pre-commit runner and desktop MCP hosts have not been tested here. The GitHub Actions workflow is configured for Python 3.10 and 3.12 on Linux, Windows and macOS; consult actual workflow results.

Distribution status and migration

Version 0.4.1 preserves all twelve tools and older public Python imports while splitting analysis implementation. Version 0.4.0 introduced six additional tools and one manually selected prompt; 0.4.1 retains these and the manifest fields. Review profiles now include 0.4.1 and explicit rule policy, so old review stamps will not skip a changed-rule review; resupply source for full coverage. See CHANGELOG.md.

The server.json follows the official MCP Registry schema and prepares future distribution through PyPI. It is metadata only; this 0.4.1 release has not been published or listed in the registry. Install from source as shown above. A manually dispatched release workflow is prepared for future PyPI trusted publishing; it does not publish on pushes and requires an explicitly enabled publish input plus authorized PyPI trusted-publisher configuration.

MIT licensed. See LICENSE and THIRD_PARTY.md.

Metadata

Release files for patchpilot-mcp 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for patchpilot-mcp 0.4.1
File Size Uploaded Provenance Actions
patchpilot_mcp-0.4.1.tar.gz 586.4 kB With provenance Details for patchpilot_mcp-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for patchpilot-mcp 0.4.1
File Interpreter ABI Platform Actions
patchpilot_mcp-0.4.1-py3-none-any.whl Python 3 none any Details for patchpilot_mcp-0.4.1-py3-none-any.whl

Total release size: 646.5 kB

Release files / patchpilot_mcp-0.4.1.tar.gz

Download URL patchpilot_mcp-0.4.1.tar.gz
Size 586.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0b6b749d018cf147c75784efb499e876fe5084f7db20353e3ac98e354a7b964a
BLAKE2b-256 checksum
How to use checksums
f6d1a6165686e39782cb6bb7c748492274b858769b6ebbf0c26ccdce2d462c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / patchpilot_mcp-0.4.1-py3-none-any.whl

Download URL patchpilot_mcp-0.4.1-py3-none-any.whl
Size 60.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a78913dd04e934d855086be28f4b5657f2217b020fb0a521d051744626d09ba
BLAKE2b-256 checksum
How to use checksums
0f3c3391240727cfa0f130ce134342bf42e57475d6b2e8a9240bcf11ea8dc9dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for patchpilot-mcp 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for patchpilot_mcp-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page