loading…
Search for a command to run...
loading…
Analyzes source code across multiple languages to extract structural elements like classes, functions, and parameters using tree-sitter. It provides LLM-optimiz
Analyzes source code across multiple languages to extract structural elements like classes, functions, and parameters using tree-sitter. It provides LLM-optimized markdown output that includes nesting levels, line numbers, and signatures to facilitate codebase navigation.
A fast Model Context Protocol (MCP) server that analyzes source code files and extracts their structure in a markdown format optimized for LLM consumption.
uv sync
pip install -r requirements.txt
uv run python src/server.py
Or directly:
python src/server.py
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"
]
}
}
}
queryAnalyzes 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:"src/models.py")["src/models.py", "src/config.py"])include_docstrings (optional, default: false): Whether to include docstrings in the outputExample Request:
{
"name": "query",
"arguments": {
"file_path": "src/models.py",
"include_docstrings": true
}
}
Example Request:
{
"name": "query",
"arguments": {
"file_path": ["src/models.py", "src/config.py", "src/server.py"],
"include_docstrings": false
}
}
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.
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
...
| Language | File Extensions |
|---|---|
| Python | .py |
| JavaScript | .js, .mjs, .cjs |
| TypeScript | .ts, .tsx |
| Java | .java |
| C# | .cs |
| Go | .go |
| Rust | .rs |
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 elementsThe 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 error
return self.process(item
uv run pytest
uv run black src/
uv run mypy src/
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"treesitter-code-structure-mcp-server": {
"command": "npx",
"args": []
}
}
}