Provides code analysis capabilities through tree-sitter parsing, enabling structured understanding and manipulation of s...
Created byApr 22, 2025
MCP Tree-sitter Server
A Model Context Protocol (MCP) server that provides code analysis capabilities using tree-sitter, designed to give Claude intelligent access to codebases with appropriate context management.
Features
Flexible Exploration: Examine code at multiple levels of granularity
Context Management: Provides just enough information without overwhelming the context window
Language Agnostic: Supports many programming languages including Python, JavaScript, TypeScript, Go, Rust, C, C++, Swift, Java, Kotlin, Julia, and APL via tree-sitter-language-pack
Structure-Aware: Uses AST-based understanding with efficient cursor-based traversal
Searchable: Find specific patterns using text search and tree-sitter queries
Caching: Optimized performance through parse tree caching
Symbol Extraction: Extract and analyze functions, classes, and other code symbols
Dependency Analysis: Identify and analyze code dependencies and relationships
State Persistence: Maintains project registrations and cached data between invocations
Secure: Built-in security boundaries and input validation
For a comprehensive list of all available commands, their current implementation status, and detailed feature matrix, please refer to the FEATURES.md document.
Installation
Prerequisites
Python 3.10+
Tree-sitter language parsers for your preferred languages
Basic Installation
Development Installation
Quick Start
Running with Claude Desktop
You can make the server available in Claude Desktop either through the MCP CLI or by manually configuring Claude Desktop.
Using MCP CLI
Register the server with Claude Desktop:
Manual Configuration
Alternatively, you can manually configure Claude Desktop:
Open your Claude Desktop configuration file:Create the file if it doesn't exist.
Add the server to the mcpServers section:Alternatively, if using uv or another package manager:Note: Make sure to replace /ABSOLUTE/PATH/TO/YOUR/PROJECT with the actual absolute path to your project directory.
Save the file and restart Claude Desktop.
The MCP tools icon (hammer) will appear in Claude Desktop's interface once you have properly configured at least one MCP server. You can then access the tree_sitter server's functionality by clicking on this icon.
Configuring with Released Version
If you prefer not to manually install the package from PyPI (released version) or clone the repository, simply use the following configuration for Claude Desktop:
Open your Claude Desktop configuration file (same location as above).
Add the tree-sitter server to the mcpServers section:
Save the file and restart Claude Desktop.
This method uses uvx to run the installed PyPI package directly, which is the recommended approach for the released version. The server doesn't require any additional parameters to run in its basic configuration.
State Persistence
The MCP Tree-sitter Server maintains state between invocations. This means:
Projects stay registered until explicitly removed or the server is restarted
Parse trees are cached according to configuration settings
Language information is retained throughout the server's lifetime
This persistence is maintained in-memory during the server's lifetime using singleton patterns for key components.
Running as a standalone server
Using with the MCP Inspector
Usage
Register a Project
First, register a project to analyze:
Explore Files
List files in the project:
View file content:
Analyze Code Structure
Get the syntax tree:
Extract symbols:
Search Code
Search for text:
Run tree-sitter queries:
Analyze Complexity
Direct Python Usage
While the primary intended use is through the MCP server, you can also use the library directly in Python code:
Configuration
Create a YAML configuration file:
Load it with:
About preferred_languages
The preferred_languages setting controls which language parsers are pre-loaded at server startup rather than on-demand. This provides several benefits:
Faster initial analysis: No delay when first analyzing a file of a pre-loaded language
Early error detection: Issues with parsers are discovered at startup, not during use
Predictable memory allocation: Memory for frequently used parsers is allocated upfront
By default, all parsers are loaded on-demand when first needed. For optimal performance, specify the languages you use most frequently in your projects.
You can also configure specific settings:
Or use environment variables:
The server will look for configuration in:
Path specified in configure() call
Path specified by MCP_TS_CONFIG_PATH environment variable
suggest_improvements - Create a prompt for suggesting code improvements
project_overview - Create a prompt for a project overview analysis
License
MIT
MCP Tree-sitter Server
A Model Context Protocol (MCP) server that provides code analysis capabilities using tree-sitter, designed to give Claude intelligent access to codebases with appropriate context management.
Features
Flexible Exploration: Examine code at multiple levels of granularity
Context Management: Provides just enough information without overwhelming the context window
Language Agnostic: Supports many programming languages including Python, JavaScript, TypeScript, Go, Rust, C, C++, Swift, Java, Kotlin, Julia, and APL via tree-sitter-language-pack
Structure-Aware: Uses AST-based understanding with efficient cursor-based traversal
Searchable: Find specific patterns using text search and tree-sitter queries
Caching: Optimized performance through parse tree caching
Symbol Extraction: Extract and analyze functions, classes, and other code symbols
Dependency Analysis: Identify and analyze code dependencies and relationships
State Persistence: Maintains project registrations and cached data between invocations
Secure: Built-in security boundaries and input validation
For a comprehensive list of all available commands, their current implementation status, and detailed feature matrix, please refer to the FEATURES.md document.
Installation
Prerequisites
Python 3.10+
Tree-sitter language parsers for your preferred languages
Basic Installation
Development Installation
Quick Start
Running with Claude Desktop
You can make the server available in Claude Desktop either through the MCP CLI or by manually configuring Claude Desktop.
Using MCP CLI
Register the server with Claude Desktop:
Manual Configuration
Alternatively, you can manually configure Claude Desktop:
Open your Claude Desktop configuration file:Create the file if it doesn't exist.
Add the server to the mcpServers section:Alternatively, if using uv or another package manager:Note: Make sure to replace /ABSOLUTE/PATH/TO/YOUR/PROJECT with the actual absolute path to your project directory.
Save the file and restart Claude Desktop.
The MCP tools icon (hammer) will appear in Claude Desktop's interface once you have properly configured at least one MCP server. You can then access the tree_sitter server's functionality by clicking on this icon.
Configuring with Released Version
If you prefer not to manually install the package from PyPI (released version) or clone the repository, simply use the following configuration for Claude Desktop:
Open your Claude Desktop configuration file (same location as above).
Add the tree-sitter server to the mcpServers section:
Save the file and restart Claude Desktop.
This method uses uvx to run the installed PyPI package directly, which is the recommended approach for the released version. The server doesn't require any additional parameters to run in its basic configuration.
State Persistence
The MCP Tree-sitter Server maintains state between invocations. This means:
Projects stay registered until explicitly removed or the server is restarted
Parse trees are cached according to configuration settings
Language information is retained throughout the server's lifetime
This persistence is maintained in-memory during the server's lifetime using singleton patterns for key components.
Running as a standalone server
Using with the MCP Inspector
Usage
Register a Project
First, register a project to analyze:
Explore Files
List files in the project:
View file content:
Analyze Code Structure
Get the syntax tree:
Extract symbols:
Search Code
Search for text:
Run tree-sitter queries:
Analyze Complexity
Direct Python Usage
While the primary intended use is through the MCP server, you can also use the library directly in Python code:
Configuration
Create a YAML configuration file:
Load it with:
About preferred_languages
The preferred_languages setting controls which language parsers are pre-loaded at server startup rather than on-demand. This provides several benefits:
Faster initial analysis: No delay when first analyzing a file of a pre-loaded language
Early error detection: Issues with parsers are discovered at startup, not during use
Predictable memory allocation: Memory for frequently used parsers is allocated upfront
By default, all parsers are loaded on-demand when first needed. For optimal performance, specify the languages you use most frequently in your projects.
You can also configure specific settings:
Or use environment variables:
The server will look for configuration in:
Path specified in configure() call
Path specified by MCP_TS_CONFIG_PATH environment variable