tree-sitter-analyzer

aimasteracc/tree-sitter-analyzer

3.4

If you are the rightful owner of tree-sitter-analyzer and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Tree-sitter Analyzer is an extensible multi-language code analyzer framework using Tree-sitter with a dynamic plugin architecture, designed to solve the problem of large code files exceeding LLM single-pass token limits.

Tools
5
Resources
0
Prompts
0

🌳 Tree-sitter Analyzer

English | |

Python Version Tests Coverage PyPI Version GitHub Stars

🚀 Enterprise-Grade Code Analysis Tool for the AI Era - Deep AI Integration · Powerful Search · 17 Languages · Intelligent Analysis


✨ What's New in v1.10.4

  • Vertex AI Compatibility: Fixed MCP tool JSON Schema compatibility with Vertex AI API by removing oneOf/anyOf/allOf constraints
  • Format Change Management System: Complete system for tracking and managing format changes with database tracking and pre-commit validation
  • Behavior Profile Comparison: CLI tool for comparing code analysis behavior profiles between versions
  • Enhanced Language Support: Added Go, Rust, and Kotlin to core dependencies for comprehensive systems programming language support
  • C++ Formatter: Dedicated formatter with Bandit security scanning
  • 8,409 tests with 100% pass rate and 80.33% coverage

📖 for complete version history.


🎬 See It In Action

Demo GIF coming soon - showcasing AI integration with SMART workflow


🚀 5-Minute Quick Start

Prerequisites

# Install uv (required)
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Install fd + ripgrep (required for search features)
brew install fd ripgrep          # macOS
winget install sharkdp.fd BurntSushi.ripgrep.MSVC  # Windows

📖 for all platforms.

Verify Installation

uv run tree-sitter-analyzer --show-supported-languages

🤖 AI Integration

Configure your AI assistant to use Tree-sitter Analyzer via MCP protocol.

Claude Desktop / Cursor / Roo Code

Add to your MCP configuration:

{
  "mcpServers": {
    "tree-sitter-analyzer": {
      "command": "uvx",
      "args": [
        "--from", "tree-sitter-analyzer[mcp]",
        "tree-sitter-analyzer-mcp"
      ],
      "env": {
        "TREE_SITTER_PROJECT_ROOT": "/path/to/your/project",
        "TREE_SITTER_OUTPUT_PATH": "/path/to/output/directory"
      }
    }
  }
}

Configuration file locations:

  • Claude Desktop: %APPDATA%\Claude\claude_desktop_config.json (Windows) / ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
  • Cursor: Built-in MCP settings
  • Roo Code: MCP configuration

After restart, tell the AI: Please set the project root directory to: /path/to/your/project

📖 for complete API documentation.


💻 Common CLI Commands

Installation

uv add "tree-sitter-analyzer[all,mcp]"  # Full installation

Top 5 Commands

# 1. Analyze file structure
uv run tree-sitter-analyzer examples/BigService.java --table full

# 2. Quick summary
uv run tree-sitter-analyzer examples/BigService.java --summary

# 3. Extract code section
uv run tree-sitter-analyzer examples/BigService.java --partial-read --start-line 93 --end-line 106

# 4. Find files and search content
uv run find-and-grep --roots . --query "class.*Service" --extensions java

# 5. Query specific elements
uv run tree-sitter-analyzer examples/BigService.java --query-key methods --filter "public=true"
📋 View Output Example
╭─────────────────────────────────────────────────────────────╮
│                   BigService.java Analysis                   │
├─────────────────────────────────────────────────────────────┤
│ Total Lines: 1419 | Code: 906 | Comments: 246 | Blank: 267  │
│ Classes: 1 | Methods: 66 | Fields: 9 | Complexity: 5.27 avg │
╰─────────────────────────────────────────────────────────────╯

📖 for all commands and options.


🌍 Supported Languages

