Skip to main content

MCP server for code analysis using Tree-sitter

Project description

Tree-sitter MCP Server

A Model Context Protocol (MCP) server for code analysis using Tree-sitter. This tool provides capabilities to parse code, extract symbols, generate call graphs, find usages, and run custom queries against C, C++, JavaScript, PHP, Rust, TypeScript, Go, Java, and Python code.

Features

  • AST Retrieval: Get the full Abstract Syntax Tree (AST) of a file.
  • Symbol Extraction: Find function and variable definitions.
  • Call Graph: Generate a call graph for C/C++ functions.
  • Tree-sitter Queries: Run custom S-expression queries against your code.
  • Usage Finder: Find usages of functions and variables.
  • Dependency Extraction: List file dependencies (includes/imports).
  • Multi-Language Support: Currently supports C, C++, JavaScript, PHP, Rust, TypeScript, Go, Java, and Python.

Installation

Prerequisites

  • Python 3.10+
  • pip

Setup

  1. Clone the repository.
  2. Install the package in editable mode:
    # Using uv (recommended)
    uv pip install -e .
    
    # Or using pip
    pip install -e .
    

This will install two command-line tools:

  • treesitter: The CLI for analyzing files
  • treesitter-mcp: The MCP server

You can now use these commands from anywhere on your system.

Usage

CLI

The CLI is available as the treesitter command after installation.

treesitter <file_path> [options]

Examples

Get AST:

treesitter test.c --ast

Find Function Definition:

treesitter test.c --find-function my_func

Find Usages:

treesitter test.c --find-usage my_func

Get Dependencies:

treesitter test.c --dependencies

Run Custom Query:

treesitter test.c --query "(function_definition) @func"

MCP Server

To run the MCP server:

treesitter-mcp

Configure your MCP client (e.g., Claude Desktop) to use this server. See docs/MCP_USAGE.md for detailed configuration instructions.

Supported Languages

  • C: Full support (Symbols, Call Graph, Queries, Usage).
  • C++: Full support.
  • JavaScript: Full support.
  • PHP: Full support.
  • Rust: Full support.
  • TypeScript: Full support.
  • Go: Full support.
  • Java: Full support.
  • Python: Full support.

Documentation

See the docs/ directory for more details:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treesitter_mcp-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

treesitter_mcp-0.1.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file treesitter_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: treesitter_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for treesitter_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 957373e1857f7b0f21aa8a992e9f76f499017fede0612eb5dd2f84ea678a77c0
MD5 2139ae503fc2210ae50200ca0a9dbf15
BLAKE2b-256 d95dffcfd49166a1f4bab3257b5dc51cc0512237ead991072e186fc630f16211

See more details on using hashes here.

File details

Details for the file treesitter_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: treesitter_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for treesitter_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c8702d5eda261127272a2a2c3e877be444cdc8cf29aeb3a9d087d5549998265
MD5 7599cc91dcd8eb7f8db2f8c4b92fecf0
BLAKE2b-256 849457b579dc33b97de8b6611e684a616b003a9e2f443f3537a17e365cd2c171

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page