Skip to content

@elad12390/js-tools

1.0.0

TypeScript refactoring via js-tools-mcp. Smell-to-tool routing: deduplicate code, move exports, split large files, rename symbols, organize imports, create barrels, extract class methods, find references. Prefer over mcp_edit for structural changes. Triggers: refactor, move function, split file, rename, deduplicate, DRY, god file, blast radius, barrel, organize imports, typescript tools, js-tools.

js-tools — TypeScript Refactoring via MCP

Programmatic TypeScript refactoring tools that replace manual mcp_edit workflows. These tools understand the AST, update all imports project-wide, and support dry-run previews.

Always prefer these over manual file edits for any TypeScript structural change.

Smell-to-Tool Routing

When you detect a code smell, use this table to pick the right tool instead of reaching for mcp_edit:

SmellToolWhy not manual?
Same function/component in N filestypescript_extract_sharedRemoves all copies, creates shared module, updates imports across project
Function/export belongs in a different filetypescript_move_symbolsMoves code + rewrites every import automatically
File over 300-400 lines, mixed concernstypescript_split_fileSplits by strategy, creates barrel, updates imports
Need to rename a variable/function/classtypescript_renameFinds re-exports, type-only usages, barrel references that grep misses
Messy imports after refactoringtypescript_organize_importsRemoves unused, sorts, groups in one pass
Directory needs an index.tstypescript_create_barrelScans exports, separates types, handles default exports
Class method too complex / needs testingtypescript_extract_methodTransforms this references to instance param, preserves async/generics
Need to check what breaks before a changetypescript_find_referencesCatches re-exports and inherited methods that grep misses
What type does TypeScript infer here?typescript_get_typeLike IDE hover, accessible programmatically
Where is this symbol actually defined?typescript_go_to_definitionResolves through barrels and re-exports to actual source
What classes implement this interface?typescript_find_implementationsDistinguishes declarations from implementations (grep cannot)
What methods does this class have?typescript_list_membersReturns typed signatures with line:column for each member
What does this method depend on via this?typescript_analyze_depsDependency tree with circular ref detection
Unsure which tool to usetypescript_suggest_refactorDescribe smell in English, get tool + pre-filled args
TypeScript errors / does it compile?typescript_checkStructured errors with file:line:column, filterable by error code

Key Principle: dry_run First

Every destructive tool defaults to dry_run=true. Always preview, then apply:

1. Call tool with dry_run=true → review changes
2. If good, call again with dry_run=false → apply

Auto-Detection

All tools auto-detect project_root (walks up to find tsconfig.json) and tsconfig when omitted. You only need to pass file-specific parameters — the tools figure out the project context.

Common Workflows

Deduplicate code across files

1. typescript_extract_shared(symbol_name, source_files, target_file)
2. typescript_organize_imports on each modified file
3. typescript_check to verify

Break up a large file

1. typescript_split_file(source_file, strategy="group-by-kind")
2. typescript_create_barrel(directory) if needed
3. typescript_check to verify

Move exports between files

1. typescript_find_references first (blast radius check)
2. typescript_move_symbols(source_file, symbol_names, target_file)
3. typescript_organize_imports on affected files
4. typescript_check to verify

Safe rename

1. typescript_find_references (see all usages)
2. typescript_rename(file, line, column, new_name, dry_run=true)
3. Review preview, then dry_run=false

Extract and reorganize a class

1. typescript_list_members(file, class_name) → see structure
2. typescript_analyze_deps(file, class_name, method_name) → see coupling
3. typescript_extract_method(source_file, class_name, method_name, target_file)

Split Strategies

typescript_split_file supports three strategies:

StrategyCreatesBest for
one-per-exportOne file per export (groups dependents)Utility files with independent exports
group-by-kindfunctions.ts, types.ts, classes.tsMixed-concern files
group-by-prefixuser-utils.ts, order-utils.tsPrefixed naming conventions

Barrel Export Styles

typescript_create_barrel supports three styles:

StyleOutputAuto-selected when
namedexport { foo, bar } from './file.js'5 or fewer exports
starexport * from './file.js'More than 5 exports
autoChooses named or starDefault behavior

Reference Files

FileContents
references/tool-catalog.mdEvery tool's parameters, edge cases, and error handling
references/refactoring-workflows.mdMulti-step workflow recipes with real examples

Command Palette

Search skills, docs, and navigate Tank