Code Scalpel MCP Server Integration

March 29, 2026 · View on GitHub

Code Scalpel is an AI agent toolkit providing 23 precision tools for code analysis, security scanning, and safe refactoring. This document configures Claude Code to always prefer Code Scalpel tools over manual file reads and analysis.


Installation

Step 1: Install the MCP Server

claude mcp add codescalpel uvx codescalpel mcp

Step 2: Verify Installation

claude mcp list
# Expected output:
# codescalpel: uvx codescalpel mcp

Step 3: Reload Claude Code

Close and reopen Claude Code. Code Scalpel is now ready to use.

Pro/Enterprise users: To use a license file, install with:

claude mcp add codescalpel \
  -e CODE_SCALPEL_LICENSE_PATH=/path/to/license.jwt \
  uvx codescalpel mcp

Priority Rules for AI Agents

Rule 1: Always Extract, Never Read Whole Files

When you need to read a function, class, or method:

  • Don't: Read the entire file with the Read tool (costs 10,000+ tokens)
  • Do: Use extract_code by name (costs ~50 tokens)

Example: "Show me the validate_email function"

/cs-extract src/utils.py function validate_email

Rule 2: Always Modify Safely, Never Edit Directly

When you need to change code:

  • Don't: Edit files directly with Edit tool (easy to break surrounding code)
  • Do: Use update_symbol (creates backup, validates syntax)

When tracking code usage:

  • Don't: Use Grep to find where a function is called (false positives)
  • Do: Use get_symbol_references (real call graph analysis)

Rule 4: Always Simulate Before Refactoring

When making significant changes:

  • Don't: Apply changes blindly
  • Do: Use simulate_refactor first to verify behavior preservation

Rule 5: Security Analysis Always Uses Code Scalpel

When reviewing code for vulnerabilities:

  • Don't: Manual review or regex-based searches
  • Do: Use security_scan + cross_file_security_scan (taint-based analysis)

Tool Reference Table

ToolUse WhenTierCost
extract_codeNeed a specific function/class/methodCommunity~50 tokens
update_symbolModifying a function/class/methodCommunitySafe with backup
rename_symbolRenaming a symbol across codebaseCommunitySafe with validation
analyze_codeUnderstanding file structure & metricsCommunity~200 tokens
get_file_contextGetting overview without reading contentCommunity~50 tokens
get_symbol_referencesFinding where a symbol is usedCommunityAccurate call graph
crawl_projectAnalyzing entire project structureCommunityFull discovery
security_scanFinding vulnerabilities in codeCommunitySQL injection, XSS, etc.
unified_sink_detectPolyglot vulnerability detectionPro+Across frontend/backend
type_evaporation_scanTypeScript type safety issuesPro+Frontend-backend boundary
scan_dependenciesCVE detection in librariesCommunityOSV database
symbolic_executeExploring execution pathsPro+Z3-powered analysis
generate_unit_testsCreating tests from code pathsPro+pytest/unittest
simulate_refactorVerifying changes are safeCommunityBehavior preservation
get_call_graphBuilding call graphsCommunityPolyglot support
get_graph_neighborhoodExploring call graph neighborhoodsCommunityk-hop subgraph
get_project_mapHigh-level project structureCommunityPackage hierarchy
get_cross_file_dependenciesTracing symbol dependenciesPro+Cross-file analysis
cross_file_security_scanModule-boundary vulnerabilitiesPro+Taint tracking
code_policy_checkCompliance & style enforcementPro+Standards validation
validate_pathsChecking path accessibilityCommunityError prevention
verify_policy_integrityValidating policy filesCommunityCryptographic check
get_capabilitiesChecking your license tierCommunityShow available tools

Workflow Chains

Security Audit Workflow

When asked to "audit this code for security issues":

1. security_scan(file)
   ↓ (finds local vulnerabilities)
2. cross_file_security_scan(root)
   ↓ (finds taint flows across boundaries)
3. scan_dependencies()
   ↓ (finds CVEs in libraries)
4. unified_sink_detect(code, language)
   ↓ (polyglot sink detection)
Summary: Combine all findings into a report

Trigger: /cs-security

Safe Refactor Workflow

