Get the FREE Ultimate OpenClaw Setup Guide →

mcp -tree-sitter

MCP Server for Tree-sitter

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio wrale-mcp-server-tree-sitter python -m mcp_server_tree_sitter.server

How to use

The MCP Tree-sitter Server provides code analysis capabilities powered by the tree-sitter parsing library. It exposes a set of MCP commands that let you register projects, examine files, retrieve abstract syntax trees, extract symbols, search code with text patterns and tree-sitter queries, and analyze code structure and dependencies. The server maintains in-memory state to persist project registrations and cached parse trees between invocations, enabling efficient iterative exploration of large codebases.

To use the server, run it locally (for example via Python module invocation shown in the configuration) and connect your MCP client (such as Claude Desktop or an MCP CLI) to the server. You can register a project, list files, fetch file contents, and request ASTs at configurable depths. Advanced features include running tree-sitter queries over a project’s code, analyzing complexity, and extracting symbols like functions, classes, and variables. The tooling supports multiple languages through tree-sitter language packs and provides structure-aware navigation and selective context to help AI assistants reason about code without overwhelming the context window.

How to install

Prerequisites:

  • Python 3.10+
  • Tree-sitter language parsers for your languages (usually installed with the package)

Basic installation (from PyPI):

pip install mcp-server-tree-sitter

Development installation (from source):

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

Running the server locally (example):

# Run the MCP server entry point directly
python -m mcp run mcp_server_tree_sitter.server

If you are integrating with Claude Desktop or another MCP client, configure the client to connect to the server using the command and arguments described in the mcp_config section.

Additional notes

Notes and tips:

  • Ensure Python 3.10+ is installed and that you have the necessary tree-sitter language packs for the languages you work with.
  • The server persists project registrations and parse-tree caches in memory for the lifetime of the process; restart will clear state unless you implement persistence.
  • When using Claude Desktop, you can register the server via the MCP CLI or manually configure the mcpServers section in the Claude config as shown in the README.
  • If you encounter issues with language parsing, verify that the required tree-sitter grammars are installed and that the server has access to the project path you register.
  • The server supports interactive exploration via commands like get_ast, get_symbols, find_text, and run_query; for long-running analyses, consider enabling caching and configuring appropriate max_depth or pattern filters to control data volume.

Related MCP Servers

Sponsor this space

Reach thousands of developers