safe-fix-mcp
safe-fix-mcp
Pythonリポジトリ内のデッドコードを検出し、自動削除しても実際に安全な唯一の種類の検出結果(単一の名前だけをインポートする行の未使用インポート)についてブランチ + PRを提案する、実際のMCPサーバーです。それ以外に検出されるもの(未使用の関数、クラス、未使用の依存関係)はレポートのみに留まります。マージは常に人間が行います。このツール自体が何かをマージすることは決してありません。
なぜこれが存在するのか
ほとんどの「デッドコード」ツールはレポートを出すだけで終わります。さらに踏み込むツールは、通常は安全策なしに削除します。これはどちらでもありません。削除後にターゲットリポジトリ自身の完全なテストスイートが実際に通ることを条件に、実際の、最小限の、レビュー可能なPRのドラフトを作成します。ヒューリスティックではなく、実際のpytestの実行です。スイートが失敗した場合は、何もコミットもプッシュもされず、リポジトリは開始時とまったく同じ状態のままになります。
Related MCP server: Python Code Guardian MCP Server
ツール
scan_dead_code(repo_path=".", min_confidence=60)
読み取り専用です。vulture(デッドコード)とdeptry(依存関係の問題)を実行し、人間が読める形式の検出結果リストを返します。何も変更しません。
propose_removal_pr(repo_path=".")
作業ツリーが汚れている場合は拒否します。未コミットの作業の上で編集することは決してありません。
単一の名前だけをインポートする行のうち、vultureの信頼度が90%以上の未使用インポートのみに絞り込みます(
from x import y, zはスキップされます。行全体を削除するとzも黙って削除されてしまうためです)。実際のブランチを作成し、条件に合うインポートを削除し、リポジトリの実際の完全なテストスイートを実行します。
実際に成功した場合のみ、コミット、プッシュ、そして
gh pr createによるPRのオープンを試みます。ghがインストールされていない、または認証されていない場合でも、ブランチは実際にコミット・プッシュされます。低下するのはPR作成だけであり、実際のエラーが返されるため、手動でPRを開くことができます。
インストール
pip install -e .MCPクライアントの設定に追加します(例: Claude Code):
claude mcp add safe-fix-mcp -- safe-fix-mcpまたは、ローカルテスト用に直接実行します:
python -m safe_fix_mcp.server要件
Python ≥ 3.10
PATHに
gitがあることpropose_removal_prで実際にPRを開きたい場合は、PATHにgh(GitHub CLI)があり、認証済みであること — これがない場合でも、ブランチは実際にプッシュされ、ツールが手動でPRを開くように指示します。
開発
pip install -e ".[dev]"
pytest既知の制限
vultureはscan_dead_code/propose_removal_pr自体を「未使用」とフラグ付けします。これは既知の誤検知の一種であり、実際のバグではありません。これらは実行時に@mcp.tool()デコレータによってディスパッチされ、ソース内のどこからも直接呼び出されないため、静的コールグラフ解析では実際の呼び出し元(MCPフレームワーク自体)を確認できないのです。
実際に検証する
scripts/verify_real_client.pyは、パッケージ化されたサーバーを実際のサブプロセスとして起動し、実際のmcp.client.ClientSessionを使って通信します。これは実際のMCPクライアントが使用するのと同じ経路です。変更後のスモークテストとして役立ちます:
python scripts/verify_real_client.pyAvailable Tools
2 toolspropose_removal_prA
Propose a real branch+PR removing only unused imports (single-name
import lines, >= 90% vulture confidence) from a Python repository. Runs
the repo's own full test suite as a safety gate before ever committing
or pushing — a failure there reverts everything and nothing is
committed or pushed. If gh isn't available or PR creation otherwise
fails, the branch is still committed and pushed for real; only the PR
itself needs opening manually. A human always merges — this never
merges anything itself.
repo_path: path to a real git repository with a clean working tree (uncommitted changes are refused, not overwritten).
Inputs: repo_path. Returns: result
scan_dead_codeA
Scan a Python repository for real dead code (vulture) and dependency issues (deptry). Read-only — never modifies anything. Returns a human-readable list of findings, or "No real candidates found."
repo_path: path to the repository to scan (must contain a pyproject.toml for the dependency checks to run; dead-code scanning works regardless). min_confidence: vulture's own confidence threshold (0-100). Lower values surface more candidates but more false positives.
Inputs: repo_path, min_confidence. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
scan_dead_code is purely read-only analysis, while propose_removal_pr actually creates a branch and PR. Their purposes are complementary and unlikely to be confused.
Both tool names use lower_snake verb-first conventions: scan_dead_code and propose_removal_pr. The pattern is predictable, though the second name is slightly less clean because 'removal_pr' bundles an action and an object into one noun phrase.
Two tools is on the thin side and sits at the borderline of feeling complete. However, each tool has a distinct role in a focused analyze-then-propose workflow, so the small count is plausible for a narrow server.
The scan surfaces both dead code and dependency issues, but propose_removal_pr only handles unused imports. Dependency fixes and non-import dead-code removals are therefore dead ends, creating a notable gap in the advertised safe-fix domain.
Maintenance
Related MCP Connectors
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Screens public GitHub repos and PRs to generate risk maps, findings, and merge-readiness signals.
Scan a public GitHub repo for known Vercel Python-runtime deploy footguns.
Security + bug + perf + refactor audit for Python. Returns 0-10 score + MD report.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables automated code review and GitHub PR commenting through MCP integration.1,175 npm9MIT
- AlicenseNot gradedqualityCmaintenanceEnables automated Python code quality checks including linting, complexity analysis, typo detection, structure validation, duplicate detection, and test coverage, with integration into Cursor IDE and CLI.MIT
- AlicenseNot gradedqualityDmaintenanceEnables scanning projects for dependency vulnerabilities, secrets, license conflicts, code quality, and git health, returning a 0-100 health score with actionable suggestions.MIT
- FlicenseNot gradedqualityBmaintenanceEnables whole-program callgraph reachability analysis to locate dead functions and stale flags, and integrates with MCP-compliant clients for automated code review, breaking-change audits, and CI/CD workflow pruning.8-