/ Directory / Playground / Tree-sitter MCP
● Community wrale ⚡ Instant

Tree-sitter MCP

by wrale · wrale/mcp-server-tree-sitter

Tree-sitter as MCP — give Claude AST-level access so it edits a function, not 47 random regex matches.

tree-sitter-mcp wraps Tree-sitter parsers as MCP tools. Instead of asking Claude to grep through code, you give it get_function, list_symbols, find_calls. The agent can slice surgical edits at the AST level: 'rename only the function definition, not the string literal that happens to match.'

Why use it

Key features

Live Demo

What it looks like in practice

tree-sitter-mcp.replay ▶ ready
0/0

Install

Pick your client

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "tree-sitter-mcp": {
      "command": "uvx",
      "args": [
        "mcp-server-tree-sitter"
      ]
    }
  }
}

Open Claude Desktop → Settings → Developer → Edit Config. Restart after saving.

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "tree-sitter-mcp": {
      "command": "uvx",
      "args": [
        "mcp-server-tree-sitter"
      ]
    }
  }
}

Cursor uses the same mcpServers schema as Claude Desktop. Project config wins over global.

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "tree-sitter-mcp": {
      "command": "uvx",
      "args": [
        "mcp-server-tree-sitter"
      ]
    }
  }
}

Click the MCP Servers icon in the Cline sidebar, then "Edit Configuration".

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "tree-sitter-mcp": {
      "command": "uvx",
      "args": [
        "mcp-server-tree-sitter"
      ]
    }
  }
}

Same shape as Claude Desktop. Restart Windsurf to pick up changes.

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "tree-sitter-mcp",
      "command": "uvx",
      "args": [
        "mcp-server-tree-sitter"
      ]
    }
  ]
}

Continue uses an array of server objects rather than a map.

~/.config/zed/settings.json
{
  "context_servers": {
    "tree-sitter-mcp": {
      "command": {
        "path": "uvx",
        "args": [
          "mcp-server-tree-sitter"
        ]
      }
    }
  }
}

Add to context_servers. Zed hot-reloads on save.

claude mcp add tree-sitter-mcp -- uvx mcp-server-tree-sitter

One-liner. Verify with claude mcp list. Remove with claude mcp remove.

Use Cases

Real-world ways to use Tree-sitter MCP

Rename a function without renaming a coincidentally-matching string

👤 Devs doing refactors ⏱ ~15 min intermediate

When to use: You want to rename validateTokenverifyToken and not also rename the docstring that says 'this validates token'.

Flow
  1. Find definition
    Use tree-sitter MCP. Find the definition of validateToken — function only, ignore strings and comments.✓ Copied
    → AST node with file:line and node type 'function_definition'
  2. Find references
    Find all call sites of validateToken — only identifier-resolution matches.✓ Copied
    → Reference list, no false positives in strings
  3. Rename
    Rename to verifyToken everywhere it's a real reference. Show me the diff.✓ Copied
    → Diff with N renames in identifier positions only

Outcome: Clean rename that doesn't touch comments, strings, or docs.

Pitfalls
  • Dynamic dispatch / reflection misses — Combine with semble for semantic recall on dynamic uses
Combine with: filesystem · semble-mcp

Pull a function's exact body for an extract-method refactor

👤 Engineers cleaning up long functions ⏱ ~20 min intermediate

When to use: You want to extract lines 42–87 of a function into a helper — surgically.

Flow
  1. Slice
    Show me the exact AST node for the for-loop at line 42 in handler.py.✓ Copied
    → Loop node with byte ranges
  2. Extract
    Move that loop into a new function process_batch. Replace original with a call.✓ Copied
    → Refactor diff respects original indentation and scope

Outcome: Refactor that compiles on first try.

Pitfalls
  • Captured variables not lifted to args — Ask Claude to enumerate free variables before extracting

Compute per-file complexity metrics

👤 Engineering managers / tech debt audits ⏱ ~25 min intermediate

When to use: You need a hot-spot map of complex code.

Flow
  1. Walk
    For every .py file under src/, count function defs and rough cyclomatic complexity using AST.✓ Copied
    → Per-file table
  2. Rank
    Top 10 most complex functions — report file, line, name, score.✓ Copied
    → Ranked hot-spot list

Outcome: Prioritized refactor backlog.

Pitfalls
  • Cyclomatic ≠ readability — Combine with reviewer judgment; metric is a starting point

Combinations

Pair with other MCPs for X10 leverage

tree-sitter-mcp + semble-mcp

Semantic recall (semble) + structural precision (tree-sitter)

Use semble to find probable call sites, then tree-sitter to verify each is a real identifier.✓ Copied
tree-sitter-mcp + filesystem

Read just the AST-derived ranges

Tree-sitter the function range, then filesystem to dump the exact bytes.✓ Copied

Tools

What this MCP exposes

ToolInputsWhen to callCost
parse_file path Get a file's full AST free
list_symbols path, kind? Top-level inventory free
find_definition name, scope? Locate where something is defined free
find_references name Find call sites for safe rename free
get_node path, byte_range or line_range Slice exact node for refactor free

Cost & Limits

What this costs to run

API quota
None — local
Tokens per call
100–1500
Monetary
Free
Tip
Slice nodes, don't dump whole files

Security

Permissions, secrets, blast radius

Minimum scopes: Local file read
Credential storage: None
Data egress: None

Troubleshooting

Common errors and fixes

Language not supported

Add the relevant Tree-sitter grammar; check supported list in README

Parse errors on partial files

Tree-sitter recovers but flags ERROR nodes; ignore or fix syntactically

Slow first run

Grammar compile happens once; subsequent runs are fast

Alternatives

Tree-sitter MCP vs others

AlternativeWhen to use it insteadTradeoff
ast-grepYou want a CLI-first structural search/replace toolLess integrated as MCP
Language servers (LSP)You need full type-resolution, not just syntaxHeavier setup; one server per language

More

Resources

📖 Read the official README on GitHub

🐙 Browse open issues

🔍 Browse all 400+ MCP servers and Skills