treesitter-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@treesitter-mcpshow me the call graph for app.py"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Tree-sitter MCP Server & CLI
An MCP server and CLI that uses Tree-sitter to parse and analyze code.
What it does
Parse files and get their AST
Extract functions and variables
Build call graphs
Find where functions/variables are used
Run custom Tree-sitter queries
List imports/includes
Extract source code for specific line/column ranges
Use as a standalone CLI or as an MCP server for Claude Desktop
Related MCP server: code-analyze-mcp
Install
Requires Python 3.10+.
# Install directly
uv pip install treesitter-mcp
# Or install a specific version
uv pip install treesitter-mcp==2.1
# Or clone and install
git clone https://github.com/pwno-io/treesitter-mcp.git
cd treesitter-mcp
uv pip install -e .This installs both treesitter-mcp and ts-cli entry points.
Or run without installing:
uvx treesitter-mcpRunning
As an MCP server (default)
For use with Claude Desktop or other MCP clients:
treesitter-mcpSee docs/MCP_USAGE.md for how to configure.
Standalone CLI (ts-cli)
Run analysis directly from the terminal:
ts-cli path/to/file.py
ts-cli path/to/file.py --ast --max-depth 2
ts-cli path/to/file.py --find-function main --include-source
ts-cli --supported-languagesUse --output-file to write results to JSON files instead of stdout.
HTTP mode
For testing or manual use:
treesitter-mcp --http --port 8000 --host 127.0.0.1Limiting tools
Only expose certain tools with --tools:
treesitter-mcp --http --port 8000 --tools treesitter_analyze_file,treesitter_get_astOr via URL query param: http://127.0.0.1:8000?tools=treesitter_analyze_file,treesitter_get_ast
Tools available:
treesitter_analyze_file- Basic analysistreesitter_get_ast- Full ASTtreesitter_get_call_graph- Function callstreesitter_find_function- Find function definitionstreesitter_find_variable- Find variablestreesitter_get_source_for_range- Extract source code for a rangetreesitter_get_supported_languages- What's supportedtreesitter_get_node_at_point- AST node at a line/columntreesitter_get_node_for_range- AST node for a rangetreesitter_cursor_walk- Walk tree with contexttreesitter_run_query- Custom Tree-sitter queriestreesitter_find_usage- Find symbol usagestreesitter_get_dependencies- Extract imports/includes
If you don't specify --tools, everything is exposed.
Writing output to file
All tools support an optional output_file parameter. When provided, the tool
writes its result directly to the specified file (as pretty-printed JSON) instead
of returning it. This is useful for large outputs like ASTs that could cause
context overload in agents.
Example:
# Returns result to file, minimal response to agent
treesitter_get_ast(file_path="large_file.py", output_file="~/output/ast.json")
# Returns: {"status": "written", "output_file": "/home/user/output/ast.json", "bytes_written": 123456}The tool will:
Automatically create parent directories if they don't exist
Expand
~to your home directoryWarn (to stderr) if overwriting an existing file
Return a minimal confirmation dict on success, or an error dict if writing fails
Including source code in results
The treesitter_find_function and treesitter_find_variable tools support an
optional include_source parameter. When set to True, each matched symbol
includes its source code in the result:
treesitter_find_function(file_path="server.py", name="main", include_source=True)
# Returns: {"query": "main", "matches": [{"name": "main", ..., "source": "def main():\n ..."}]}Language support
Language | analyze_file | get_ast | get_call_graph | find_function | find_variable | find_usage | get_dependencies |
C | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
C++ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Python | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Go | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Java | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
PHP | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Rust | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Ruby | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
File extensions
Language | Extensions |
C |
|
C++ |
|
Python |
|
JavaScript |
|
TypeScript |
|
Go |
|
Java |
|
PHP |
|
Rust |
|
Ruby |
|
Docs
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Appeared in Searches
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/pwno-io/treesitter-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server