Get the FREE Ultimate OpenClaw Setup Guide →

code-to-tree

A runtime-free MCP server that converts source code into AST🌲, regardless of language.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio micl2e2-code-to-tree ./code-to-tree \
  --env CODE_TO_TREE_PATH="Path to the code-to-tree binary if not in PATH"

How to use

code-to-tree is a standalone MCP server that exposes the code-to-tree binary, which converts source code into an Abstract Syntax Tree (AST) using tree-sitter grammars. It supports multiple languages (C, C++, Rust, Ruby, Go, Java, Python) and is designed to run as a single binary so MCP clients can install and run it with minimal dependencies. To use it, place the code-to-tree executable on your machine and configure your MCP client to point at the local binary. The server expects to receive source code and language context and will return an AST representation that can be consumed by the client for downstream tasks such as analysis, prompting, or debugging. Since it’s a standalone binary, you don’t need a separate service or runtime environment beyond what your MCP client requires.

Clients (for example Claude, Claude-like configurations, or other MCP-enabled frontends) should be configured to launch the code-to-tree binary when integration is requested. The client configuration typically specifies the executable path under an mcpServers entry. Once started, the server will listen for requests and respond with the ASTs generated by tree-sitter-powered grammars included in the code-to-tree release.

How to install

Prerequisites:

  • A supported operating system (Windows, macOS, or Linux)
  • Basic development tools if you plan to build from source (Git, a C compiler, and a make tool on Windows/macOS).
  • Access to the internet to fetch the code-to-tree binary or build dependencies.

Install from release (recommended):

  1. Download the code-to-tree binary from the GitHub releases page for your OS (code-to-tree.exe on Windows or code-to-tree on macOS/Linux).
  2. Make sure the binary is executable (chmod +x code-to-tree on macOS/Linux).
  3. (Optional) Move the binary to a directory in your PATH, e.g. /usr/local/bin.

If building from source is desired:

  1. Install dependencies and build tools for your platform (examples below).

Windows:

  • Install MSYS2, then use MSYS2 MINGW64 and ensure make, gcc, and git are installed.

  • Clone mcpc and the tree-sitter grammars as described in the repository’s Windows building guide.

  • Build mcpc and the code-to-tree example as demonstrated in the README:

    git clone https://github.com/micl2e2/mcpc cd mcpc && make install cd mcpc/example/code-to-tree CFLAGS="-I/usr/local/include -L/usr/local/lib" make

macOS:

  • Install Xcode Command Line Tools.

  • Clone mcpc and build as described in the repository, then compile code-to-tree:

    git clone https://github.com/micl2e2/mcpc cd mcpc && make install cd mcpc/example/code-to-tree make

After installation, ensure the code-to-tree binary is accessible and testable by invoking:

code-to-tree --help

Configure your MCP client to point to the executable path you installed.

Additional notes

Tips and common issues:

  • Ensure the code-to-tree binary has execute permissions on macOS/Linux and is not blocked by macOS Gatekeeper.
  • If your MCP client runs in a sandbox or container, ensure the path to the code-to-tree binary is mounted or accessible inside the container.
  • The server supports multiple languages via tree-sitter grammars; if a language is not recognized, verify that the appropriate grammar is included in the binary release.
  • If you move the binary after configuring a client, update the client configuration to reflect the new path.
  • Use the environment variable CODE_TO_TREE_PATH to override alternative binary locations if needed.
  • When integrating with clients that expect a JSON-based protocol, ensure the request body includes the source code and the language metadata so tree-sitter can select the correct grammar.

Related MCP Servers

Sponsor this space

Reach thousands of developers ↗