contextshrinker
contextshrinker
contextshrinker is a zero-dependency, headless Model Context Protocol (MCP) server written in Go. It indexes local codebases into an embedded Kùzu graph database to drastically reduce LLM token bloat for autonomous AI agents (such as Claude Code, Cursor, Antigravity IDE, Aider, and Claude Desktop).
Instead of forcing AI agents to read raw source files or run clumsy grep-based searches, contextshrinker allows agents to query a semantic graph of your project's architectural dependencies, function call chains, and class inheritance structures—reducing input context consumption by 90% to 98%.
🚀 Key Features
Universal Agent Compatibility: Attaches seamlessly to any MCP-compliant coding tool or IDE over standard I/O (
stdio).Zero External Databases: Completely self-contained. Runs an in-process graph database (Kùzu) inside your project's local
.contextshrinker/directory.Auto-Managed LSP Daemons: Automatically detects project languages, programmatically provisions sandboxed language servers (like
goplsfor Go orpyrightfor Python) if missing, and queries their RPC interfaces in the background to build call graphs.Multi-Language Support: Full AST syntax parsing and semantic indexing for Go, Python, JavaScript, TypeScript, and Java.
Clean Project Isolation: Every workspace maintains its own
.contextshrinker/directory containing isolated configuration rules (.contextshrinker/ignore) and graph database files (.contextshrinker/db/).Live State Sync: Uses
fsnotifyto watch your files recursively. On save, a debounced delta update purges old nodes and re-indexes modified files in real-time.Interactive Graph Visualization: Generates a stunning, Vis.js-powered dark-mode HTML codebase visualization (
.contextshrinker/contextshrinker_graph.html) on-demand.
Related MCP server: code-graph-mcp
🛠️ Architecture: The Two-Pass Ingest
To index your code cleanly, contextshrinker runs a two-pass ingestion sequence:
graph TD
A[Walk Workspace] -->|Filter via .contextshrinker/ignore| B[Pass 1: Tree-sitter Syntax]
B -->|Create Nodes| C[(Kùzu Graph DB)]
C --> D[Pass 2: LSP Semantic Cross-References]
D -->|Create CALLS / IMPLEMENTS Edges| CPass 1 (Tree-sitter AST Extraction): Rapidly scans source files to extract entities (Functions/Methods, Classes/Structs, Variables) and their associated docstrings, inserting them as nodes.
Pass 2 (LSP Semantic Resolving): Queries background Language Server Protocol (LSP) daemons for cross-references to identify and connect invocations (
CALLS), imports (IMPORTS), and class inheritances (IMPLEMENTS/EXTENDS).
📥 Installation
Option 1: Precompiled Binaries (Fastest)
If you don't want to install Go, you can download a precompiled portable package for your platform:
Go to the Releases page.
Download the archive for your OS (
.tar.gzor.zip).Extract the archive. Keep the executable (
contextshrinker) and its dynamic library (libkuzu/kuzu_shared) in the same folder.Run the executable from that directory:
macOS / Linux:
chmod +x contextshrinker
./contextshrinker --helpWindows:
contextshrinker.exe --helpOption 2: Build from Source (Requires Go)
Prerequisites
Go (1.21 or later)
Node.js & npm (for automatically installing JS/TS and Python LSPs)
Compile
Clone the repository and run:
go build -o contextshrinkerTo install it directly to your system PATH:
go install🔌 Integration into Coding Agents
contextshrinker runs on-demand as a child process of your coding agent. Register the absolute path to the compiled binary in your client:
1. Antigravity IDE (Gemini Agent Panel)
Open the Antigravity IDE.
Click the
...(More Options) menu in the Agent Panel.Select "Manage MCP Servers" $\rightarrow$ "View raw config".
Register the server in your
mcp_config.json:{ "mcpServers": { "contextshrinker": { "command": "/absolute/path/to/contextshrinker" } } }
2. Claude Code (CLI)
Add the server automatically:
claude mcp add contextshrinker /absolute/path/to/contextshrinker3. Cursor IDE
Navigate to Settings $\rightarrow$ Features $\rightarrow$ MCP.
Click + Add New MCP Server.
Set configuration:
Name:
contextshrinkerType:
commandCommand:
/absolute/path/to/contextshrinker
4. Claude Desktop
Add it to your ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"contextshrinker": {
"command": "/absolute/path/to/contextshrinker"
}
}
}🧰 Exposed Tools
Once configured, the following tools will automatically be available to your AI coding agents:
search_codebaseArguments:
query(string)Description: Executes Full-Text Search and Cypher queries to match structures and docstrings across classes, functions, and variables.
get_call_chainArguments:
target_function(string),depth(integer, max 5)Description: Resolves upstream caller chains using variable-length path Cypher queries to map calling dependencies.
get_file_structureArguments:
file_path(string)Description: Retrieves the complete abstract node structure (classes, interfaces, methods, variables) contained in a single file without feeding the raw text contents to the context window.
visualize_codebaseDescription: Triggers an on-demand HTML export, saving
contextshrinker_graph.htmlinside your.contextshrinker/directory.
get_architecture_reportDescription: Retrieves the complete codebase architectural health report containing metrics on God Objects, coupling hotspots, cycles, dead unexported functions, AI metrics (SCR, DCR, BVI, AOI, Call Chain Depth Index - CDI), and actionable code quality guidelines (Jeff Dean principles) with AI system prompt directives.
🏛️ Codebase & Architecture Optimization
You can use contextshrinker to systematically audit coupling, analyze domain boundaries (DDD), and guide code restructuring (e.g. splitting a monolith into modules) using LLMs.
Optimization Workflow
Generate the Architectural Metrics & Guidelines: Run the analysis command in your terminal to inspect the codebase graph and generate a report:
./contextshrinker analyzeThis generates
contextshrinker-report.mdcontaining metrics for God Objects (high outbound coupling), Black Holes (high inbound calls), Cyclic Import Paths, Dead Code (unused private functions), AI Metrics (including Call Chain Depth Index - CDI), and Actionable Code Quality & LLM Architecture Guidelines (Jeff Dean principles).Obtaining the System Prompt: Retrieve the principal systems architect prompt from the CLI:
./contextshrinker prompt architectAnalyzing with LLMs:
Set the output of the
prompt architectcommand as the System Prompt for your LLM.Provide the contents of the generated
contextshrinker-report.mdas the Context / Input.Ask the LLM to propose bounded context splits or interface boundaries.
Agentic / Tool-Use Workflows: If using an MCP-compatible agent (like Antigravity IDE, Claude Code, or Cursor), you can ask it directly:
"Run the contextshrinker analysis report, read the generated markdown, and act as a Systems Architect to audit our design hotspots. Use the
get_call_chainandget_file_structuretools to inspect the coupling before suggesting concrete module extractions."
⚙️ Configuration & Ignores
To prevent workspace graph bloat, standard library and dependency folders (node_modules/, vendor/, .git/, etc.) are ignored by default.
To add custom ignores, initialize the project and generate a .csignore file at your workspace root by running:
contextshrinker initEach line in .csignore is matched recursively:
# Custom project ignores
*.log
tmp-output/
dist/
.vitepress💡 Best Practices for Large Projects
If you are using contextshrinker on a medium-to-large project (e.g., hundreds or thousands of files), running the initial codebase ingestion directly from inside an LLM/agent prompt (like Claude Code or Cursor) can cause agent timeout issues. This happens because the agent has a tight timeout limit (typically 60 seconds) while waiting for the first-time workspace parsing and LSP references resolution to complete.
To prevent this, follow this optimized workflow in your terminal before starting the agent:
Initialize the workspace: Run the initialization command to create the configuration directory and default ignore list:
contextshrinker initConfigure your ignores: Open the generated
.csignorefile at your workspace root and add any large directories you want to exclude (e.g. documentation sites, test assets, built build folders).Build the database offline: Run the analyze command once from your terminal to build the initial graph database:
contextshrinker analyzeThis performs the heavy lifting of Tree-sitter parsing and LSP semantic cross-referencing offline. Once the database is populated, subsequent agent requests and live state syncs will run incrementally in seconds, preventing any future timeouts!
📊 Command Line Interface (CLI) Mode
You can query the codebase graph, start the MCP server daemon explicitly, retrieve systems architect prompts, or generate health analysis reports directly from your terminal.
1. Start the MCP Server
By default, running ./contextshrinker with no arguments starts the MCP server daemon. You can also trigger it explicitly:
./contextshrinker start2. Run Codebase Architectural Analysis
Analyze the codebase structure (God objects, inbound call hot-spots, cyclic imports, dead code, Call Chain Depth Index - CDI, and LLM code quality guidelines) and write a report to contextshrinker-report.md:
./contextshrinker analyze3. Print Principal Systems Architect Prompt
Print the Domain-Driven Design (DDD) principal systems architect system prompt to stdout:
./contextshrinker prompt architect4. Search the Codebase
Find functions, classes, or variables matching a query:
./contextshrinker search "IngestWorkspace"5. Trace Call Chains
Trace upstream callers of a target function name (default depth is 3, maximum is 5):
./contextshrinker call-chain "IngestWorkspace" --depth 36. Retrieve File Structure
Get the structure of a file without reading its full text content:
./contextshrinker structure "main.go"7. Generate Interactive Visualization
Generate a Vis.js codebase graph representation:
./contextshrinker visualizeOpen the generated .contextshrinker/contextshrinker_graph.html in any browser to explore your project's architecture interactively.
Options (Global Flags)
--workspace <path>: Specifies the project directory (defaults to.).--db <path>: Specifies the database storage directory (defaults to.contextshrinker/db).--reindex: Forces a full workspace ingestion scan (re-parsing code and mapping LSP relationships) before executing the query. If the database is empty, ingestion runs automatically.Note: Because Kuzu DB establishes an exclusive file-level lock, ensure your IDE's MCP client is paused or stopped when running CLI commands on the active database, or use a different workspace/db directory with the CLI flags.
📄 License
This project is licensed under the MIT License.
This server cannot be installed
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 Servers
- AlicenseAqualityCmaintenanceCross-repository code knowledge graph MCP server for Java, Kotlin, JavaScript, and TypeScript. Indexes source code into embedded KuzuDB via tree-sitter and exposes 30+ tools for call-flow tracing, multi-hop taint analysis (OWASP/CWE/PCI/STIG), entry-point reachability filtering, performance hotspot detection, and license compliance — without reading source files. 95% fewer tokens vs source-read331MIT
- AlicenseNot gradedqualityAmaintenanceA high-performance code knowledge graph server implementing MCP, indexing codebases into a structured AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing.2,78368MIT
- AlicenseAqualityAmaintenanceHigh-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 159 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.1539,846MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for semantic code search and dependency graph analysis. Indexes codebases into a knowledge graph with vector embeddings for AI-powered code understanding.9MIT
Related MCP Connectors
Enterprise code intelligence for M&A, security audits, and tech debt. Hosted server with 200k free.
AI Agent with Architectural Memory. Impact analysis (free), tests and code from the graph (pro).
An MCP server that gives your AI access to the source code and docs of all public github repos
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/bauhaus28/contextshrinker'
If you have feedback or need assistance with the MCP directory API, please join our Discord server