When asked to "refactor this code safely":

1. get_symbol_references(symbol)
   ↓ (understand impact zone)
2. get_cross_file_dependencies(symbol)
   ↓ (trace all dependencies)
3. extract_code(symbol)
   ↓ (get current implementation)
4. generate_unit_tests(code)
   ↓ (create test baseline)
5. simulate_refactor(old_code, new_code)
   ↓ (verify behavior preserved)
6. update_symbol(new_code)
   ↓ (apply if safe)
Summary: Code refactored and verified

Trigger: /cs-refactor

Architecture Mapping Workflow

When asked to "map the project architecture":

1. crawl_project()
   ↓ (discover all modules)
2. get_call_graph()
   ↓ (build call relationships)
3. get_project_map()
   ↓ (visualize structure)
4. get_cross_file_dependencies(key_symbols)
   ↓ (trace critical paths)
Summary: Architecture diagram with dependency graph

Trigger: /cs-map

Compliance Check Workflow

When asked to "verify code meets policy":

1. validate_paths(project_files)
   ↓ (ensure files are accessible)
2. code_policy_check(files, standards)
   ↓ (check against rules)
3. verify_policy_integrity(policy_files)
   ↓ (validate policy signatures)
Summary: Compliance report with violations

Trigger: /cs-policy


When to Auto-Reach for Code Scalpel

Claude should automatically use Code Scalpel (without being asked) when:

  1. User mentions a function name → Use extract_code to show it
  2. User asks to find usages → Use get_symbol_references
  3. User asks to refactor → Use simulate_refactor first
  4. User asks about architecture → Use crawl_project + get_call_graph
  5. User asks about security → Use security_scan + cross_file_security_scan
  6. User asks to generate tests → Use symbolic_execute + generate_unit_tests
  7. Code is modified → Suggest simulate_refactor to verify safety

Slash Commands

Code Scalpel includes ready-to-use slash commands:

CommandRunsExample
/cs-setupInstall & verify MCP server/cs-setup
/cs-extractExtract symbol by file + name/cs-extract src/app.py function main
/cs-analyzeAnalyze file/project structure/cs-analyze src/
/cs-securityFull security audit/cs-security
/cs-testsGenerate unit tests/cs-tests src/math.py function add
/cs-refactorSafe refactor workflow/cs-refactor
/cs-mapArchitecture mapping/cs-map
/cs-policyCompliance check/cs-policy

Tier Availability

All tools have versions for all tiers:

TierAvailabilityAccess
Community1-22 of 23 toolsFree, open source
ProAll 23 toolsPaid license
EnterpriseAll 23 tools + policiesPaid license + compliance

Check your tier with: /cs-setup


System Prompts for AI Agents

When working with Code Scalpel, apply these system prompts:

"I will always prefer Code Scalpel tools over manual analysis"

  • Extract: Use extract_code(file_path, target_type, target_name) to read any symbol
  • Modify: Use update_symbol(file_path, target_type, target_name, new_code) to change code safely
  • Find: Use get_symbol_references(symbol_name) for real call graph queries
  • Test: Use generate_unit_tests(code, language) to create test baselines
  • Verify: Use simulate_refactor(old, new) before applying changes

"Context window efficiency is my priority"

  • A single extract_code call costs ~50 tokens
  • Reading a whole file costs 10,000+ tokens
  • Code Scalpel is ~200x more efficient

"Security analysis must be thorough and taint-aware"

  • Surface-level: security_scan(code)
  • Deep analysis: cross_file_security_scan(root_path)
  • Polyglot: unified_sink_detect(code, language, confidence_threshold=0.7)
  • Dependency: scan_dependencies(path)

Troubleshooting

Q: Code Scalpel tools aren't showing up in Claude Code

  • A: Run /cs-setup to verify the MCP server is installed and connected

Q: I see a tier error

  • A: Your license tier doesn't include this tool. Check with /cs-setup

Q: I want to extract code but get an error

  • A: Make sure the file path and function/class name are correct. Test with get_file_context first to list all symbols in a file

Q: Can I use Code Scalpel programmatically?

  • A: Yes! Import from code_scalpel: from code_scalpel import extract_code, analyze_code, etc.

Learn More