A Model Context Protocol (MCP) server for code analysis using Tree-sitter. This tool provides capabilities to parse code, extract symbols, generate call graphs, find usages, and run custom queries against C, C++, and Python code.
- AST Retrieval: Get the full Abstract Syntax Tree (AST) of a file.
- Symbol Extraction: Find function and variable definitions.
- Call Graph: Generate a call graph for C/C++ functions.
- Tree-sitter Queries: Run custom S-expression queries against your code.
- Usage Finder: Find usages of functions and variables.
- Dependency Extraction: List file dependencies (includes/imports).
- Multi-Language Support: Currently supports C, C++, and Python.
- Python 3.10+
pip
- Clone the repository.
- Install the package in editable mode:
# Using uv (recommended) uv pip install -e . # Or using pip pip install -e .
This will install two command-line tools:
code-analysis: The CLI for analyzing filescode-analysis-server: The MCP server
You can now use these commands from anywhere on your system.
The CLI is available as the code-analysis command after installation.
code-analysis <file_path> [options]Get AST:
code-analysis test.c --astFind Function Definition:
code-analysis test.c --find-function my_funcFind Usages:
code-analysis test.c --find-usage my_funcGet Dependencies:
code-analysis test.c --dependenciesRun Custom Query:
code-analysis test.c --query "(function_definition) @func"To run the MCP server:
code-analysis-serverConfigure your MCP client (e.g., Claude Desktop) to use this server. See docs/MCP_USAGE.md for detailed configuration instructions.
- C: Full support (Symbols, Call Graph, Queries, Usage).
- C++: Full support.
- Python: Full support.
See the docs/ directory for more details: