This project is an MCP-based Gemini CLI extension focused on context reduction for code analysis in large repositories.
Goal: help agentic workflows stay within strict token budgets by reducing unnecessary code context before inference.
This extension exposes the following tools:
analyze_directory- Builds a lightweight AST-based structure map of
.jsand.tsfiles.
- Builds a lightweight AST-based structure map of
search_codebase- Performs structural keyword matching against functions, classes, and limited JSDoc/file-name signals.
get_dependencies- Extracts shallow import/require dependencies for a target file.
view_file_skeleton- Returns a compressed code skeleton (signatures/types/classes, stripped implementations).
get_pruned_context- End-to-end pruning pipeline: search -> choose anchor file -> compress -> include dependencies until
tokenBudgetis reached.
- End-to-end pruning pipeline: search -> choose anchor file -> compress -> include dependencies until
The semantic retrieval is currently basic and must be enhanced for production-scale conceptual queries.
search_codebaseis mostly identifier-driven, not full semantic intent retrieval.- Natural language queries like "message sending flow" may return empty matches if similar identifiers are absent.
- This is a known gap and the next planned improvement area.
server.js: MCP server entry point and tool registration.src/indexer.js: directory indexing (AST structure extraction).src/searcher.js: structural keyword search.src/dependency.js: dependency extraction.src/compressor.js: skeleton/compression logic.src/pipeline.js: budgeted pruned-context assembly pipeline.gemini-extension.json: Gemini extension config.GEMINI.md: operational prompt protocol for using tools efficiently.
- Node.js 18+ (recommended)
- npm
- Gemini CLI with extension support
Clone/copy this folder to your machine, then open a terminal inside:
cd <path-to>/code-analyzernpm installUse your Gemini CLI local extension workflow and point it to this folder (the folder that contains gemini-extension.json).
The extension starts server.js over stdio using:
- command:
node - args:
${extensionPath}/server.js
Ask Gemini to run one of the tools, for example:
- "Use
analyze_directoryon<absolute-project-path>and summarize the architecture." - "Use
get_pruned_contextwithtokenBudget: 6000for querybuildPrunedContext."
You should see a tool execution line similar to:
get_pruned_context (code-analyzer MCP Server)
Use get_pruned_context on:
targetDirectory: D:\path\to\repo
query: "authentication flow"
tokenBudget: 6000
Then explain the critical modules and possible bug risks.
- This is a working MVP extension for context reduction in code analysis.
- It is intentionally focused on tooling mechanics, not full semantic retrieval quality yet.
- Semantic ranking and conceptual search quality are the primary next improvement track before large-monorepo validation.