Analyzes JavaScript source code to extract classes, functions, and parameters, providing a structured overview of file content for LLM consumption.
Formats code structure analysis results into a markdown representation optimized for LLM readability, including nesting levels and line numbers.
Analyzes Python source code to extract classes, functions, and parameters, providing a structured overview of file content for LLM consumption.
Analyzes TypeScript source code to extract classes, functions, and parameters, providing a structured overview of file content for LLM consumption.
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 Code Structure MCP Serversummarize the classes and functions in src/models.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.
TreeSitter MCP Server
A fast Model Context Protocol (MCP) server that analyzes source code files and extracts their structure in a markdown format optimized for LLM consumption.
Features
Multi-language Support: Python, JavaScript, TypeScript, Java, C#, and Go
Fast Parsing: Uses tree-sitter for efficient AST parsing
Comprehensive Structure: Extracts classes, functions, nested elements
Line Numbers: Tracks start and end lines for each element
Nesting Levels: Shows the depth of nested elements
Parameters & Return Types: Extracts function signatures
Optional Docstrings: Configurable docstring extraction
Multi-File Analysis: Analyze single or multiple files in one request
Error Handling: Parses as much as possible and indicates error locations
LLM-Optimized Output: Markdown format designed for easy LLM consumption
Installation
Using uv (Recommended)
Using pip
Usage
Running the MCP Server
Or directly:
MCP Configuration
Add the following to your MCP client configuration (e.g., Claude Desktop):
MCP Tool: analyze_code_structure
Analyzes the structure of one or more source code files.
Parameters:
file_path(required): Path to the source code file(s) to analyze. Can be either:A single file path as a string (e.g.,
"src/models.py")An array of file paths (e.g.,
["src/models.py", "src/config.py"])
include_docstrings(optional, default: false): Whether to include docstrings in the output
Single File Analysis
Example Request:
Multi-File Analysis
Example Request:
Single File Output
Multi-File Output
Supported Languages
Language | File Extensions |
Python | .py |
JavaScript | .js, .mjs, .cjs |
TypeScript | .ts, .tsx |
Java | .java |
C# | .cs |
Go | .go |
Architecture
The server is organized into the following modules:
src/mcp/server.py: MCP server implementation with tool definitionssrc/parsers/tree_sitter.py: Tree-sitter parser integrationsrc/extractors/structure.py: Code structure extraction logicsrc/formatters/markdown.py: Markdown formatting for outputsrc/config.py: Language configuration and mappingssrc/models.py: Data models for code elements
Error Handling
The server attempts to parse as much of the file as possible, even when there are syntax errors. Errors are reported in a dedicated section:
Development
Running Tests
Code Formatting
Type Checking
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.