refact-mcp
Enables static analysis and conservative AST refactorings for TypeScript repositories, including dependency graphs, cycle detection, symbol/reference indexes, move/rename operations, and typecheck/Public API verification gates.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
refact-mcp
Read-only TypeScript architecture analysis and conservative, rollback-safe micro-refactoring tool with thin CLI and MCP interfaces.
Positioning & Explicit Non-Goals (v1)
What refact-mcp does:
Analyzes TypeScript repositories without executing target code: dependency graph, Tarjan SCC cycles, hotspot metrics, line-independent
SymbolIdindex, semantic references, Public API snapshots, static blind spots (ResidualUnknown), and bottom-up micro-refactor plans.Applies conservative, fail-closed AST refactorings (
moveSymbol,renameSymbol) inside an isolated temporary Git worktree, verified by multi-evidence gates (TypeCheckGate,PublicApiGate, and opt-inProjectTestGate) before fast-forward merging back to the main branch—or rolling back cleanly on failure.
Explicit v1 non-goals:
TypeScript only: No support for other languages; unsupported or ambiguous TypeScript syntax is rejected fail-closed rather than best-effort rewritten.
Not an OS security sandbox: Git worktrees and sanitized child processes provide working-tree rollback isolation, not security confinement against malicious target code.
No mathematical proof of zero behavior change: Passing typechecking, Public API comparison, and finite project tests provides multi-evidence confidence, not a formal proof.
No implicit execution or destructive Git operations: Never runs
npm test,npm install, lifecycle scripts,git push, orgit reset --hardwithout explicit authorization.
Related MCP server: TypeScript AST MCP Server
Requirements & Installation
Node.js
>= 22.0.0Git (required for write refactoring worktree transactions; read-only analysis works with or without Git)
# Local development / from source
git clone https://github.com/realcarsonterry/refact-mcp.git
cd refact-mcp
npm ci
npm run build
# Run CLI directly from build artifacts
node dist/composition/cliEntry.js --helpOr run via npx once published:
npx -y refact-mcp doctor .Quick Start
1. CLI Examples
# Workspace health & revision fingerprint (read-only)
refact-mcp doctor ./fixtures/messy-monolith
# Dependency graph, Tarjan cycles, hotspots & static unknowns (read-only)
refact-mcp analyze ./fixtures/messy-monolith --json
# Bottom-up micro-refactor plan isolating cycles and blocking unknowns (read-only)
refact-mcp plan ./fixtures/messy-monolith
# Verification gates (test execution blocked unless --allow-exec is explicitly passed)
refact-mcp verify ./fixtures/messy-monolith
refact-mcp verify ./fixtures/messy-monolith --allow-exec
# Dry-run preview of an atomic moveSymbol or renameSymbol (zero writes)
refact-mcp refactor move ./fixtures/messy-monolith \
--symbol "sym:v1|src/godService.ts|function|buildCustomerNotice" \
--to src/customerNotice.ts --dry-run
refact-mcp refactor rename ./fixtures/messy-monolith \
--symbol "sym:v1|src/godService.ts|function|buildCustomerNotice" \
--new-name formatCustomerNotice --dry-run
# Safely preview or register refact-mcp in a verified MCP client config
refact-mcp setup --client cursor --dry-run
refact-mcp setup --client claude --config-path /path/to/claude_desktop_config.json2. MCP Server Configuration
refact-mcp exposes an MCP stdio server via refact-mcp serve (or the dedicated binary refact-mcp-server). stdout is 100% reserved for JSON-RPC frames; all logs go to stderr.
{
"mcpServers": {
"refact-mcp": {
"command": "npx",
"args": ["-y", "refact-mcp", "serve"]
}
}
}Use
refact-mcp setup --client cursor --dry-run(or--client claude) to preview config installation.setuprefuses JSONC files containing comments/trailing commas, never silently overwrites a differing existingrefact-mcpentry without--overwrite-existing, and backs up existing files before atomic replacement.
CLI Commands & MCP Tools
CLI Commands
Command | Mode | Description |
| Read-only | Inspect workspace boundary, tsconfig, Git cleanliness, and revision fingerprint |
| Read-only | Compute dependency graph, Tarjan SCC cycles, hotspots, and static unknowns |
| Read-only | Generate conservative bottom-up refactor plan isolating cycles and blocking unknowns |
| Read-only (opt-in test exec) | Run multi-evidence verification gates ( |
| Write (supports | Rollback-safe Git worktree |
| Write (supports | Rollback-safe Git worktree |
| Config write (supports | Safely register |
| MCP stdio | Start MCP stdio server |
MCP Tools
Tool | Mode | Key Parameters |
| Read-only |
|
| Read-only |
|
| Read-only |
|
| Read-only |
|
| Read-only |
|
| Read-only |
|
| Write ( |
|
| Read-only |
|
An agent workflow skill matching these exact tools is shipped at .agents/skills/monolith-refactor/SKILL.md.
Architecture Overview
refact-mcp enforces unidirectional layering, zero cycles, public.ts-only cross-module encapsulation, and function/file complexity limits via dependency-cruiser + ESLint (npm run lint:arch && npm run lint).
flowchart LR
composition["composition/ (wiring root)"] --> cli["adapters/cli"]
composition --> mcp["adapters/mcp"]
composition --> workflows["workflows/ (orchestration + evidence + setup)"]
composition --> modules["modules/*/public.ts"]
composition --> platform["platform/ (fs, process, git-cli, ts-project, config)"]
cli --> workflows
mcp --> workflows
workflows -. "narrow ports" .-> modules
modules --> platform
modules --> shared["shared/ (zero-dep value objects)"]
platform --> sharedSee ARCHITECTURE.md for the complete module graph and dependency rules.
Supported AST Transformations
moveSymbol: Top-level namedfunction,interface,type, and pure single-identifierconst. Refuses private dependencies (never auto-addsexport), module mutable state, position-sensitive semantics (import.meta,__dirname,eval, dynamicimport()), top-level side effects, overloads, declaration merging, classes, default exports, and cycle introduction.renameSymbol: Top-level namedfunction,class,interface,type, and single-identifier variable via TypeScript Language Service semantic rename locations. Preserves import/export aliases, object property shorthands ({ foo }->{ foo: newName }), and namespace destructuring while refusing scope shadowing/capture, dynamic reflection, and unapproved Public API breaks.
Full support and fail-closed rejection matrix: docs/supported-transformations.md.
Verification States & Decisions
Each verification gate (typecheck, public_api, project_tests) reports one of 5 honest states:
Gate State | Meaning |
| Gate executed and met all pass criteria |
| Regression detected (new TS diagnostics, Public API removal/change, or non-zero test exit) |
| Gate intentionally not applicable (e.g., |
| Requires explicit execution authorization ( |
| Environment/fingerprint mismatch or unexpected error prevented a reliable verdict |
Aggregated verification decisions:
safe_to_commit: All required gatespassed(never masksskipped/needs_approval/inconclusiveaspassed).blocked: At least one gatefailed.requires_human_approval: No gate failed, but at least one required gate isneeds_approval.inconclusive: No gate failed, but a required gate isinconclusiveor could not complete.
Worktree Dependencies, Security Risks & Recovery
Worktree dependency resolution: Worktrees do not symlink
node_modules/from your main workspace to avoid cache/file leakage. Read docs/adr/ADR-0001-worktree-dependencies.md for the three explicit strategies (none,node-path-readonly,explicit-install).Security model & static blind spots: Read docs/security-and-limitations.md and SECURITY.md.
Manual recovery (stale worktrees or
committed_with_cleanup_warning): Read docs/worktree-recovery.md.
Development & Verification
npm ci
npm run check # lint:arch && lint && typecheck && test && buildLicense
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Stateless TS/JS compiler facts for agents: references, imports, impact. No repo index or OAuth.
Ask a codebase what calls what: search, blast radius, paths between symbols, and diffs.
Ask who calls a route, what a change breaks or who reads a field, across a system's repos.
Deterministic context layer for your codebase: change impact, blast radius, answers with receipts.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceProvides read-only code analysis and safe, reversible code refactoring with proven edit plans, previews, and rollback.1MIT
- AlicenseAqualityDmaintenanceProvides deep structural analysis of TypeScript and JavaScript code via the TypeScript Compiler API, offering 20 tools for functions, types, call graphs, code quality, dead code detection, and IDE integration.2067 npm1MIT
- AlicenseAqualityNot gradedmaintenanceProvides read-only structural analysis of codebases, surfacing architecture smells with traffic-light ratings and rendering dependency relationships as Mermaid flowcharts.4MIT
- AlicenseBqualityBmaintenanceEnables coding agents to query a static AST-based call graph for TypeScript/JavaScript repositories, including who-calls, impact analysis, entry-to-dependency traces, hotspots, symbol search, and git-blame archaeology, with every result backed by source evidence chains.91MIT