mcp-codebase-intelligence

mcp-codebase-intelligence

Provides a semantic understanding of your codebase by parsing with tree-sitter and building a graph of symbols and dependencies. Enables AI assistants to navigate code, analyze changes, and discover architecture using 18 tools with minimal context overhead.

Category
访问服务器

README

mcp-codebase-intelligence

Give your AI assistant a deep understanding of your codebase — without burning your context window.

CI npm License: MIT

An MCP server that parses your entire codebase with tree-sitter, builds a semantic graph of symbols, references, and dependencies, and lets AI assistants query it in real time. 18 tools, 8 languages, zero infrastructure.

Works with Claude Code, Cursor, VS Code, and any MCP-compatible client.


Why?

AI coding assistants are limited by what fits in their context window. When they need to understand your codebase — find callers of a function, trace a dependency chain, or assess the impact of a change — they resort to grep and guesswork, burning thousands of tokens on raw file reads.

mcp-codebase-intelligence gives them structured understanding in ~200 tokens instead of 50,000.

Without With codebase-intelligence
Understand a PR Read 1200 lines, open 23 files semantic_diff → 8 risk flags in 3 seconds
Find payment logic grep "payment" → 200 results search_codebase "payment processing" → 3 exact matches with docstrings
Impact of a change Manually trace callers for 30 min analyze_change_impact → 12 dependents across 6 files, instantly
Onboard to new repo Read code for 2 days architecture_diagram + query_codebase → 10 minutes
AI context cost Feed 50k tokens of raw files Structured 200-token summaries

No Docker. No cloud. No API keys. No embeddings. Just npx.


Quick Start

One-liner (no clone needed)

# Add to Claude Code via npx — auto-detects your project from cwd
claude mcp add codebase-intelligence npx mcp-codebase-intelligence

Or with an explicit project path:

claude mcp add codebase-intelligence \
  npx mcp-codebase-intelligence \
  -e PROJECT_ROOT=/path/to/your/project

JSON config (Claude Code, Cursor, VS Code)

Add to your MCP config file:

{
  "mcpServers": {
    "codebase-intelligence": {
      "command": "npx",
      "args": ["mcp-codebase-intelligence"],
      "env": {
        "PROJECT_ROOT": "/path/to/your/project"
      }
    }
  }
}

From source (for development)

git clone https://github.com/g-tiwari/mcp-codebase-intelligence.git
cd mcp-codebase-intelligence
npm install && npm run build

claude mcp add codebase-intelligence \
  node /path/to/mcp-codebase-intelligence/dist/index.js \
  -e PROJECT_ROOT=/path/to/your/project

That's it. The server indexes your codebase on startup and watches for changes.


Multi-Project Support

Work across multiple repos, monorepos, or a mix of both — from a single MCP server.

Auto-detection (zero config)

When no config is set, the server auto-detects your project:

  1. Finds the git root from your current directory
  2. Detects monorepo markers (pnpm, lerna, nx, npm/yarn workspaces, go.work, Cargo workspace)
  3. Indexes accordingly

Multi-repo projects

Use PROJECT_ROOTS for projects spanning multiple repositories:

claude mcp add codebase-intelligence \
  npx mcp-codebase-intelligence \
  -e PROJECT_ROOTS="/code/shared-models,/code/api-gateway,/code/android-app"

Config file (power users)

Create .codegraph.json in your project root (or ~/.codegraph/config.json for user-level config):

{
  "projects": {
    "tv-backend": {
      "root": "/code/monorepo",
      "include": ["packages/api-gateway", "packages/shared-models"],
      "roots": ["/code/android-app", "/code/webos-app"]
    },
    "music-service": {
      "roots": ["/code/music-api", "/code/music-models"]
    }
  }
}

Then use list_projects and switch_project tools to navigate between projects.


18 Tools

Code Navigation

