MCP Codebase Analyzer
Enables LLMs to explore codebases structurally via MCP tools for outlines, function sources, imports, complexity, git changes, and dead code detection, reducing token usage by avoiding raw file ingestion.
README
MCP Codebase Analyzer
A Model Context Protocol (MCP) server that lets an LLM explore a codebase structurally - outlines, signatures, dependencies, complexity, and change impact, instead of ingesting raw files into context.
The Problem
Feeding entire files or repositories into an LLM's context window wastes tokens and increases hallucination risk. Most of that content is irrelevant to any given question. If someone asks "what does read_file do," the model doesn't need the whole file — it needs the function's signature, docstring, and maybe its body, nothing else.
The Approach
Instead of dumping raw text, this server parses code into an Abstract Syntax Tree using Tree-sitter and exposes that structure through a set of MCP tools. An LLM client (e.g. Claude Desktop) can query exactly what it needs, a directory outline, one function's source, an import graph, a complexity score and drill deeper only when the task requires it. The result is a smaller, more precise context footprint and fewer tokens spent on irrelevant code.
Tech Stack
- Python 3.13
- FastMCP - MCP server framework
- Tree-sitter (+ language grammars for Python and JavaScript) - structural parsing
- Git (via subprocess) - diff and change-impact analysis
- GitHub API - remote repository ingestion
- MCP Inspector - protocol-level testing and debugging
Tools
| Tool | Description |
|---|---|
scan_directory |
High-speed recursive directory traversal with noise pruning (.venv, node_modules, .git, etc). |
get_outline |
Maps out function and class definitions, signatures, return types, docstrings, and line numbers for a file. |
get_function_source |
Extracts the exact source of a single named function or method. |
search_symbols |
AST-aware symbol lookup across the workspace (finds definitions, not just text matches). |
search_code |
Regex-based text search across allowed file types. |
get_imports |
Maps how internal and external modules connect to one another. |
score_complexity |
Calculates cyclomatic complexity per function to highlight refactor targets. |
analyze_git_changes |
Maps uncommitted git modifications to the specific functions they affect. |
analyze_dead_code |
Cross-references defined functions against usage to flag likely-unused code. |
analyze_churn_heatmap |
Combines file size with git commit frequency to surface large, frequently-changed files — a common code-smell signal. |
analyze_github_repo |
Downloads and mounts a remote GitHub repository into a local sandbox for the same structural analysis. |
Design Principles
- On-demand over front-loaded. Every tool returns the minimum structure needed to answer the next question, not the whole file.
- Sandboxed by default. All file access is path-bounded to a configured project root, preventing traversal outside the allowed workspace.
- Composable. Higher-level tools (dead code detection, churn heatmaps) are built by combining outputs from lower-level tools (outline, search, git) rather than duplicating parsing logic.
- Language-extensible. Tree-sitter's grammar model means adding a new language is a matter of adding a grammar + query, not rewriting the architecture.
Status
Phase 1 of a three-phase project. Phase 2 is a self-hosted home server (reverse proxy, monitoring, CI/CD). Phase 3 merges the two: applying this same "structured query over raw dump" philosophy to infrastructure — an LLM querying and managing a live server the same way it queries a codebase here.
Running Locally
git clone <this-repo>
cd mcp-codebase-analyzer
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txt
fastmcp run server.py
Test with MCP Inspector:
npx @modelcontextprotocol/inspector fastmcp run server.py
Or connect it to Claude Desktop as an MCP server for real LLM tool-use testing.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.