rename_identifier, remove_unused_imports, insert_code and transform_code all accept preview, so the change can be read before it lands. The rename is structural rather than textual — the vendor states it avoids renaming inside strings and comments, which is exactly where a find-and-replace goes wrong. The one hard sequencing rule is that parse_code runs first, because everything else reads the AST state it loaded; transform_code is what batches several operations against that same state instead of reparsing between them.
A tree-hugger-js client with 12 tools that load a file or a source string into AST state, then query, analyse and transform it: pattern searches, function and class inventories, scope analysis, and refactoring operations.
- parse_code loads JavaScript or TypeScript from a file path or a string into AST state, and has to run before the other tools.
- Pattern queries in an intuitive syntax: find_pattern for the first match and find_all_pattern for every one, with selectors such as function[name="main"], function[async], comment[text*="TODO"] and call[text*="eval"].
- Structured inventories: get_functions with name, type, location and async status including class methods and arrow functions, get_classes with method and property analysis, and get_imports with module and specifier detail.
- Transformations that each take a preview flag: rename_identifier, which avoids renaming inside strings and comments, remove_unused_imports, insert_code before or after matching nodes with smart formatting, and transform_code for several operations in one pass.
- Positional and scope analysis: get_node_at_position for the AST node at a line and column, and analyze_scopes for variable bindings, shadowing and naming conflicts.
A JavaScript or TypeScript file or source string, loaded through parse_code before any other tool runs.
One command — npx tree-hugger-js-mcp
