Provides powerful code analysis and transformation capabilities for JavaScript, enabling parsing, pattern matching, and manipulation of JavaScript code structure
Supports analysis of JSX elements and React components, with pattern matching capabilities specifically designed for React code structures
Enables analysis and transformation of TypeScript code, including handling of TypeScript-specific features like type imports
Tree-Hugger-JS MCP Server
An MCP (Model Context Protocol) server that provides AI agents with powerful JavaScript/TypeScript code analysis and transformation capabilities using the tree-hugger-js library.
Features
🔍 Code Analysis
- Parse JavaScript, TypeScript, JSX, and TSX files or code strings
- Find patterns using intuitive syntax (e.g.,
function
,class[name="MyClass"]
) - Extract functions, classes, imports with detailed metadata
- Navigate AST nodes and analyze code structure
- Get nodes at specific positions
🔧 Code Transformation
- Rename identifiers throughout code
- Remove unused imports
- Chain multiple transformations
- Insert code before/after patterns
- Preview transformations before applying
📊 Code Intelligence
- Scope analysis and variable binding
- Pattern matching with CSS-like selectors
- Support for async functions, classes, methods
- TypeScript type import handling
Installation & Usage
🚀 Quick Start (Recommended)
Try immediately with npx - no installation required:
📦 Global Installation
🔧 Development Setup
MCP Client Configuration
Using with Claude Code
Add to your MCP client configuration:
Alternative Configurations
Tools
Code Analysis Tools
parse_code
Parse JavaScript/TypeScript code from file or string.
Parameters:
source
(string): File path or code string to parseisFilePath
(boolean, optional): Whether source is a file path (auto-detected if not provided)language
(string, optional): Language to use (javascript, typescript, jsx, tsx)
Example:
find_pattern
Find first node matching a pattern.
Parameters:
pattern
(string): Pattern to match using tree-hugger-js syntax
Examples:
find_all_pattern
Find all nodes matching a pattern.
Parameters:
pattern
(string): Pattern to matchlimit
(number, optional): Maximum matches to return
get_functions
Get all functions with details.
Parameters:
includeAnonymous
(boolean, optional): Include anonymous functions (default: true)asyncOnly
(boolean, optional): Only return async functions (default: false)
get_classes
Get all classes with methods and properties.
Parameters:
includeProperties
(boolean, optional): Include class properties (default: true)includeMethods
(boolean, optional): Include class methods (default: true)
get_imports
Get all import statements.
Parameters:
includeTypeImports
(boolean, optional): Include TypeScript type-only imports (default: true)
Code Transformation Tools
rename_identifier
Rename all occurrences of an identifier.
Parameters:
oldName
(string): Current identifier namenewName
(string): New identifier namepreview
(boolean, optional): Return preview only (default: false)
Example:
remove_unused_imports
Remove unused import statements.
Parameters:
preview
(boolean, optional): Return preview only (default: false)
transform_code
Apply multiple transformations in sequence.
Parameters:
operations
(array): Array of transformation operationspreview
(boolean, optional): Return preview only (default: false)
Example:
insert_code
Insert code before or after nodes matching a pattern.
Parameters:
pattern
(string): Pattern to match for insertion pointscode
(string): Code to insertposition
(string): "before" or "after"preview
(boolean, optional): Return preview only (default: false)
Navigation Tools
get_node_at_position
Get AST node at specific line and column.
Parameters:
line
(number): Line number (1-based)column
(number): Column number (0-based)
analyze_scopes
Analyze variable scopes and bindings.
Parameters:
includeBuiltins
(boolean, optional): Include built-in identifiers (default: false)
Resources
The server provides three resources for accessing internal state:
ast://current
Current parsed AST state with metadata and statistics.
ast://analysis
Results from the most recent code analysis (functions, classes, imports).
ast://transforms
History of code transformations and available operations.
Pattern Syntax
Tree-hugger-js uses intuitive patterns instead of verbose tree-sitter node types:
Basic Patterns
function
- Any function (declaration, expression, arrow, method)class
- Class declarations and expressionsstring
- String and template literalsimport
/export
- Import/export statementscall
- Function callsloop
- For, while, do-while loops
Attribute Selectors
[name="foo"]
- Nodes with specific name[async]
- Async functions[text*="test"]
- Nodes containing text
CSS-like Selectors
class method
- Methods inside classesfunction > return
- Return statements directly in functions:has()
and:not()
pseudo-selectors
Examples
Basic Code Analysis
Code Refactoring
Pattern Matching
Development
Error Handling
The server provides detailed error messages and suggestions:
- File not found errors for invalid file paths
- Parse errors with helpful context
- Pattern matching errors with suggestions
- Transformation errors with rollback capability
License
MIT
Tools
Provides AI agents with powerful JavaScript/TypeScript code analysis and transformation capabilities using the tree-hugger-js library.
- Features
- Installation & Usage
- MCP Client Configuration
- Tools
- Resources
- Pattern Syntax
- Examples
- Development
- Error Handling
- License
Related Resources
Related MCP Servers
- -securityAlicense-qualityProvides deep source code analysis for Unreal Engine codebases, allowing AI assistants to understand C++ class structures, search code, and analyze subsystems.Last updated -71TypeScriptMIT License
- AsecurityAlicenseAqualityProvides Zig language tooling and code analysis, enhancing AI capabilities with Zig-specific functions like code optimization, compute unit estimation, code generation, and recommendations for best practices.Last updated -423JavaScriptMIT License
- AsecurityFlicenseAqualityEnables AI agents to interact with web browsers using natural language, featuring automated browsing, form filling, vision-based element detection, and structured JSON responses for systematic browser control.Last updated -147Python
- AsecurityAlicenseAqualityProvides code context and analysis for AI assistants by extracting directory structures and code symbols using WebAssembly Tree-sitter parsers with zero native dependencies.Last updated -11634JavaScriptMIT License