Skip to main content

safe-fix-mcp

A real MCP server that finds dead code in a Python repository and proposes a branch + PR for the one class of finding that's actually safe to auto-remove: unused imports on a single-name import line. Everything else it finds — unused functions, classes, unused dependencies — stays report-only. A human always merges. This tool never merges anything itself.

Why this exists

Most "dead code" tools stop at reporting. The ones that go further usually delete with no safety net. This does neither: it drafts a real, minimal, reviewable PR, gated on the target repo's own full test suite actually passing after the removal — not a heuristic, a real pytest run. If the suite fails, nothing is committed or pushed; the repo is left exactly as it started.

Tools

scan_dead_code(repo_path=".", min_confidence=60)

Read-only. Runs vulture (dead code) and deptry (dependency issues) and returns a human-readable list of findings. Never modifies anything.

propose_removal_pr(repo_path=".")

  • Refuses on a dirty working tree — never edits on top of uncommitted work.
  • Filters to unused imports at ≥90% vulture confidence, on single-name import lines only (from x import y, z is skipped — removing the whole line would silently remove z too).
  • Creates a real branch, removes the qualifying imports, runs the repo's real full test suite.
  • Only on a real pass: commits, pushes, and tries to open a PR via gh pr create.
  • If gh isn't installed/authenticated, the branch is still committed and pushed for real — only PR creation degrades, with the real error returned so you can open it manually.

Install

pip install -e .

Add to your MCP client config (e.g. Claude Code):

claude mcp add safe-fix-mcp -- safe-fix-mcp

Or run directly for local testing:

python -m safe_fix_mcp.server

Requirements

  • Python ≥ 3.10
  • git on PATH
  • gh (GitHub CLI) on PATH and authenticated, if you want propose_removal_pr to actually open the PR — without it, the branch still gets pushed for real, and the tool tells you to open the PR by hand.

Development

pip install -e ".[dev]"
pytest

Known limitation

vulture flags scan_dead_code/propose_removal_pr themselves as "unused" — a known false-positive class, not a real bug: they're dispatched by the @mcp.tool() decorator at runtime, not called directly anywhere in the source, so static call-graph analysis can't see the real caller (the MCP framework itself).

Verifying it for real

scripts/verify_real_client.py launches the packaged server as a real subprocess and talks to it with the real mcp.client.ClientSession — the same path a real MCP client uses. Useful as a smoke test after any change:

python scripts/verify_real_client.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safe_fix_mcp-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safe_fix_mcp-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file safe_fix_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: safe_fix_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.9

File hashes

Hashes for safe_fix_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5f6b101c16f24e5d1b8fec4817e85d52fc608d454f763b110e11b0bbb3e3a147
MD5 7fb5e72b7c7fd8334f48a9ac4f13cd9a
BLAKE2b-256 cac83c4fb08c03393201bbaf086cf6d4b9c6d487b03b744e6c2c0644a3f03c96

See more details on using hashes here.

File details

Details for the file safe_fix_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safe_fix_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.9

File hashes

Hashes for safe_fix_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3657d35b5a9cd02585f4547cafbd5f8911c93e1e5b97f35ec97858f7c9b128c5
MD5 5ecea1211408250b8a8430f8569ab229
BLAKE2b-256 bc9e4c2dab3945bbcf8a4a63e4a5c887b2be7454d7f658c807f0764ab22ae4d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page