|
| 1 | +# Code Intelligence MCP Server |
| 2 | + |
| 3 | +Hybrid ctags + clangd code intelligence for C/C++ projects, exposed as an [MCP](https://modelcontextprotocol.io/) server. Gives AI coding assistants (Claude, Copilot, Gemini) instant symbol lookup and precision type information. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +Two tiers of intelligence, automatically selected: |
| 8 | + |
| 9 | +| Tier | Backend | Speed | Tools | |
| 10 | +|------|---------|-------|-------| |
| 11 | +| **Tier 1** | Universal Ctags | Instant (~0.1s) | `find_definition`, `find_references`, `list_symbols`, `search_symbol`, `rebuild_index` | |
| 12 | +| **Tier 2** | clangd LSP | Slower (~1-5s) | `hover_info`, `class_hierarchy`, `call_hierarchy` | |
| 13 | + |
| 14 | +Tier 1 builds a JSON symbol index from ctags output and keeps it cached. Tier 2 launches clangd as a subprocess and communicates via LSP protocol. Both tiers are optional — the server works with just ctags, just clangd, or both. |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +```bash |
| 19 | +# Install |
| 20 | +pip install -e . |
| 21 | + |
| 22 | +# Run (from your project root) |
| 23 | +code-intel |
| 24 | + |
| 25 | +# Or configure as an MCP server |
| 26 | +``` |
| 27 | + |
| 28 | +### MCP Configuration |
| 29 | + |
| 30 | +Add to your MCP client config (Claude Code, Antigravity, etc.): |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "mcpServers": { |
| 35 | + "codeintel": { |
| 36 | + "command": "python", |
| 37 | + "args": ["-m", "code_intel_server"], |
| 38 | + "cwd": "/path/to/your/project", |
| 39 | + "env": { |
| 40 | + "PROJECT_ROOT": "/path/to/your/project", |
| 41 | + "SOURCE_DIR": "src", |
| 42 | + "PYTHONUTF8": "1" |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Environment Variables |
| 50 | + |
| 51 | +| Variable | Default | Purpose | |
| 52 | +|----------|---------|---------| |
| 53 | +| `PROJECT_ROOT` | `.` (cwd) | Root of the C/C++ project | |
| 54 | +| `SOURCE_DIR` | `src` | Subdirectory containing source files (ctags scans here) | |
| 55 | +| `COMPILE_COMMANDS_DIR` | `./build` | Directory containing `compile_commands.json` (for clangd) | |
| 56 | +| `CLANGD_PATH` | `clangd` | Path to the clangd binary | |
| 57 | +| `CTAGS_PATH` | `ctags` | Path to the Universal Ctags binary | |
| 58 | + |
| 59 | +## Tools |
| 60 | + |
| 61 | +### Tier 1 (ctags — instant) |
| 62 | + |
| 63 | +- **`find_definition`** — Find where a symbol is defined. Supports qualified names (`MyNamespace::MyClass`), optional kind filter. |
| 64 | +- **`find_references`** — Find all references to a symbol across the codebase. Uses ctags scope/signature matching. |
| 65 | +- **`list_symbols`** — List all symbols in a specific file, optionally filtered by kind. |
| 66 | +- **`search_symbol`** — Fuzzy search for symbols by name pattern (substring or glob). |
| 67 | +- **`rebuild_index`** — Force a full ctags re-scan (normally auto-detects staleness). |
| 68 | + |
| 69 | +### Tier 2 (clangd — precision) |
| 70 | + |
| 71 | +- **`hover_info`** — Get full type information, documentation, and value for a symbol at a specific file:line location. |
| 72 | +- **`class_hierarchy`** — Show base classes and derived classes for a type. |
| 73 | +- **`call_hierarchy`** — Show what calls a function and what it calls. |
| 74 | + |
| 75 | +## Requirements |
| 76 | + |
| 77 | +- **Python 3.10+** |
| 78 | +- **[Universal Ctags](https://github.com/universal-ctags/ctags)** — for Tier 1 (install via package manager or from source) |
| 79 | +- **[clangd](https://clangd.llvm.org/)** — for Tier 2 (optional, usually bundled with LLVM/Clang) |
| 80 | +- **[FastMCP](https://github.com/jlowin/fastmcp)** — Python MCP framework |
| 81 | + |
| 82 | +## How It Works |
| 83 | + |
| 84 | +1. On first run, ctags scans `SOURCE_DIR/` recursively and builds a JSON symbol index |
| 85 | +2. The index is cached at `.cache/code_intel/tags.json` for instant restarts |
| 86 | +3. Staleness is auto-detected by comparing file mtimes against cache age |
| 87 | +4. clangd is launched on-demand when Tier 2 tools are called, using `compile_commands.json` for accurate type resolution |
| 88 | +5. All results are returned as structured JSON via MCP tool responses |
| 89 | + |
| 90 | +## Performance |
| 91 | + |
| 92 | +Tested on a 15,000-commit C++ project (~500K lines): |
| 93 | +- Index build: ~3 seconds (cached restart: instant) |
| 94 | +- Symbol lookup: <100ms |
| 95 | +- clangd hover: 1-5 seconds (depends on TU complexity) |
| 96 | + |
| 97 | +## License |
| 98 | + |
| 99 | +MIT |
0 commit comments