wrale_mcp_server_tree_sitter

wrale_mcp_server_tree_sitter

by wrale
A Model Context Protocol server that provides code analysis capabilities using tree-sitter for intelligent codebase exploration.

Code Analysis MCP Server for Tree-sitter

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 via Tree-sitter
  • 🌳 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

pip install mcp-server-tree-sitter

Development Installation

git clone https://github.com/wrale/mcp-server-tree-sitter.git
cd mcp-server-tree-sitter
pip install -e ".[dev,languages]"

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:

mcp install mcp_server_tree_sitter.server:mcp --name "tree_sitter"

Manual Configuration

  1. Open your Claude Desktop configuration file:
  2. macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json
  3. Windows: %APPDATA%\Claude\claude_desktop_config.json

Create the file if it doesn't exist.

  1. Add the server to the mcpServers section:
{
    "mcpServers": {
        "tree_sitter": {
            "command": "python",
            "args": ["-m", "mcp_server_tree_sitter.server"]
        }
    }
}
  1. Save the file and restart Claude Desktop.

Configuring with Released Version

  1. Open your Claude Desktop configuration file (same location as above).
  2. 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"]
        }
    }
}
  1. Save the file and restart Claude Desktop.

Usage

Register a Project

register_project_tool(path="/path/to/your/project", name="my-project")

Explore Files

List files in the project:

list_files(project="my-project", pattern="**/*.py")

View file content:

get_file(project="my-project", path="src/main.py")

Analyze Code Structure

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")

Search Code

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 Complexity

analyze_complexity(project="my-project", path="src/main.py")

Configuration

Create a YAML configuration file:

cache:
  enabled: true
  max_size_mb: 100
  ttl_seconds: 300

security:
  max_file_size_mb: 5
  excluded_dirs:
    - .git
    - node_modules
    - __pycache__

language:
  default_max_depth: 5
  preferred_languages:
    - python
    - javascript

log_level: INFO
max_results_default: 100

Load it with:

configure(config_path="/path/to/config.yaml")

License

MIT

About

MCP Server for Tree-sitter

Topics

tree-sitter mcp code-analysis ast code-search claude coding-assistant ai-assistant claude-ai claude-desktop model-context-protocol model-context-protocol-servers

Features & Capabilities

Categories
mcp_server model_context_protocol tree-sitter code-analysis ast python claude search api_integration docker

Implementation Details

Stats

0 Views
0 Likes
4 GitHub Stars

Repository Info

wrale Organization

Similar Servers

continuedev_continue by continuedev
0
0
0

Recently Viewed