Tree-sitter MCP Server

io.github.joowaniv0.1.0更新于 Oct 2, 2026

Parse code into Tree-sitter ASTs to see node kinds, field names, and positions

已验证STDIO仅桌面Developer Tools

概览

AI 生成的概览

让助手用 Tree-sitter 解析代码片段并查看生成的语法树,包括节点类型、字段名和位置。

功能
提供一个工具 get_tree_sitter_ast,接收代码字符串和语言名称,返回 Tree-sitter 语法树,每行一个具名节点,并带有字段名和从零开始的行列范围。ERROR 和 MISSING 节点用于标记语法错误。支持多种语言,包括 C、C++、C#、Go、GraphQL、HCL、Java、JavaScript、JSON、JSX、Kotlin、PHP、Prisma、Protobuf、Python、Ruby、Rust、SQL、Swift、Terraform、Thrift、TOML、TSX、TypeScript 和 YAML,名称不区分大小写,也支持常见别名。
适用场景
适合助手在编写 Tree-sitter 查询或遍历语法树的代码时,用来确认某个代码片段的确切节点类型、字段名和位置。它是面向解析器相关开发工作的轻量辅助工具,而不是通用的代码分析工具。
运行要求
通过 stdio 在本地运行。npm 包用 npx 启动,需要 Node.js;也可以改用 cargo 或从发布页面安装二进制文件,并以 tree-sitter-mcp-server 作为命令。未声明任何账号、API 密钥或环境变量。
安装前请注意
该服务器会解析传给它的代码片段;如果在意,请避免发送密钥或敏感源码。未声明任何身份验证、凭据、支付或写入操作。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Tree-sitter MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Tree-sitter MCP Server

An MCP server that shows coding agents the Tree-sitter syntax tree of a code snippet, so they can check node kinds, field names, and positions before writing Tree-sitter queries or code that walks a syntax tree.

Installation

Claude Code:

shell
claude mcp add tree-sitter -- npx -y tree-sitter-mcp-server

Codex:

shell
codex mcp add tree-sitter -- npx -y tree-sitter-mcp-server

Other clients:

json
{  "mcpServers": {    "tree-sitter": {      "command": "npx",      "args": ["-y", "tree-sitter-mcp-server"]    }  }}

npx needs Node.js. Without it, install the binary with cargo install --locked tree-sitter-mcp-server or download it from the releases, and use tree-sitter-mcp-server as the command.

Clients that browse the MCP Registry, such as VS Code, can also install it from there.

mcp-name: io.github.joowani/tree-sitter-mcp-server

Supported Languages

c, cpp, csharp, go, graphql, hcl, java, javascript, json, jsx, kotlin, php, prisma, protobuf, python, ruby, rust, sql, swift, terraform, thrift, toml, tsx, typescript, yaml

Names are case-insensitive, and common aliases such as c++, c#, py, and ts also work. javascript and jsx use the TypeScript and TSX grammars, and terraform uses the HCL grammar. PHP code must start with <?php.

Tool

get_tree_sitter_ast returns the syntax tree of code in language, one named node per line, with field names and zero-based (row-column) ranges. ERROR and MISSING nodes mark syntax errors.

json
{  "language": "python",  "code": "x = 1"}
text
module (0-0) - (0-5)  expression_statement (0-0) - (0-5)    assignment (0-0) - (0-5)      left: identifier (0-0) - (0-1)      right: integer (0-4) - (0-5)

来源:README.md,提交 d12ee35

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v0.1.0最新Oct 2, 2026