The MCP Tree-sitter Server provides code analysis capabilities using tree-sitter, giving AI assistants intelligent access to codebases with appropriate context management. It supports multiple programming languages and offers structure-aware code exploration features.
pip install mcp-server-tree-sitter
You can make the server available in Claude Desktop either through the MCP CLI or by manually configuring it.
Register the server with Claude Desktop:
mcp install mcp_server_tree_sitter.server:mcp --name "tree_sitter"
Alternatively, you can manually configure Claude Desktop:
Open your Claude Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Create the file if it doesn't exist.
Add the server to the mcpServers
section:
{
"mcpServers": {
"tree_sitter": {
"command": "python",
"args": [
"-m",
"mcp_server_tree_sitter.server"
]
}
}
}
Alternatively, if using uv or another package manager:
{
"mcpServers": {
"tree_sitter": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/YOUR/PROJECT",
"run",
"-m",
"mcp_server_tree_sitter.server"
]
}
}
}
Save the file and restart Claude Desktop.
If you prefer to use the released version from PyPI:
Open your Claude Desktop configuration file (same location as above).
Add the tree-sitter server to the mcpServers
section:
{
"mcpServers": {
"tree_sitter": {
"command": "uvx",
"args": [
"--directory", "/ABSOLUTE/PATH/TO/YOUR/PROJECT",
"mcp-server-tree-sitter"
]
}
}
}
Save the file and restart Claude Desktop.
There are several ways to run the server:
python -m mcp run mcp_server_tree_sitter.server
# Run the server with default settings
mcp-server-tree-sitter
# Show help information
mcp-server-tree-sitter --help
# Show version information
mcp-server-tree-sitter --version
# Run with custom configuration file
mcp-server-tree-sitter --config /path/to/config.yaml
# Enable debug logging
mcp-server-tree-sitter --debug
# Disable parse tree caching
mcp-server-tree-sitter --disable-cache
python -m mcp dev mcp_server_tree_sitter.server
Register a project for analysis:
register_project_tool(path="/path/to/your/project", name="my-project")
List registered projects:
list_projects_tool()
Remove a project:
remove_project_tool(name="my-project")
List files in the project:
list_files(project="my-project", pattern="**/*.py")
View file content:
get_file(project="my-project", path="src/main.py")
Get file metadata:
get_file_metadata(project="my-project", path="src/main.py")
Get the syntax tree:
get_ast(project="my-project", path="src/main.py", max_depth=3)
Extract symbols:
get_symbols(project="my-project", path="src/main.py")
Find where a symbol is used:
find_usage(project="my-project", symbol="MyClass", path="src/main.py")
Search for text:
find_text(project="my-project", pattern="function", file_pattern="**/*.py")
Run tree-sitter queries:
run_query(
project="my-project",
query='(function_definition name: (identifier) @function.name)',
language="python"
)
Analyze code complexity:
analyze_complexity(project="my-project", path="src/main.py")
Analyze project structure:
analyze_project(project="my-project")
Identify dependencies:
get_dependencies(project="my-project", path="src/main.py")
Find similar code:
find_similar_code(project="my-project", path="src/main.py", function_name="process_data")
Create a YAML configuration file:
cache:
enabled: true # Enable/disable caching (default: true)
max_size_mb: 100 # Maximum cache size in MB (default: 100)
ttl_seconds: 300 # Cache entry time-to-live in seconds (default: 300)
security:
max_file_size_mb: 5 # Maximum file size to process in MB (default: 5)
excluded_dirs: # Directories to exclude from processing
- .git
- node_modules
- __pycache__
allowed_extensions: # Optional list of allowed file extensions
# - py
# - js
# Leave empty or omit for all extensions
language:
default_max_depth: 5 # Default max depth for AST traversal (default: 5)
preferred_languages: # List of languages to pre-load at startup for faster performance
- python # Pre-loading reduces latency for first operations
- javascript
log_level: INFO # Logging level (DEBUG, INFO, WARNING, ERROR)
max_results_default: 100 # Default maximum results for search operations
Apply configuration:
configure(config_path="/path/to/config.yaml")
Or configure specific settings:
configure(cache_enabled=True, max_file_size_mb=10, log_level="DEBUG")
You can also use environment variables to configure the server:
export MCP_TS_CACHE_MAX_SIZE_MB=256
export MCP_TS_LOG_LEVEL=DEBUG
export MCP_TS_CONFIG_PATH=/path/to/config.yaml
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "tree_sitter" '{"command":"python","args":["-m","mcp_server_tree_sitter.server"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"tree_sitter": {
"command": "python",
"args": [
"-m",
"mcp_server_tree_sitter.server"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"tree_sitter": {
"command": "python",
"args": [
"-m",
"mcp_server_tree_sitter.server"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect