|
1 | 1 | # Code-Indexer (CIDX) Project Instructions |
2 | 2 |
|
| 3 | +## 0. CRITICAL BUSINESS INSIGHT - Query is Everything |
| 4 | + |
| 5 | +**THE SINGLE MOST IMPORTANT FEATURE**: Query capability is the core value proposition of CIDX. All query features available in CLI MUST be available in MCP/REST APIs with full parity. |
| 6 | + |
| 7 | +**Query Parity is Non-Negotiable**: Any feature gap between CLI and MCP/REST query interfaces represents a critical degradation of the product's primary function. This is not optional - this is the business. |
| 8 | + |
| 9 | +**Current Status** (as of 2025-11-18): |
| 10 | +- CLI query parameters: 23 total |
| 11 | +- MCP query parameters: 11 total (48% parity) |
| 12 | +- **P0 filters implemented**: language, exclude_language, path_filter, exclude_path, file_extensions, accuracy |
| 13 | +- **Remaining gap**: FTS-specific options (8 params), temporal options (4 params) |
| 14 | + |
| 15 | +**Never remove or break query functionality** without explicit approval. Query degradation = product failure. |
| 16 | + |
| 17 | +--- |
| 18 | + |
3 | 19 | ## 1. Operational Modes Overview |
4 | 20 |
|
5 | 21 | CIDX has **three operational modes**. Understanding which mode you're working in is critical. |
@@ -84,6 +100,31 @@ CIDX has **three operational modes**. Understanding which mode you're working in |
84 | 100 | - Real-time vs batch updates |
85 | 101 | - Performance optimizations |
86 | 102 |
|
| 103 | +### MCP Protocol (Server Mode) |
| 104 | + |
| 105 | +**Protocol Version**: `2024-11-05` (Model Context Protocol) |
| 106 | + |
| 107 | +**Initialize Handshake** (CRITICAL for Claude Code connection): |
| 108 | +- Method: `initialize` - MUST be first client-server interaction |
| 109 | +- Server Response: `{ "protocolVersion": "2024-11-05", "capabilities": { "tools": {} }, "serverInfo": { "name": "CIDX", "version": "7.3.0" } }` |
| 110 | +- Implemented in: `src/code_indexer/server/mcp/protocol.py` (process_jsonrpc_request) |
| 111 | +- Required for OAuth flow completion - Claude Code calls `initialize` after authentication |
| 112 | + |
| 113 | +**Key Points**: |
| 114 | +- Without `initialize` method, Claude Code fails with "Method not found: initialize" |
| 115 | +- Must return protocolVersion, capabilities (with tools), and serverInfo (name + version) |
| 116 | +- Tests in: `tests/unit/server/mcp/test_protocol.py::TestInitializeMethod` |
| 117 | + |
| 118 | +**Tool Response Format** (CRITICAL for Claude Code compatibility): |
| 119 | +- All tool results MUST return `content` as an **array of content blocks**, NOT a string |
| 120 | +- Each content block must have: `{ "type": "text", "text": "actual content here" }` |
| 121 | +- Empty content should be `[]`, NOT `""` or missing |
| 122 | +- Error responses must also include `content: []` (empty array is valid) |
| 123 | +- Example: `{ "success": true, "content": [{"type": "text", "text": "file contents"}], "metadata": {...} }` |
| 124 | +- Violating this format causes Claude Code to fail with "Expected array, received string" |
| 125 | +- Implemented in: `src/code_indexer/server/mcp/handlers.py` (all tool handlers) |
| 126 | +- Tests in: `tests/unit/server/mcp/test_handlers.py::TestFileHandlers::test_get_file_content` |
| 127 | + |
87 | 128 | --- |
88 | 129 |
|
89 | 130 | ## 3. Daily Development Workflows |
@@ -337,13 +378,15 @@ cidx query "def.*" --fts --regex # FTS/regex search |
337 | 378 | ``` |
338 | 379 |
|
339 | 380 | **Key Flags** (ALWAYS use `--quiet`): |
340 | | -- `--limit N` - Results (default 10) |
| 381 | +- `--limit N` - Results (default 10, start with 5-10 to conserve context window) |
341 | 382 | - `--language python` - Filter by language |
342 | 383 | - `--path-filter */tests/*` - Path pattern |
343 | 384 | - `--min-score 0.8` - Similarity threshold |
344 | 385 | - `--accuracy high` - Higher precision |
345 | 386 | - `--quiet` - Minimal output |
346 | 387 |
|
| 388 | +**Context Conservation**: Start with low `--limit` values (5-10) on initial queries. High limits consume context window rapidly when results contain large code files. |
| 389 | + |
347 | 390 | **Search Decision**: |
348 | 391 | - ✅ "What code does", "Where is X implemented" → CIDX |
349 | 392 | - ❌ Exact strings (variable names, config) → grep/find |
|
0 commit comments