Multi-layer codebase analysis MCP server with Gemini AI.
Progressive Disclosure: Start cheap (surface), reveal more on demand. Don't analyze everything upfront.
Budget Awareness: Track tokens. Surface is free, structural is cheap, semantic is expensive.
Graceful Degradation: Partial failures don't break analysis. Capture warnings, continue.
Agent-First Design: Output structured for AI agents - expandable sections, cost estimates, next steps.
bun install && bun run buildSee docs/ARCHITECTURE.md for system design.
| Path | Purpose |
|---|---|
src/mcp/server.ts |
MCP server entry |
src/mcp/tools/ |
MCP tool definitions |
src/cli/index.ts |
CLI interface |
src/core/orchestrator.ts |
Analysis coordination |
src/core/layers/ |
Analysis layers |
src/core/gemini.ts |
Gemini AI client |
src/core/cache.ts |
Analysis result cache |
| Tool | Purpose | Cost |
|---|---|---|
analyze_repo |
Full analysis with expandable sections | Varies |
query_repo |
Ask questions about a codebase | Medium |
expand_section |
Drill into specific sections | Low |
read_files |
Read source files from cached analysis | None |
find_patterns |
Pattern detection | Medium |
trace_dataflow |
Data flow tracing | Medium |
get_analysis_capabilities |
List capabilities | None |
| Depth | What It Does | LLM Cost |
|---|---|---|
surface |
File enumeration, languages, entry points | ~0 |
standard |
+ structural analysis with Tree-sitter | Low |
deep |
+ semantic analysis with Gemini | High |
- Create
src/mcp/tools/your-tool.ts(schema + execute) - Export from
src/mcp/tools/index.ts - Register in
src/mcp/server.ts - Add CLI command in
src/cli/index.ts(optional) bun run build
GEMINI_API_KEY=... # Optional. Required for semantic analysis, patterns, dataflow.Also reads from ~/.config/codebase-analyzer/config.json as fallback:
{"geminiApiKey": "your_key"}Uses npm trusted publishing (OIDC) - no NPM_TOKEN secret needed.
- Bump version:
npm version patch(or minor/major) - Push with tags:
git push && git push --tags
CI automatically publishes to npm when version changes on main.
When analyzing GitHub repos, temp clone directory name (cba-XXXXX) was shown instead of repo name. Fixed by extracting owner/repo from GitHub URLs before resolving to local path and passing sourceName through analysis chain.
Pattern: Preserve user-facing identifiers separately from internal paths.
Multiple bugs from accessing wrong property names (l.name vs l.language, totalFiles vs fileCount).
Pattern: When adding new types, grep for all usages of old patterns and update together.
Claude Code plugin system adds complexity (agents, commands, skills, plugin.json) with marginal benefit for an MCP server. Env vars don't propagate to plugin MCP subprocesses, causing endless debugging. Simpler to ship as a plain MCP server with npx.
Pattern: Ship MCP servers as MCP servers, not plugins. Use plugins only when you need agents/commands/skills and don't need env vars.