AiDex
AiDex
别再把 80% 的 AI 上下文窗口浪费在代码搜索上了。
AiDex 是一个 MCP 服务器,通过持久化的预构建索引,让 AI 编程助手能够即时访问您的整个代码库。适用于任何兼容 MCP 的 AI 助手:Claude Code、Claude Desktop、Cursor、Windsurf、Gemini CLI、VS Code Copilot 等。


功能概览 — 一个服务器集成 30 种工具
类别 | 工具 | 功能描述 |
搜索与索引 |
| 索引您的项目,按名称搜索标识符(精确/包含/以...开头),基于时间的过滤 |
签名 |
| 获取任何文件的类 + 方法,无需读取文件内容 — 支持单个文件或 glob 模式 |
项目概览 |
| 入口点、语言分布、带统计信息的文件树、按类型列出文件 |
跨项目 |
| 链接依赖项,发现已索引的项目 |
全局搜索 |
| 同时搜索您所有的项目 — “我曾经写过 X 吗?” |
指南 |
| 持久化的 AI 指令与编码规范 — 在所有项目中共享 |
会话 |
| 跟踪会话,检测外部更改,为下一次会话留下笔记(支持可搜索的历史记录) |
任务积压 |
| 内置任务管理,支持优先级、标签、自动记录历史以及定时/循环任务 |
日志中心 |
| 通用日志接收器 — 任何程序通过 HTTP 发送日志,AI 可查询,并在 Viewer 中实时查看 |
截图 |
| 针对 LLM 优化的跨平台屏幕捕获 — 缩放 + 颜色缩减可节省高达 95% 的 token |
查看器 |
| 交互式浏览器 UI,包含文件树、签名、任务、日志和实时重载 |
支持 11 种语言 — C#, TypeScript, JavaScript, Rust, Python, C, C++, Java, Go, PHP, Ruby
# Find where "PlayerHealth" is defined — 1 call, ~50 tokens
aidex_query({ term: "PlayerHealth" })
→ Engine.cs:45, Player.cs:23, UI.cs:156
# All methods in a file — without reading the whole file
aidex_signature({ file: "src/Engine.cs" })
→ class GameEngine { Update(), Render(), LoadScene(), ... }
# What changed in the last 2 hours?
aidex_query({ term: "render", modified_since: "2h" })
# Search across ALL your projects at once
aidex_global_query({ term: "TransparentWindow", mode: "contains" })
→ Found in: LibWebAppGpu (3 hits), DebugViewer (1 hit)
# Leave a note for your next session
aidex_note({ path: ".", note: "Test the parser fix after restart" })
# Create a task while working
aidex_task({ path: ".", action: "create", title: "Fix edge case in parser", priority: 1, tags: "bug" })目录
问题所在
每当您的 AI 助手搜索代码时,它都会:
Grep 数千个文件 → 数百个结果淹没上下文
读取 一个又一个文件来理解结构 → 消耗更多上下文
遗忘 会话结束时的所有内容 → 从头开始重复
一个简单的“X 在哪里定义?”问题可能会消耗 2000+ 个 token。重复 10 次,您仅在导航上就烧掉了半个上下文窗口。
解决方案
索引一次,永久查询:
# Before: grep flooding your context
AI: grep "PlayerHealth" → 200 hits in 40 files
AI: read File1.cs, File2.cs, File3.cs...
→ 2000+ tokens consumed, 5+ tool calls
# After: precise results, minimal context
AI: aidex_query({ term: "PlayerHealth" })
→ Engine.cs:45, Player.cs:23, UI.cs:156
→ ~50 tokens, 1 tool call结果:代码导航节省 50-80% 的上下文。
为什么不直接用 Grep?
Grep/Ripgrep | AiDex | |
上下文使用 | 每次搜索 2000+ token | ~50 token |
结果 | 所有文本匹配 | 仅标识符 |
精度 |
|
|
持久性 | 每次重新开始 | 索引跨会话存在 |
结构 | 平面文本搜索 | 了解方法、类、类型 |
Grep 的真正代价:每个 grep 结果都包含周围的上下文。在大型项目中搜索 User,您会得到数百个命中结果——注释、字符串、部分匹配。您的 AI 会阅读所有这些内容,在噪音上浪费上下文 token。
AiDex 索引标识符:它使用 Tree-sitter 真正解析您的代码。当您搜索 User 时,您得到的是类定义、方法参数、变量声明——而不是每一个提到“user”的注释。
工作原理
索引您的项目一次(每 1000 个文件约 1 秒)
aidex_init({ path: "/path/to/project" })AI 搜索索引而不是 grep
aidex_query({ term: "Calculate", mode: "starts_with" }) → All functions starting with "Calculate" + exact line numbers aidex_query({ term: "Player", modified_since: "2h" }) → Only matches changed in the last 2 hours无需读取整个文件即可获取文件概览
aidex_signature({ file: "src/Engine.cs" }) → All classes, methods, and their signatures
索引存储在 .aidex/index.db (SQLite) 中 — 快速、便携、无外部依赖。
特性
Tree-sitter 解析:真正的代码解析,而非正则 — 索引标识符,忽略关键字和噪音
每次搜索 ~50 个 Token:对比 grep 的 2000+ — 让您的 AI 将上下文保留用于实际工作
持久化索引:跨会话存在 — 无需重新扫描,无需重新读取
增量更新:更改后仅重新索引单个文件,而非整个项目
基于时间的过滤:查找过去一小时、一天或一周内更改的内容
自动清理:排除的文件(如构建输出)会自动从索引中删除
零依赖:SQLite 采用 WAL 模式 — 单文件、快速、便携
支持的语言
语言 | 扩展名 |
C# |
|
TypeScript |
|
JavaScript |
|
Rust |
|
Python |
|
C |
|
C++ |
|
Java |
|
Go |
|
PHP |
|
Ruby |
|
快速开始
1. 安装
npm install -g aidex-mcp就是这样。 安装后会自动运行设置 — 它会检测您已安装的 AI 客户端(Claude Code、Claude Desktop、Cursor、Windsurf、Gemini CLI、VS Code Copilot)并将 AiDex 注册为 MCP 服务器。它还会将使用说明添加到您的 AI 配置中(~/.claude/CLAUDE.md, ~/.gemini/GEMINI.md)。
手动重新运行设置:aidex setup | 取消注册:aidex unsetup | 跳过自动设置:AIDEX_NO_SETUP=1 npm install -g aidex-mcp
2. 或手动向您的 AI 助手注册
对于 Claude Code (~/.claude/settings.json 或 ~/.claude.json):
{
"mcpServers": {
"aidex": {
"type": "stdio",
"command": "aidex",
"env": {}
}
}
}对于 Claude Desktop (Windows 上为 %APPDATA%/Claude/claude_desktop_config.json):
{
"mcpServers": {
"aidex": {
"command": "aidex"
}
}
}注意:
aidex和aidex-mcp均可用作命令名称。
重要: 配置中的服务器名称决定了 MCP 工具的前缀。使用如上所示的
"aidex"— 这将为您提供诸如aidex_query,aidex_signature等工具名称。使用不同的名称(例如"codegraph")将相应地更改前缀。
对于 Gemini CLI (~/.gemini/settings.json):
{
"mcpServers": {
"aidex": {
"command": "aidex"
}
}
}对于 VS Code Copilot (在命令面板中运行 MCP: Open User Configuration):
{
"servers": {
"aidex": {
"type": "stdio",
"command": "aidex"
}
}
}对于其他 MCP 客户端:请参阅您客户端的 MCP 服务器配置文档。
3. 让您的 AI 真正使用它
添加到您的 AI 指令中(例如 Claude Code 的 ~/.claude/CLAUDE.md,或您 AI 客户端的等效文件)。这告诉 AI 何时以及如何使用 AiDex 而不是 grep:
## AiDex - Persistent Code Index (MCP Server)
AiDex provides fast, precise code search through a pre-built index.
**Always prefer AiDex over Grep/Glob for code searches.**
### REQUIRED: Before using Grep/Glob/Read for code searches
我是否需要搜索代码? ├── 存在 .aidex/ → 停止!改用 AiDex ├── 缺少 .aidex/ → 运行 aidex_init (不要询问),然后使用 AiDex └── 配置/日志/文本 → 使用 Grep/Read 即可
**NEVER do this when .aidex/ exists:**
- ❌ `Grep pattern="functionName"` → ✅ `aidex_query term="functionName"`
- ❌ `Grep pattern="class.*Name"` → ✅ `aidex_query term="Name" mode="contains"`
- ❌ `Read file.cs` to see methods → ✅ `aidex_signature file="file.cs"`
- ❌ `Glob pattern="**/*.cs"` + Read → ✅ `aidex_signatures pattern="**/*.cs"`
### Session-Start Rule (REQUIRED — every session, no exceptions)
1. Call `aidex_session({ path: "<project>" })` — detects external changes, auto-reindexes
2. If `.aidex/` does NOT exist → run `aidex_init` automatically (don't ask)
3. If a session note exists → **show it to the user** before continuing
4. **Before ending a session:** always leave a note about what to do next
### Question → Right Tool
| Question | Tool |
|----------|------|
| "Where is X defined?" | `aidex_query term="X"` |
| "Find anything containing X" | `aidex_query term="X" mode="contains"` |
| "All functions starting with X" | `aidex_query term="X" mode="starts_with"` |
| "What methods does file Y have?" | `aidex_signature file="Y"` |
| "Explore all files in src/" | `aidex_signatures pattern="src/**"` |
| "Project overview" | `aidex_summary` + `aidex_tree` |
| "What changed recently?" | `aidex_query term="X" modified_since="2h"` |
| "What files changed today?" | `aidex_files path="." modified_since="8h"` |
| "Have I ever written X?" | `aidex_global_query term="X" mode="contains"` |
| "Which project has class Y?" | `aidex_global_signatures term="Y" kind="class"` |
| "All indexed projects?" | `aidex_global_status` |
### Search Modes
- **`exact`** (default): Finds only the exact identifier — `log` won't match `catalog`
- **`contains`**: Finds identifiers containing the term — `render` matches `preRenderSetup`
- **`starts_with`**: Finds identifiers starting with the term — `Update` matches `UpdatePlayer`, `UpdateUI`
### All Tools (30)
| Category | Tools | Purpose |
|----------|-------|---------|
| Search & Index | `aidex_init`, `aidex_query`, `aidex_update`, `aidex_remove`, `aidex_status` | Index project, search identifiers (exact/contains/starts_with), time filter |
| Signatures | `aidex_signature`, `aidex_signatures` | Get classes + methods without reading files |
| Overview | `aidex_summary`, `aidex_tree`, `aidex_describe`, `aidex_files` | Entry points, file tree, file listing by type |
| Cross-Project | `aidex_link`, `aidex_unlink`, `aidex_links`, `aidex_scan` | Link dependencies, discover projects |
| Global Search | `aidex_global_init`, `aidex_global_query`, `aidex_global_signatures`, `aidex_global_status`, `aidex_global_refresh` | Search across ALL projects |
| Guidelines | `aidex_global_guideline` | Persistent AI instructions & conventions (key-value, global) |
| Sessions | `aidex_session`, `aidex_note` | Track sessions, leave notes (with searchable history) |
| Tasks | `aidex_task`, `aidex_tasks` | Built-in backlog with priorities, tags, summaries, auto-logged history, scheduled/recurring tasks |
| Log Hub | `aidex_log` | Universal log receiver — any program sends logs via HTTP, AI queries them, live in Viewer |
| Screenshots | `aidex_screenshot`, `aidex_windows` | Screen capture with LLM optimization (scale + color reduction, no index needed) |
| Viewer | `aidex_viewer` | Interactive browser UI with file tree, signatures, tasks, and live logs |
**11 languages:** C#, TypeScript, JavaScript, Rust, Python, C, C++, Java, Go, PHP, Ruby
### Session Notes
Leave notes for the next session — they persist in the database:aidex_note({ path: ".", note: "重启后测试修复" }) # 写入 aidex_note({ path: ".", note: "同时检查边界情况", append: true }) # 追加 aidex_note({ path: "." }) # 读取 aidex_note({ path: ".", search: "parser" }) # 搜索历史 aidex_note({ path: ".", clear: true }) # 清除
- **Before ending a session:** automatically leave a note about next steps
- **User says "remember for next session: ..."** → write it immediately
### Task Backlog
Track TODOs, bugs, and features right next to your code index:aidex_task({ path: ".", action: "create", title: "修复 bug", priority: 1, tags: "bug" }) aidex_task({ path: ".", action: "update", id: 1, status: "done" }) aidex_task({ path: ".", action: "log", id: 1, note: "找到根本原因" }) aidex_tasks({ path: ".", status: "active" })
定时与循环任务
aidex_task({ path: ".", action: "create", title: "检查 PR 状态", due: "3d", interval: "3d", task_action: "gh pr list" })
Priority: 1=high, 2=medium, 3=low | Status: `backlog → active → done | cancelled`
### Global Search (across all projects)
aidex_global_init({ path: "/path/to/all/repos" }) # 扫描并注册 aidex_global_init({ path: "...", index_unindexed: true }) # + 自动索引小型项目 aidex_global_query({ term: "TransparentWindow", mode: "contains" }) # 全局搜索 aidex_global_signatures({ term: "Render", kind: "method" }) # 全局查找方法 aidex_global_status({ sort: "recent" }) # 列出所有项目
### Screenshots
aidex_screenshot() # 全屏 aidex_screenshot({ mode: "active_window" }) # 活动窗口 aidex_screenshot({ mode: "window", window_title: "VS Code" }) # 特定窗口 aidex_screenshot({ scale: 0.5, colors: 2 }) # 黑白,半尺寸 (LLM 理想选择) aidex_screenshot({ colors: 16 }) # 16 色 (UI 可读) aidex_windows({ filter: "chrome" }) # 查找窗口标题
No index needed. Returns file path → use `Read` to view immediately.
**LLM optimization strategy:** Always start with aggressive settings, then retry if unreadable:
1. First try: `scale: 0.5, colors: 2` (B&W, half size — smallest possible)
2. If unreadable: retry with `colors: 16` (adds shading for UI elements)
3. If still unclear: `scale: 0.75` or omit `colors` for full quality
4. **Remember** what works for each window/app during the session — don't retry every time.4. 索引您的项目
询问您的 AI:“使用 AiDex 索引此项目”
或者在 AI 聊天中手动输入:
aidex_init({ path: "/path/to/your/project" })可用工具
工具 | 描述 |
| 索引项目 (创建 |
| 按术语搜索 (精确/包含/以...开头) |
| 获取单个文件的类 + 方法 |
| 获取多个文件的签名 (glob) |
| 重新索引单个已更改的文件 |
| 从索引中删除已删除的文件 |
| 项目概览 |
| 带统计信息的文件树 |
| 向摘要添加文档 |
| 链接另一个已索引的项目 |
| 移除已链接的项目 |
| 列出已链接的项目 |
| 索引统计信息 |
| 在目录树中查找已索引的项目 |
| 按类型列出项目文件 (代码/配置/文档/资源) |
| 读取/写入会话笔记 (跨会话持久化) |
| 开始会话,检测外部更改,自动重新索引 |
| 在浏览器中打开交互式项目树 |
| 创建、读取、更新、删除带优先级和标签的任务 |
| 按状态、优先级或标签列出和过滤任务 |
| 截屏 (全屏、窗口、区域),支持可选缩放 + 颜色缩减 |
| 列出打开的窗口以进行截图定位 |
| 扫描目录树,在全局数据库中注册所有已索引的项目 |
| 列出所有已注册项目及其统计信息 |
| 在所有已注册项目中搜索术语 |
| 在所有项目中按名称搜索方法/类型 |
| 更新统计信息并从全局数据库中删除过期的项目 |
| 存储/检索 AI 指南和编码规范 (键值对,全局) |
| 通用日志接收器 — 启动 HTTP 服务器,查询日志,在 Viewer 中实时流式传输 |
基于时间的过滤
使用 modified_since 和 modified_before 跟踪最近的更改:
aidex_query({ term: "render", modified_since: "2h" }) # Last 2 hours
aidex_query({ term: "User", modified_since: "1d" }) # Last day
aidex_query({ term: "API", modified_since: "1w" }) # Last week支持的格式:
相对时间:
30m(分钟),2h(小时),1d(天),1w(周)ISO 日期:
2026-01-27或2026-01-27T14:30:00
非常适合回答诸如“我过去一
Latest Blog Posts
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/CSCSoftware/AiDex'
If you have feedback or need assistance with the MCP directory API, please join our Discord server