PI

pwno-io/treesitter-mcp

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

20 stars 4 forks Качество 49 Тренд 0

MCP-сервер для деревца

Обзор

Сервер MCP и CLI, который использует Tree-sitter для анализа и анализа кода. - Парсовые файлы и получить их AST - Вычтите функции и переменные - Создайте графы вызовов - Найдите, где используются функции / переменные - Запустите пользовательский Tree-sitter queries - List import/includes - Extract source code for specific line/column ranges - Use as a standalone CLI or as a MCP server for Claude Desktop Здесь установлены как точки входа treeitter-mcp, так и ts-cli. Для использования с Claude Desktop или другими клиентами MCP: См. docs/MCP USAGE.md для настройки. Проведите анализ прямо из терминала: Используйте файл-выход для записи результатов в файлы JSON вместо stdout. Или через парам запроса URL: http://127.0.0.1:8000?tools=treesitter_analyze_file,treesitter_get_ast

Обзор (машинный перевод)

Сервер MCP и CLI, который использует Tree-sitter для анализа и анализа кода.

Что он делает

Парс файлов и получить их AST

  • Извлечение функций и переменных
  • Построить графы вызовов Найти, где используются функции/переменные
  • Запуск пользовательских запросов Tree-sitter
  • Перечень импорта/включений
  • Извлечение исходного кода для определенных диапазонов строк/столбцов Использование в качестве автономного CLI или MCP-сервера для Claude Desktop

##Установка

Требуется Python 3.10+.

При этом они устанавливают как treesitter-mcp, так и ts-cli точки входа.

Или работать без установки:

##Бегущий

###Как MCP-сервер (по умолчанию) Для использования с Claude Desktop или другими клиентами MCP:

См. [[Т2]], как настроить.

Автономный CLI (ts-cli)

Проведите анализ прямо из терминала:

Используйте --output-file для записи результатов в файлы JSON вместо stdout.

HTTP режим

Для тестирования или ручного использования:

###Ограничение инструментов Выделите только определенные инструменты с [4]:

Или через парам запроса URL: http://127.0.0.1:8000?tools=treesitter_analyze_file,treesitter_get_ast

Доступные инструменты: [6] - Базовый анализ [[Т7]] - Полный AST

  • treesitter_get_call_graph - Функциональные вызовы

Эта страница переведена автоматически. Технические детали смотрите в оригинале.

README

Показан фрагмент оригинального README. Открыть оригинал.

Tree-sitter MCP Server & CLI

An MCP server and CLI that uses Tree-sitter to parse and analyze code.

What it does

  • Parse files and get their AST
  • Extract functions and variables
  • Build call graphs
  • Find where functions/variables are used
  • Run custom Tree-sitter queries
  • List imports/includes
  • Extract source code for specific line/column ranges
  • Use as a standalone CLI or as an MCP server for Claude Desktop

Install

Requires Python 3.10+.

# Install directly
uv pip install treesitter-mcp

# Or install a specific version
uv pip install treesitter-mcp==2.1

# Or clone and install
git clone https://github.com/pwno-io/treesitter-mcp.git
cd treesitter-mcp
uv pip install -e .

This installs both treesitter-mcp and ts-cli entry points.

Or run without installing:

uvx treesitter-mcp

Running

As an MCP server (default)

For use with Claude Desktop or other MCP clients:

treesitter-mcp

See docs/MCP_USAGE.md for how to configure.

Standalone CLI (ts-cli)

Run analysis directly from the terminal:

ts-cli path/to/file.py
ts-cli path/to/file.py --ast --max-depth 2
ts-cli path/to/file.py --find-function main --include-source
ts-cli --supported-languages

Use --output-file to write results to JSON files instead of stdout.

HTTP mode

For testing or manual use:

treesitter-mcp --http --port 8000 --host 127.0.0.1

Limiting tools

Only expose certain tools with --tools:

treesitter-mcp --http --port 8000 --tools treesitter_analyze_file,treesitter_get_ast

Or via URL query param: http://127.0.0.1:8000?tools=treesitter_analyze_file,treesitter_get_ast

Tools available:

  • treesitter_analyze_file - Basic analysis
  • treesitter_get_ast - Full AST
  • treesitter_get_call_graph - Function calls
  • treesitter_find_function - Find function definitions
  • treesitter_find_variable - Find variables
  • treesitter_get_source_for_range - Extract source code for a range
  • treesitter_get_supported_languages - What’s supported
  • treesitter_get_node_at_point - AST node at a line/column
  • treesitter_get_node_for_range - AST node for a range
  • treesitter_cursor_walk - Walk tree with context
  • treesitter_run_query - Custom Tree-sitter queries
  • treesitter_find_usage - Find symbol usages
  • treesitter_get_dependencies - Extract imports/includes

If you don’t specify --tools, everything is exposed.

Writing output to file

All tools support an optional output_file parameter. When provided, the tool writes its result directly to the specified file (as pretty-printed JSON) instead of returning it. This is useful for large outputs like ASTs that could cause context overload in agents.

Example:

# Returns result to file, minimal response to agent
treesitter_get_ast(file_path="large_file.py", output_file="~/output/ast.json")
# Returns: {"status": "written", "output_file": "/home/user/output/ast.json", "bytes_written": 123456}
Открыть полный README на GitHub

Установка

uvx treesitter-mcp
Новичок в MCP? Начните с руководства на mcpskill.org →