TreeSitter Code Structure MCP Server
The TreeSitter Code Structure MCP Server analyzes source code files to extract their structural elements in an LLM-optimized markdown format.
Capabilities:
Multi-language support: Parse Python, JavaScript, TypeScript, Java, C#, Go, and Rust files
Single or multi-file analysis: Process individual files or batch analyze multiple files in a single request
Comprehensive structure extraction: Extract classes, functions, methods, and nested elements with hierarchical relationships
Detailed element tracking: Capture start/end line numbers, nesting depth, and parent relationships for each element
Function signature analysis: Extract parameters with types and return type information
Optional docstring inclusion: Configurable option to include or exclude documentation
Error-resilient parsing: Handle syntax errors gracefully, extracting as much as possible and reporting error locations
LLM-optimized output: Generate token-efficient markdown with consistent structure
Fast parsing: Utilize tree-sitter for efficient AST parsing
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#, Go, and Rust
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
Related MCP server: Scantool - File Scanner MCP
Installation
Using uv (Recommended)
uv syncUsing pip
pip install -r requirements.txtUsage
Running the MCP Server
uv run python src/server.pyOr directly:
python src/server.pyMCP Configuration
Add the following to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"CodeStructureAnalyzer": {
"command": "uv",
"args": [
"--directory",
"/path/to/TreeSitterMcp",
"run",
"python",
"src/server.py"
]
}
}
}MCP Tool: query
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:
{
"name": "query",
"arguments": {
"file_path": "src/models.py",
"include_docstrings": true
}
}Multi-File Analysis
Example Request:
{
"name": "query",
"arguments": {
"file_path": ["src/models.py", "src/config.py", "src/server.py"],
"include_docstrings": false
}
}Output Format
The output is optimized for token efficiency and follows this schema:
Format: ### Name (Start-End, Nesting, [Parent]) | - Type | - [Parameters] | - [Return Type] | - [Docstring]
Example Output:
Format: ### `Name` (Start-End, Nesting, [Parent]) | - Type | - [Parameters] | - [Return Type] | - [Docstring]
# `src/models.py`
### `MyClass` (10-50, N:0)
- Class
- A sample class for demonstration.
### `__init__` (15-25, N:1, P: `MyClass`)
- Function
- (self, param1: str, param2: int)
- -> None
- Initialize the class.Multi-File Output Example
Format: ### `Name` (Start-End, Nesting, [Parent]) | - Type | - [Parameters] | - [Return Type] | - [Docstring]
# `src/models.py`
### `MyClass` (10-50, N:0)
- Class
...
---
# `src/config.py`
### `get_language_from_extension` (10-20, N:0)
- Function
...Supported Languages
Language | File Extensions |
Python | .py |
JavaScript | .js, .mjs, .cjs |
TypeScript | .ts, .tsx |
Java | .java |
C# | .cs |
Go | .go |
Rust | .rs |
Architecture
The server is organized into the following modules:
src/mcp_impl/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:
## Parse Errors
⚠️ **Error at Line 42**: Syntax errorreturn self.process(itemDevelopment
Running Tests
uv run pytestCode Formatting
uv run black src/Type Checking
uv run mypy src/License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Available Tools
1 toolanalyze_code_structureA
Analyze the structure of one or more source code files and return classes, functions, their line numbers, nesting levels, parameters, and return types. Supports Python, JavaScript, TypeScript, Java, C#, and Go. Accepts either a single file path (string) or an array of file paths.
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path(s) to the source code file(s) to analyze | |
| include_docstrings | No | Whether to include docstrings in the output (default: false) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It discloses behavioral traits such as the types of analysis performed and supported languages, but it does not cover aspects like error handling, performance characteristics, or authentication needs. The description adds useful context but leaves gaps in behavioral disclosure.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is front-loaded with the core purpose, followed by supporting details in two efficient sentences. Every sentence adds value: the first defines the analysis scope and output, the second specifies languages and input formats. There is no wasted text.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity of code analysis, no annotations, and no output schema, the description is moderately complete. It covers the purpose, input formats, and languages, but lacks details on output structure, error cases, or limitations. This is adequate for basic understanding but could be more comprehensive for a tool of this nature.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema fully documents the parameters. The description adds marginal value by mentioning the input format options (single file path or array) and supported languages, but it does not provide additional semantic details beyond what the schema already specifies. Baseline 3 is appropriate here.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the specific action ('analyze the structure'), the target resource ('source code files'), and the detailed output ('classes, functions, their line numbers, nesting levels, parameters, and return types'). It also specifies supported programming languages, making the purpose highly specific and comprehensive.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage by specifying supported languages and input formats (single file path or array), but it does not provide explicit guidance on when to use this tool versus alternatives, prerequisites, or exclusions. With no sibling tools, this is adequate but lacks explicit contextual framing.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool has a clear, singular purpose focused on analyzing code structure across multiple programming languages.
The single tool name 'analyze_code_structure' follows a clear verb_noun pattern and is descriptive. Since there is only one tool, consistency is inherently perfect with no deviations to assess.
A single tool is too few for a server focused on code structure analysis, as it suggests an incomplete or overly simplistic surface. For a domain like code analysis, typical servers would include multiple tools for different aspects (e.g., parsing, querying, modifying).
The tool set is severely incomplete for the implied domain of code structure analysis. While the single tool provides analysis, there are obvious gaps such as tools for querying specific elements, modifying code, or handling other structural operations, which limits agent workflows.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
AI-powered codebase analysis — call graphs, security, dead code, complexity. 150+ tools.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to understand and navigate codebases through structural analysis. Provides code mapping, symbol search, and impact analysis using ast-grep for accurate parsing of Python, JavaScript, TypeScript, and Go projects.452MIT
- AlicenseAqualityAmaintenanceAnalyzes source code structure across multiple languages using tree-sitter, extracting classes, functions, methods, and metadata with precise line numbers for efficient codebase exploration and AI-assisted development.83MIT
- AlicenseAqualityDmaintenanceAnalyzes codebases and extracts all symbols (functions, classes, methods, interfaces, etc.) from 10+ programming languages into LLM-optimized markdown format. Enables AI assistants to understand entire project structures efficiently without processing full source code.215MIT
- AlicenseNot gradedqualityDmaintenanceA structural codebase indexer that exposes 18 tools via the Model Context Protocol for AI-assisted code navigation, enabling efficient querying of functions, classes, dependencies, and call chains without reading entire files.62AGPL 3.0
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- 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/DarkEden-coding/CodeStructureMCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server