LanguageSupport LevelKey Features
Java✅ CompleteSpring, JPA, enterprise features
Python✅ CompleteType annotations, decorators
TypeScript✅ CompleteInterfaces, types, TSX/JSX
JavaScript✅ CompleteES6+, React/Vue/Angular
C✅ CompleteFunctions, structs, unions, enums, preprocessor
C++✅ CompleteClasses, templates, namespaces, inheritance
C#✅ CompleteRecords, async/await, attributes
SQL✅ EnhancedTables, views, procedures, triggers
HTML✅ CompleteDOM structure, element classification
CSS✅ CompleteSelectors, properties, categorization
Go✅ CompleteStructs, interfaces, goroutines
Rust✅ CompleteTraits, impl blocks, macros
Kotlin✅ CompleteData classes, coroutines
PHP✅ CompletePHP 8+, attributes, traits
Ruby✅ CompleteRails patterns, metaprogramming
YAML✅ CompleteAnchors, aliases, multi-document
Markdown✅ CompleteHeaders, code blocks, tables

📖 for language-specific details.


📊 Features Overview

FeatureDescriptionLearn More
SMART WorkflowSet-Map-Analyze-Retrieve-Trace methodology
MCP ProtocolNative AI assistant integration
Token OptimizationUp to 95% token reduction
File Searchfd-based high-performance discovery
Content Searchripgrep regex search
SecurityProject boundary protection

🏆 Quality & Testing

MetricValue
Tests6,246 passed ✅
CoverageCoverage
Type Safety100% mypy compliance
PlatformsWindows, macOS, Linux
# Run tests
uv run pytest tests/ -v

# Generate coverage report
uv run pytest tests/ --cov=tree_sitter_analyzer --cov-report=html

🛠️ Development

Setup

git clone https://github.com/aimasteracc/tree-sitter-analyzer.git
cd tree-sitter-analyzer
uv sync --extra all --extra mcp

Quality Checks

uv run pytest tests/ -v                    # Run tests
uv run python check_quality.py --new-code-only  # Quality check
uv run python llm_code_checker.py --check-all   # AI code check

📖 for system design details.


🤝 Contributing & License

We welcome contributions! See for development guidelines.

⭐ Support

If this project helps you, please give us a ⭐ on GitHub!

💝 Sponsors

@o93 - Lead Sponsor supporting MCP tool enhancement, test infrastructure, and quality improvements.

💖 Sponsor this project

📄 License

MIT License - see file.


🧪 Testing

Test Coverage

MetricValue
Total Tests2,411 tests ✅
Test Pass Rate100% (2,411/2,411)
Code CoverageCoverage
Type Safety100% mypy compliance

Running Tests

# Run all tests
uv run pytest tests/ -v

# Run specific test category
uv run pytest tests/unit/ -v              # Unit tests
uv run pytest tests/integration/ -v         # Integration tests
uv run pytest tests/regression/ -m regression  # Regression tests
uv run pytest tests/benchmarks/ -v         # Benchmark tests

# Run with coverage
uv run pytest tests/ --cov=tree_sitter_analyzer --cov-report=html

# Run property-based tests
uv run pytest tests/property/

# Run performance benchmarks
uv run pytest tests/benchmarks/ --benchmark-only

Test Documentation

DocumentDescription
Comprehensive guide for writing tests
Golden Master methodology and regression testing
Project testing standards

Test Categories

  • Unit Tests (2,087 tests): Test individual components in isolation
  • Integration Tests (187 tests): Test component interactions
  • Regression Tests (70 tests): Ensure backward compatibility and format stability
  • Property Tests (75 tests): Hypothesis-based property testing
  • Benchmark Tests (20 tests): Performance monitoring and regression detection
  • Compatibility Tests (30 tests): Cross-version compatibility validation

CI/CD Integration

  • Test Coverage Workflow: Automated coverage checks on PRs and pushes
  • Regression Tests Workflow: Golden Master validation and format stability checks
  • Performance Benchmarks: Daily benchmark runs with trend analysis
  • Quality Checks: Automated linting, type checking, and security scanning

Contributing Tests

When contributing new features:

  1. Write Tests: Follow the
  2. Ensure Coverage: Maintain >80% code coverage
  3. Run Locally: uv run pytest tests/ -v
  4. Check Quality: uv run ruff check . && uv run mypy tree_sitter_analyzer/
  5. Update Docs: Document new tests and features

📚 Documentation

DocumentDescription
Setup for all platforms
Complete command reference
AI-assisted analysis guide
MCP integration details
Language support details
System design
Development guidelines
Comprehensive test writing guide
Golden Master methodology
Version history

🎯 Built for developers working with large codebases and AI assistants

Making every line of code understandable to AI, enabling every project to break through token limitations