scalpel-mcp
Surgical AST-based Python editing for AI agents — edit by symbol name, not text position. Built-in blast radius and token cost on every edit.
pip install scalpel-mcp
Why
AI coding agents (Claude Code, Cursor, Aider) edit Python via string replacement or line numbers. This forces the agent to echo the old code to locate the edit, then echo the entire new file as output. On large files that wastes thousands of tokens per edit.
Scalpel exposes four MCP tools that operate on symbol names:
edit_function_body("auth.py", "validate_token", new_body)
No echoing. No stale line numbers. Every edit returns a diff, a blast radius score, and a token cost — automatically.
Benchmark
Measured on 406 real functions across 10 popular OSS projects (requests, flask, fastapi, django, httpx, pydantic, black, click, rich). All files verified with libcst round-trip.
| Scenario | str_replace | Scalpel | Reduction |
|---|---|---|---|
| Single edit — 406 functions total | 36,907 tokens | 18,674 tokens | 49.4% |
| 5 edits / same file — 10 files total | 70,948 tokens | 2,039 tokens | 95.4% |
The multi-edit gap is large because str_replace pays the full file on every call. Scalpel pays for read_structure once and only the function name + new body per subsequent edit.
MCP Tools
| Tool | What it does |
|---|---|
read_structure |
File skeleton — signatures and line ranges, no bodies. ~3.4× cheaper than reading the file. |
edit_function_body |
Replace a top-level function body by name. Writes to disk. Returns diff + metrics. |
edit_class_method |
Replace a class method body by name. Writes to disk. Returns diff + metrics. |
measure_edit |
Dry-run: compute blast radius and token cost without writing. |
Metrics returned on every edit
- blast_radius — fraction of the file's symbols whose signature changed (0.0 = nothing changed structurally)
- patch_locality — how contained the edit is (1.0 = perfectly local)
- token_cost — tiktoken count of input + diff output
Install
pip install scalpel-mcp
scalpel install-skill
Then restart Claude Code. Scalpel tools will be available automatically.
The second command:
- Copies the Claude Code skill to
.claude/SKILL.md - Registers the MCP server in
.claude/settings.json - After restart, Claude Code knows when and how to use all 4 tools
Optimal workflow
1. read_structure(file_path) → locate symbols, costs ~200 tokens
2. measure_edit(file_path, fn, body) → dry run, check blast_radius
3. edit_function_body / edit_class_method → write if metrics look good
4. Check result: success, diff, blast_radius, patch_locality, token_cost
For multiple edits on the same file, call read_structure once and skip measure_edit — the multi-edit token reduction reaches 95.4%.
Requirements
- Python ≥ 3.12
- Works with any MCP-compatible host (Claude Code, Continue, custom agents)
License
MIT
Metadata
Release files for scalpel-mcp 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scalpel_mcp-0.1.3.tar.gz | 248.1 kB | Without provenance | Details for scalpel_mcp-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scalpel_mcp-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for scalpel_mcp-0.1.3-py3-none-any.whl |
Total release size: 260.3 kB
Release files / scalpel_mcp-0.1.3.tar.gz
| Download URL | scalpel_mcp-0.1.3.tar.gz |
|---|---|
| Size | 248.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4219307f79df70f4f13d900cecaf7a0392a37c0fefcc4957ece4268b1167e4b2
|
|
BLAKE2b-256 checksum How to use checksums |
233637da94ad8edc37d2ba9613f70012945c37f0f603bbb00a78aef3d96a8650
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / scalpel_mcp-0.1.3-py3-none-any.whl
| Download URL | scalpel_mcp-0.1.3-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf1129442a220ed06191990e117aea07f955d4267680a0ca3aeada0af11c5405
|
|
BLAKE2b-256 checksum How to use checksums |
bc2b4d3b9d975df846683a1cfd79452aa044529549333ea98130e31d0b464c61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for scalpel-mcp 0.1.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.