Tool What it does
find_symbol Search for functions, classes, interfaces, types by name. Fuzzy matching, kind/scope filters. Returns signatures and docstrings.
get_references Find all callers/users of a symbol. Transitive: follow the chain N levels deep.
get_exports Public API surface of any file — all exported symbols with signatures.
get_dependencies Import graph for a file. Transitive: see the full dependency tree.
get_call_graph Who calls this function? What does it call? Tree or mermaid diagram output.

Code Intelligence (LSP-powered)

Tool What it does
goto_definition Jump to the definition of any symbol at a given position (TS/JS).
get_type_info Get the inferred type of any expression at a given position (TS/JS).
find_implementations Find all implementations of an interface or abstract method (TS/JS).

Change Analysis

Tool What it does
semantic_diff Feed it a git_ref (e.g. HEAD~1). It identifies affected symbols, finds all downstream dependents, and flags breaking changes.
analyze_change_impact Point it at specific lines in a file. It tells you which symbols are affected and who depends on them.

Architecture & Discovery

Tool What it does
architecture_diagram Auto-generate a mermaid diagram of module dependencies, grouped by directory.
query_codebase Ask natural language questions: "find all API endpoints", "what does the orders module do?", "what depends on the database layer?"
search_codebase Search symbols by their docstring/comment content. Find code by what it does, not what it's named.

Project Management

Tool What it does
list_projects Show all configured projects, their roots, and index stats.
switch_project Change active project context. All tools operate against the selected project.
add_project Add a new project at runtime. Indexes immediately and persists to config.

Admin

Tool What it does
get_index_stats How many files, symbols, references, and imports are indexed.
reindex Trigger a full re-index after major changes.

8 Languages

Language Extensions Parser
TypeScript .ts .tsx .mts .cts tree-sitter + LSP
JavaScript .js .jsx .mjs .cjs tree-sitter + LSP
Python .py .pyi tree-sitter
Go .go tree-sitter
Rust .rs tree-sitter
Java .java tree-sitter
C .c .h tree-sitter
C++ .cpp .cc .cxx .hpp .hxx .hh tree-sitter

All languages get symbol extraction, reference tracking, import/export analysis, call graphs, and docstring/comment extraction. TypeScript/JavaScript additionally get LSP-powered go-to-definition, type info, and find-implementations.


How It Works

Source Files ──> tree-sitter AST ──> Symbol Extraction ──> SQLite Graph
                                                              │
                                    File Watcher ─────────────┤ (incremental updates)
                                                              │
                                    MCP Tools ◄───────────────┘ (AI queries)
                                        │
                                    LSP Servers ──> Type Info (TS/JS)
  1. Parse — tree-sitter builds ASTs for all supported files
  2. Extract — language plugins walk the AST to find symbols, references, imports, inheritance, and docstrings
  3. Store — everything goes into a SQLite database with WAL mode, prepared statements, batch transactions
  4. Watch — chokidar monitors the filesystem; changed files are re-indexed incrementally
  5. Query — MCP tools run recursive SQL queries against the graph (transitive references, dependency chains)
  6. LSP — typescript-language-server provides type-aware intelligence for TS/JS

Performance

  • Batch indexing with single-transaction writes
  • Prepared statement cache -- 14 SQL statements prepared once at startup
  • In-memory hash cache -- skip DB lookups for unchanged files
  • Incremental updates -- only re-index files that actually changed

Tested on real-world projects: Zod, Express, gin, ripgrep, gson.


Testing

npm test

146 tests across 10 test suites covering all 8 language parsers, docstring extraction, grammar regression tests, the graph engine, and semantic diff.


Configuration

Environment Variables

Variable Description Default
PROJECT_ROOT Path to a single codebase to index git root of cwd()
PROJECT_ROOTS Comma-separated paths for multi-repo projects
DB_PATH Path to SQLite database file ~/.codegraph/graphs/<project>.db
LOG_LEVEL Logging verbosity: debug, info, warn, error info

Config Files

File Scope Purpose
.codegraph.json Project (check into git) Define project roots, monorepo scoping
~/.codegraph/config.json User Personal multi-project setup

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选