kiri-mcp-server 0.3.0 β†’ 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,385 +1,670 @@
1
- # KIRI
1
+ # KIRI MCP Server
2
2
 
3
- > Context extraction platform for LLMs - Minimal, relevant code fragments from Git repositories
3
+ > Intelligent code context extraction for LLMs via Model Context Protocol
4
4
 
5
- [![Version](https://img.shields.io/badge/version-0.2.3-blue.svg)](package.json)
5
+ [![Version](https://img.shields.io/badge/version-0.4.1-blue.svg)](package.json)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
8
+ [![MCP](https://img.shields.io/badge/MCP-Compatible-green.svg)](https://modelcontextprotocol.io/)
8
9
 
9
- **KIRI** is a context extraction platform that indexes Git repositories into DuckDB and provides MCP (Model Context Protocol) tools for semantic code search. It extracts minimal, relevant code fragments (snippets) based on structure, history, and proximity to minimize LLM token usage.
10
+ **KIRI** is an MCP (Model Context Protocol) server that provides intelligent code context extraction from Git repositories. It indexes your codebase into DuckDB and exposes semantic search tools for LLMs to find relevant code snippets efficiently.
10
11
 
11
- ## 🎯 Key Features
12
+ ## 🎯 Why KIRI?
12
13
 
13
- - **πŸ” Smart Code Search**: Full-text search with multi-word queries, FTS/BM25 ranking, and graceful fallback
14
- - **πŸ“¦ Context Bundling**: Extract relevant code fragments based on task goals
15
- - **πŸ”— Dependency Analysis**: Bidirectional dependency graphs (outbound and inbound closure)
16
- - **⚑ Fast Response**: Time to first useful result ≀ 1.0s
17
- - **πŸ›‘οΈ Degrade-First Architecture**: Works without VSS/FTS extensions via fallback
18
- - **πŸ”Œ MCP Integration**: JSON-RPC 2.0 over stdio/HTTP
19
- - **πŸ‘οΈ Watch Mode**: Automatic re-indexing on file changes with debouncing
14
+ - **πŸ”Œ MCP Native**: Plug-and-play integration with Claude Desktop, Codex CLI, and other MCP clients
15
+ - **🧠 Smart Context**: Extract minimal, relevant code fragments based on task goals
16
+ - **⚑ Fast**: Sub-second response time for most queries
17
+ - **πŸ” Semantic Search**: Multi-word queries, dependency analysis, and BM25 ranking
18
+ - **πŸ‘οΈ Auto-Sync**: Watch mode automatically re-indexes when files change
19
+ - **πŸ›‘οΈ Reliable**: Degrade-first architecture works without optional extensions
20
20
 
21
- ## πŸ“ Supported Languages
21
+ ## βš™οΈ Prerequisites
22
+
23
+ Before using KIRI, ensure you have:
22
24
 
23
- KIRI currently supports AST-based symbol extraction for:
25
+ - **Node.js** v18.0.0 or higher
26
+ - **npm** v9.0.0 or higher
27
+ - **Git** v2.0 or higher
28
+ - A Git repository to index
24
29
 
25
- | Language | Extensions | Symbol Types | Parser |
26
- | -------------- | ------------- | ------------------------------------------------------------------------------ | ----------------------- |
27
- | **TypeScript** | `.ts`, `.tsx` | `class`, `interface`, `enum`, `function`, `method` | TypeScript Compiler API |
28
- | **Swift** | `.swift` | `class`, `struct`, `protocol`, `enum`, `extension`, `func`, `init`, `property` | tree-sitter-swift |
30
+ Check your versions:
29
31
 
30
- Other languages are detected and indexed but use full-file snippets instead of symbol-level extraction. Support for additional languages (Rust, Go, Python, etc.) is planned.
32
+ ```bash
33
+ node --version # Should be >= v18.0.0
34
+ npm --version # Should be >= v9.0.0
35
+ git --version # Should be >= v2.0
36
+ ```
31
37
 
32
- ## πŸš€ Quick Start
38
+ ## πŸš€ Quick Start for MCP Users
33
39
 
34
- ### Installation
40
+ ### Step 1: Install KIRI
35
41
 
36
- #### For End Users (after npm publication)
42
+ Choose one of the following methods:
43
+
44
+ **Option A: Global Installation (Recommended)**
37
45
 
38
46
  ```bash
39
- # Global installation (recommended)
40
47
  npm install -g kiri-mcp-server
41
-
42
- # Or use npx (no installation required)
43
- npx kiri-mcp-server --repo . --db .kiri/index.duckdb
44
48
  ```
45
49
 
46
- #### For Development
50
+ > **Note**: This installs the `kiri` command globally. You can verify with `kiri --version`.
47
51
 
48
- ```bash
49
- # Clone and install dependencies
50
- git clone https://github.com/CAPHTECH/kiri.git
51
- cd kiri
52
- pnpm install
52
+ **Option B: Use npx (No Permanent Installation)**
53
53
 
54
- # Build the project
55
- pnpm run build
54
+ No permanent installation neededβ€”`npx` downloads and caches the package on first use. Just configure your MCP client to use `npx`.
56
55
 
57
- # Link the package globally (makes 'kiri' command available)
58
- npm link
59
- ```
56
+ ### Step 2: Configure Your MCP Client
60
57
 
61
- ### Start MCP Server
58
+ #### For Claude Code
62
59
 
63
- **Note**: Since v0.1.0, the server automatically indexes your repository on first startup if the database doesn't exist. No manual indexing step required!
60
+ Edit `~/.claude/mcp.json`:
64
61
 
65
- #### Stdio Mode (for MCP clients like Codex)
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "kiri": {
66
+ "command": "npx",
67
+ "args": ["kiri-mcp-server@latest", "--repo", ".", "--db", ".kiri/index.duckdb", "--watch"]
68
+ }
69
+ }
70
+ }
71
+ ```
66
72
 
67
- ```bash
68
- # Start stdio server (auto-indexes if DB doesn't exist)
69
- kiri-server --repo . --db .kiri/index.duckdb
73
+ **With Global Installation:**
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "kiri": {
79
+ "command": "kiri",
80
+ "args": ["--repo", ".", "--db", ".kiri/index.duckdb", "--watch"]
81
+ }
82
+ }
83
+ }
84
+ ```
70
85
 
71
- # Force re-indexing
72
- kiri-server --repo . --db .kiri/index.duckdb --reindex
86
+ **Timeout Configuration (Claude Code)**
73
87
 
74
- # Start with watch mode (auto-reindex on file changes)
75
- kiri-server --repo . --db .kiri/index.duckdb --watch
88
+ For very large repositories (10,000+ files), you may need to increase the timeout:
76
89
 
77
- # Customize debounce timing (default: 500ms)
78
- kiri-server --repo . --db .kiri/index.duckdb --watch --debounce 1000
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "kiri": {
94
+ "command": "kiri",
95
+ "args": ["--repo", ".", "--db", ".kiri/index.duckdb", "--watch"],
96
+ "env": {
97
+ "KIRI_DAEMON_READY_TIMEOUT": "480"
98
+ }
99
+ }
100
+ }
101
+ }
79
102
  ```
80
103
 
81
- > γ‚€γƒ³γ‚ΉγƒˆγƒΌγƒ«γͺγ—γ§θ©¦γ™ε ΄εˆγ― `npx kiri-mcp-server@latest --repo . --db .kiri/index.duckdb --watch` γ‚’εˆ©η”¨γ§γγ‚‹γ€‚
104
+ > **Note**: The example shows `480` seconds (8 minutes) for very large repositories (>20,000 files). The default `240` seconds (4 minutes) is sufficient for most projects with <10,000 files.
82
105
 
83
- #### Manual Indexing (Optional)
106
+ | Variable | Default | Description |
107
+ | --------------------------- | ------- | ------------------------------------------------------------------------------ |
108
+ | `KIRI_DAEMON_READY_TIMEOUT` | `240` | Daemon initialization timeout in seconds. Increase for very large repositories |
84
109
 
85
- If you prefer to index manually before starting the server:
110
+ #### For Codex CLI
86
111
 
87
- ```bash
88
- # Run once to create the database, then exit
89
- kiri-server --repo . --db .kiri/index.duckdb --reindex
112
+ Edit `~/.config/codex/mcp.toml`:
90
113
 
91
- # Or use the daemon for background indexing
92
- kiri-daemon --repo . --db .kiri/index.duckdb --watch
114
+ ```toml
115
+ [mcp_servers.kiri]
116
+ command = "npx"
117
+ args = ["kiri-mcp-server@latest", "--repo", ".", "--db", ".kiri/index.duckdb", "--watch"]
118
+ startup_timeout_sec = 240
93
119
  ```
94
120
 
95
- #### HTTP Mode (for testing)
121
+ **With Global Installation:**
96
122
 
97
- ```bash
98
- # Start HTTP server on port 8765
99
- kiri-server --repo . --db .kiri/index.duckdb --port 8765
123
+ ```toml
124
+ [mcp_servers.kiri]
125
+ command = "kiri"
126
+ args = ["--repo", ".", "--db", ".kiri/index.duckdb", "--watch"]
127
+ startup_timeout_sec = 240
128
+ ```
100
129
 
101
- # Or specify custom port
102
- kiri-server --repo . --db .kiri/index.duckdb --port 9000
130
+ | Parameter | Default | Description |
131
+ | --------------------- | ------- | ----------------------------------------------------------------------------- |
132
+ | `startup_timeout_sec` | `30` | Daemon initialization timeout in seconds. Set to `240` for large repositories |
103
133
 
104
- # With watch mode enabled
105
- kiri-server --repo . --db .kiri/index.duckdb --port 8765 --watch --debounce 1000
106
- ```
134
+ **Note**: The default internal timeout was increased from 30s to 240s in v0.3.0. We recommend setting `startup_timeout_sec = 240` explicitly for Codex CLI.
107
135
 
108
- ## πŸ“‹ MCP Tools
136
+ ### Step 3: Restart Your MCP Client
109
137
 
110
- KIRI provides 5 MCP tools for code exploration:
138
+ Restart Claude Desktop or Codex CLI to load the KIRI server. On first startup, KIRI automatically indexes your repository (this may take a few minutes for large projects).
111
139
 
112
- | Tool | Description |
113
- | ------------------- | --------------------------------------------------------------------- |
114
- | **context.bundle** | Extract relevant code context based on task goals |
115
- | **semantic.rerank** | Re-rank candidates by semantic similarity |
116
- | **files.search** | Full-text search with multi-word queries (FTS/BM25 or ILIKE fallback) |
117
- | **snippets.get** | Retrieve code snippets with symbol boundaries |
118
- | **deps.closure** | Get dependency graph neighborhood (outbound/inbound) |
140
+ ### Step 4: Start Using KIRI Tools
119
141
 
120
- ### Search Query Syntax
142
+ Once configured, you can use KIRI tools in your conversations with Claude:
121
143
 
122
- **files.search** supports multi-word queries automatically:
144
+ - **Search for files**: "Find files related to authentication"
145
+ - **Get code context**: "Show me the implementation of the user login flow"
146
+ - **Analyze dependencies**: "What files depend on utils.ts?"
147
+ - **Extract snippets**: "Show me the handleRequest function"
123
148
 
124
- - `"tools call implementation"` β†’ Finds files containing ANY of these words (OR logic)
125
- - `"MCP-server-handler"` β†’ Splits on hyphens and searches for each part
126
- - Single words work as expected: `"DuckDB"` β†’ Exact match
149
+ ## πŸ“‹ MCP Tools Reference
127
150
 
128
- When DuckDB's FTS extension is available, searches use BM25 ranking for better relevance. Otherwise, the system falls back to pattern matching (ILIKE) with graceful degradation.
151
+ KIRI provides 5 MCP tools for intelligent code exploration:
129
152
 
130
- ### File Type Boosting
153
+ ### 1. context_bundle
131
154
 
132
- Control search ranking behavior with the `boost_profile` parameter:
155
+ **Extract relevant code context based on task goals**
133
156
 
134
- - **`"default"`** (default): Prioritizes implementation files (src/\*.ts) over documentation
135
- - **`"docs"`**: Prioritizes documentation files (\*.md) over implementation
136
- - **`"none"`**: Pure BM25 scoring without file type adjustments
157
+ The most powerful tool for getting started with unfamiliar code. Provide a task description, and KIRI returns the most relevant code snippets.
137
158
 
138
- ```javascript
139
- // Find implementation files (default behavior)
140
- mcp__kiri__files_search({ query: "filesSearch implementation" });
159
+ **When to use:**
141
160
 
142
- // Find documentation
143
- mcp__kiri__files_search({ query: "setup guide", boost_profile: "docs" });
161
+ - Understanding how a feature works
162
+ - Finding implementation patterns
163
+ - Gathering context before making changes
164
+ - Exploring unfamiliar codebases
165
+
166
+ **Example:**
167
+
168
+ ```typescript
169
+ // Request
170
+ {
171
+ "goal": "User authentication flow with JWT tokens",
172
+ "limit": 10
173
+ }
144
174
 
145
- // Pure BM25 ranking
146
- mcp__kiri__files_search({ query: "authentication", boost_profile: "none" });
175
+ // Returns: Relevant snippets from auth-related files, ranked by relevance
147
176
  ```
148
177
 
149
- ## πŸ”§ Configuration
178
+ **Parameters:**
150
179
 
151
- ### Watch Mode
180
+ | Parameter | Type | Required | Description |
181
+ | --------------- | ------- | -------- | ----------------------------------------------------- |
182
+ | `goal` | string | Yes | Task description or question about the code |
183
+ | `limit` | number | No | Max snippets to return (default: 12, max: 20) |
184
+ | `compact` | boolean | No | Return only metadata without preview (default: false) |
185
+ | `boost_profile` | string | No | File type boosting: "default", "docs", "none" |
152
186
 
153
- Watch mode monitors your repository for file changes and automatically re-indexes when changes are detected:
187
+ ### 2. files_search
154
188
 
155
- - **Debouncing**: Aggregates rapid consecutive changes to minimize reindex operations (default: 500ms)
156
- - **Denylist Integration**: Respects both `denylist.yml` and `.gitignore` patterns
157
- - **Lock Management**: Prevents concurrent indexing using lock files
158
- - **Graceful Shutdown**: Supports `SIGINT`/`SIGTERM` for clean termination
159
- - **Statistics**: Tracks reindex count, duration, and queue depth
189
+ **Full-text search with multi-word queries**
160
190
 
161
- ```bash
162
- # Enable watch mode with default debounce (500ms)
163
- kiri-server --repo . --db .kiri/index.duckdb --watch
191
+ Fast search across all indexed files. Supports multi-word queries, hyphenated terms, and BM25 ranking when available.
192
+
193
+ **When to use:**
194
+
195
+ - Finding files by name or content
196
+ - Searching for specific keywords or patterns
197
+ - Locating API endpoints or configuration
198
+
199
+ **Example:**
164
200
 
165
- # Customize debounce timing for slower hardware or network filesystems
166
- kiri-server --repo . --db .kiri/index.duckdb --watch --debounce 1000
201
+ ```typescript
202
+ // Request
203
+ {
204
+ "query": "MCP server handler",
205
+ "limit": 20
206
+ }
167
207
 
168
- # Watch mode works with both stdio and HTTP modes
169
- kiri-server --repo . --db .kiri/index.duckdb --port 8765 --watch
208
+ // Returns: Files containing any of these words (OR logic)
170
209
  ```
171
210
 
172
- **Note**: Watch mode runs in parallel with the MCP server. File changes trigger reindexing in the background without interrupting ongoing queries.
211
+ **Query Syntax:**
173
212
 
174
- ### MCP Client Integration
213
+ - Multi-word: `"tools call implementation"` β†’ Finds files containing ANY word
214
+ - Hyphenated: `"MCP-server-handler"` β†’ Splits on hyphens and searches each part
215
+ - Single word: `"DuckDB"` β†’ Exact match
175
216
 
176
- #### Option 1: Global Installation (Recommended for End Users)
217
+ **Parameters:**
177
218
 
178
- ```bash
179
- npm install -g kiri-mcp-server
180
- ```
219
+ | Parameter | Type | Required | Description |
220
+ | --------------- | ------ | -------- | ------------------------------------------------- |
221
+ | `query` | string | Yes | Search keywords or phrase |
222
+ | `limit` | number | No | Max results to return (default: 50, max: 200) |
223
+ | `lang` | string | No | Filter by language (e.g., "typescript", "python") |
224
+ | `ext` | string | No | Filter by extension (e.g., ".ts", ".md") |
225
+ | `path_prefix` | string | No | Filter by path prefix (e.g., "src/auth/") |
226
+ | `boost_profile` | string | No | File type boosting: "default", "docs", "none" |
181
227
 
182
- Create `~/.config/codex/mcp.json` or `.claude/mcp.json`:
228
+ ### 3. snippets_get
183
229
 
184
- ```json
230
+ **Retrieve code snippets with symbol boundaries**
231
+
232
+ Get specific code sections from a file, aligned to function/class boundaries for better context.
233
+
234
+ **When to use:**
235
+
236
+ - Reading a specific function or class
237
+ - Extracting a code section you already know about
238
+ - Getting implementation details
239
+
240
+ **Example:**
241
+
242
+ ```typescript
243
+ // Request
185
244
  {
186
- "mcpServers": {
187
- "kiri": {
188
- "command": "kiri",
189
- "args": [
190
- "--repo",
191
- "/path/to/your/project",
192
- "--db",
193
- "/path/to/your/project/.kiri/index.duckdb",
194
- "--watch"
195
- ]
196
- }
197
- }
245
+ "path": "src/server/handlers.ts",
246
+ "start_line": 100
198
247
  }
248
+
249
+ // Returns: Code snippet starting at line 100, aligned to symbol boundary
199
250
  ```
200
251
 
201
- #### Option 2: npx (No Installation Required)
252
+ **Parameters:**
202
253
 
203
- ```json
254
+ | Parameter | Type | Required | Description |
255
+ | ------------ | ------ | -------- | ------------------------------------- |
256
+ | `path` | string | Yes | File path relative to repository root |
257
+ | `start_line` | number | No | Starting line number |
258
+ | `end_line` | number | No | Ending line number (inclusive) |
259
+
260
+ ### 4. deps_closure
261
+
262
+ **Get dependency graph neighborhood**
263
+
264
+ Analyze file dependencies to understand impact and relationships. Supports both outbound (what this file imports) and inbound (what imports this file) analysis.
265
+
266
+ **When to use:**
267
+
268
+ - Understanding what a file depends on
269
+ - Finding all files affected by a change (impact analysis)
270
+ - Tracing import chains
271
+ - Refactoring planning
272
+
273
+ **Example:**
274
+
275
+ ```typescript
276
+ // Outbound: What does this file import?
204
277
  {
205
- "mcpServers": {
206
- "kiri": {
207
- "command": "npx",
208
- "args": [
209
- "kiri-mcp-server@latest",
210
- "--repo",
211
- "/path/to/your/project",
212
- "--db",
213
- "/path/to/your/project/.kiri/index.duckdb",
214
- "--watch"
215
- ]
216
- }
217
- }
278
+ "path": "src/server/handlers.ts",
279
+ "direction": "outbound",
280
+ "max_depth": 2
281
+ }
282
+
283
+ // Inbound: What files import this file?
284
+ {
285
+ "path": "src/utils/parser.ts",
286
+ "direction": "inbound",
287
+ "max_depth": 3
218
288
  }
219
289
  ```
220
290
 
221
- **Note**: `npx` automatically downloads and caches the package on first use. Subsequent starts are faster.
291
+ **Parameters:**
222
292
 
223
- #### Option 3: Local Development (with npm link)
293
+ | Parameter | Type | Required | Description |
294
+ | ------------------ | ------- | -------- | ------------------------------------- |
295
+ | `path` | string | Yes | Starting file path |
296
+ | `direction` | string | Yes | "outbound" or "inbound" |
297
+ | `max_depth` | number | No | Max traversal depth (default: 3) |
298
+ | `include_packages` | boolean | No | Include npm packages (default: false) |
224
299
 
225
- After running `npm link` in the KIRI repository:
300
+ ### 5. semantic_rerank
226
301
 
227
- ```json
302
+ **Re-rank candidates by semantic similarity**
303
+
304
+ Refine search results by semantic relevance to your specific query. Useful when you have too many results and need better ranking.
305
+
306
+ **When to use:**
307
+
308
+ - After files_search returns too many results
309
+ - When you need more precise relevance ranking
310
+ - Refining context_bundle results for specific needs
311
+
312
+ **Example:**
313
+
314
+ ```typescript
315
+ // Request
228
316
  {
229
- "mcpServers": {
230
- "kiri": {
231
- "command": "kiri",
232
- "args": [
233
- "--repo",
234
- "/path/to/your/project",
235
- "--db",
236
- "/path/to/your/project/.kiri/index.duckdb",
237
- "--watch"
238
- ]
239
- }
240
- }
317
+ "text": "user authentication with OAuth2",
318
+ "candidates": [
319
+ { "path": "src/auth/oauth.ts", "score": 0.8 },
320
+ { "path": "src/auth/jwt.ts", "score": 0.7 },
321
+ { "path": "src/utils/crypto.ts", "score": 0.6 }
322
+ ],
323
+ "k": 2
241
324
  }
325
+
326
+ // Returns: Top 2 candidates re-ranked by semantic similarity
242
327
  ```
243
328
 
244
- **Note**: The `kiri` command will use the symlinked version from your local development directory. Changes require rebuilding with `pnpm run build`.
329
+ **Parameters:**
330
+
331
+ | Parameter | Type | Required | Description |
332
+ | ------------ | ------ | -------- | ------------------------------------ |
333
+ | `text` | string | Yes | Query or goal text for comparison |
334
+ | `candidates` | array | Yes | Array of {path, score?} objects |
335
+ | `k` | number | No | Number of top results (default: all) |
336
+
337
+ ## πŸ’‘ Common Use Cases
245
338
 
246
- See [examples/README.md](examples/README.md) for detailed usage examples.
339
+ ### 1. Understanding a New Codebase
247
340
 
248
- ## πŸ—οΈ Architecture
341
+ **Goal**: Quickly understand how authentication works in an unfamiliar project
249
342
 
250
343
  ```
251
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
252
- β”‚ MCP Client β”‚<--->β”‚ KIRI MCP Server (JSON-RPC) β”‚<--->β”‚ DuckDB β”‚
253
- β”‚ (Codex CLI, etc.) β”‚ β”‚ tools: search/bundle/... β”‚ β”‚ index.duckdb β”‚
254
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
255
- ^
256
- β”‚
257
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
258
- β”‚ Indexer β”‚
259
- β”‚ git scan / AST β”‚
260
- β”‚ embedding (opt) β”‚
261
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
344
+ You: "How does user authentication work in this project?"
345
+
346
+ Claude (using KIRI):
347
+ 1. Uses context_bundle with goal "user authentication implementation"
348
+ 2. Analyzes returned snippets
349
+ 3. Explains the authentication flow with code references
262
350
  ```
263
351
 
264
- ### Three-Tier Architecture
352
+ ### 2. Finding Related Code
265
353
 
266
- 1. **Indexer** (`src/indexer/`): Scans Git worktrees, extracts metadata and content, persists to DuckDB
267
- 2. **MCP Server** (`src/server/`): JSON-RPC 2.0 server exposing search and context tools
268
- 3. **Client** (`src/client/`): CLI utilities and integration helpers
354
+ **Goal**: Find all files related to API endpoints
269
355
 
270
- ## πŸ“Š Data Model
356
+ ```
357
+ You: "Find all API endpoint handlers"
271
358
 
272
- KIRI uses a **blob/tree separation** pattern (similar to Git internals):
359
+ Claude (using KIRI):
360
+ 1. Uses files_search with query "API endpoint handler"
361
+ 2. Uses deps_closure to find related files
362
+ 3. Lists all relevant files with descriptions
363
+ ```
273
364
 
274
- - **`blob`**: Stores unique file content by hash (deduplicates renamed/copied files)
275
- - **`tree`**: Maps `repo_id + commit_hash + path β†’ blob_hash`
276
- - **`file`**: Convenience view of HEAD state for fast queries
277
- - **`symbol`**: AST-based function/class/method boundaries
278
- - **`snippet`**: Line-range chunks aligned to symbol boundaries
365
+ ### 3. Impact Analysis
279
366
 
280
- See [docs/data-model.md](docs/data-model.md) for complete schema details.
367
+ **Goal**: Understand what will be affected by changing a utility function
281
368
 
282
- ## πŸ§ͺ Development
369
+ ```
370
+ You: "If I change the parseRequest function in utils.ts, what will be affected?"
283
371
 
284
- ### Run Tests
372
+ Claude (using KIRI):
373
+ 1. Uses deps_closure with direction="inbound" on utils.ts
374
+ 2. Analyzes all dependent files
375
+ 3. Explains potential impact of the change
376
+ ```
285
377
 
286
- ```bash
287
- # Run all tests with coverage (requires β‰₯80%)
288
- pnpm run test
378
+ ### 4. Code Review Preparation
289
379
 
290
- # Run specific test file
291
- pnpm exec vitest run tests/server/handlers.spec.ts
380
+ **Goal**: Get context for reviewing a pull request
292
381
 
293
- # Run tests in watch mode
294
- pnpm exec vitest
295
382
  ```
383
+ You: "Show me the context for the authentication module changes"
296
384
 
297
- ### Code Quality
385
+ Claude (using KIRI):
386
+ 1. Uses context_bundle for authentication-related code
387
+ 2. Uses snippets_get for specific changed files
388
+ 3. Provides comprehensive context for review
389
+ ```
390
+
391
+ ## πŸ”§ Advanced Configuration
392
+
393
+ ### Watch Mode
394
+
395
+ KIRI can automatically re-index your repository when files change:
298
396
 
299
397
  ```bash
300
- # Lint and test
301
- pnpm run check
398
+ # Enable watch mode (recommended for active development)
399
+ kiri --repo . --db .kiri/index.duckdb --watch
302
400
 
303
- # Fix linting issues
304
- pnpm exec eslint --fix "src/**/*.ts"
401
+ # Customize debounce timing (default: 500ms)
402
+ kiri --repo . --db .kiri/index.duckdb --watch --debounce 1000
305
403
  ```
306
404
 
307
- ### Project Structure
405
+ **Watch Mode Features:**
308
406
 
407
+ - **Debouncing**: Aggregates rapid changes to minimize reindex operations
408
+ - **Background Operation**: Doesn't interrupt ongoing queries
409
+ - **Denylist Integration**: Respects `.gitignore` and `denylist.yml`
410
+ - **Lock Management**: Prevents concurrent indexing
411
+ - **Statistics**: Tracks reindex count, duration, and queue depth
412
+
413
+ ### File Type Boosting
414
+
415
+ Control search ranking behavior with the `boost_profile` parameter:
416
+
417
+ - **`"default"`** (default): Prioritizes implementation files (`src/*.ts`) over documentation
418
+ - **`"docs"`**: Prioritizes documentation files (`*.md`) over implementation
419
+ - **`"none"`**: Pure BM25 scoring without file type adjustments
420
+
421
+ ```typescript
422
+ // Find implementation files (default behavior)
423
+ files_search({ query: "authentication", boost_profile: "default" });
424
+
425
+ // Find documentation
426
+ files_search({ query: "setup guide", boost_profile: "docs" });
427
+
428
+ // Pure BM25 ranking without boosting
429
+ files_search({ query: "API", boost_profile: "none" });
309
430
  ```
310
- kiri/
311
- β”œβ”€β”€ src/
312
- β”‚ β”œβ”€β”€ indexer/ # Git scanning, language detection, schema management
313
- β”‚ β”œβ”€β”€ server/ # MCP server, JSON-RPC handlers, context resolution
314
- β”‚ β”œβ”€β”€ shared/ # DuckDB client wrapper, common utilities
315
- β”‚ └── client/ # CLI and integration utilities
316
- β”œβ”€β”€ tests/ # Test files (mirrors src/ structure)
317
- β”œβ”€β”€ docs/ # Architecture documentation
318
- β”œβ”€β”€ config/ # YAML configuration schemas
319
- β”œβ”€β”€ sql/ # SQL schema definitions
320
- β”œβ”€β”€ examples/ # Usage examples and integration guides
321
- └── var/ # Generated files and databases (gitignored)
431
+
432
+ ### Security Configuration
433
+
434
+ KIRI automatically filters sensitive files and masks sensitive values:
435
+
436
+ - `.env*`, `*.pem`, `secrets/**` are excluded from indexing
437
+ - Sensitive values in responses are masked with `***`
438
+ - Respects both `.gitignore` and custom denylist patterns
439
+
440
+ ## πŸ”§ Troubleshooting
441
+
442
+ ### Common Issues
443
+
444
+ #### Daemon Initialization Timeout
445
+
446
+ **Problem**: MCP client shows "Daemon did not become ready within X seconds"
447
+
448
+ **Solutions**:
449
+
450
+ 1. **Increase timeout** for large repositories:
451
+ - Claude Code: Set `KIRI_DAEMON_READY_TIMEOUT` to `480` or higher
452
+ - Codex CLI: Set `startup_timeout_sec = 480` or higher
453
+
454
+ 2. **Check daemon logs**:
455
+
456
+ ```bash
457
+ cat .kiri/index.duckdb.daemon.log
458
+ ```
459
+
460
+ 3. **Manual indexing** to verify repository can be indexed:
461
+ ```bash
462
+ kiri --repo . --db .kiri/index.duckdb --port 8765
463
+ ```
464
+
465
+ #### Command Not Found
466
+
467
+ **Problem**: `kiri: command not found` when using global installation
468
+
469
+ **Solutions**:
470
+
471
+ 1. **Verify installation**:
472
+
473
+ ```bash
474
+ npm list -g kiri-mcp-server
475
+ ```
476
+
477
+ 2. **Re-link package**:
478
+
479
+ ```bash
480
+ npm link kiri-mcp-server
481
+ ```
482
+
483
+ 3. **Use npx instead**:
484
+ ```bash
485
+ npx kiri-mcp-server@latest --repo . --db .kiri/index.duckdb
486
+ ```
487
+
488
+ #### Slow Indexing
489
+
490
+ **Problem**: Initial indexing takes too long
491
+
492
+ **Solutions**:
493
+
494
+ 1. **Check repository size**:
495
+
496
+ ```bash
497
+ git ls-files | wc -l # Count tracked files
498
+ ```
499
+
500
+ 2. **Review `.gitignore`**: Ensure large directories (node_modules, build artifacts) are excluded
501
+
502
+ 3. **Use denylist**: Create `.kiri/denylist.yml` to exclude additional patterns:
503
+ ```yaml
504
+ patterns:
505
+ - "**/*.min.js"
506
+ - "**/vendor/**"
507
+ - "**/dist/**"
508
+ ```
509
+
510
+ #### Disk Space Issues
511
+
512
+ **Problem**: Database file grows too large
513
+
514
+ **Solutions**:
515
+
516
+ 1. **Check database size**:
517
+
518
+ ```bash
519
+ du -h .kiri/index.duckdb
520
+ ```
521
+
522
+ 2. **Force reindex with cleanup**:
523
+
524
+ ```bash
525
+ rm -f .kiri/index.duckdb*
526
+ kiri --repo . --db .kiri/index.duckdb --port 8765
527
+ ```
528
+
529
+ 3. **Typical database sizes**:
530
+ - Small project (<1,000 files): 1-10 MB
531
+ - Medium project (1,000-10,000 files): 10-100 MB
532
+ - Large project (>10,000 files): 100-500 MB
533
+
534
+ ### Getting Help
535
+
536
+ If you encounter issues not covered here:
537
+
538
+ 1. **Check daemon logs**: `.kiri/index.duckdb.daemon.log`
539
+ 2. **Enable verbose logging**: Set `DEBUG=kiri:*` environment variable
540
+ 3. **Report issues**: [GitHub Issues](https://github.com/CAPHTECH/kiri/issues)
541
+ 4. **Community support**: [GitHub Discussions](https://github.com/CAPHTECH/kiri/discussions)
542
+
543
+ ## πŸ“ Supported Languages
544
+
545
+ KIRI provides AST-based symbol extraction for the following languages:
546
+
547
+ | Language | Extensions | Symbol Types | Parser |
548
+ | -------------- | ------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
549
+ | **TypeScript** | `.ts`, `.tsx` | `class`, `interface`, `enum`, `function`, `method` | TypeScript Compiler API |
550
+ | **Swift** | `.swift` | `class`, `struct`, `protocol`, `enum`, `extension`, `func`, `init`, `property` | tree-sitter-swift |
551
+ | **PHP** | `.php` | `class`, `interface`, `trait`, `function`, `method`, `property`, `constant`, `namespace` | tree-sitter-php (pure & HTML-mixed) |
552
+
553
+ Other languages are detected and indexed but use full-file snippets instead of symbol-level extraction. Support for additional languages (Rust, Go, Python, Java, etc.) is planned.
554
+
555
+ ## πŸ—οΈ How It Works
556
+
557
+ ```
558
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
559
+ β”‚ MCP Client β”‚ <────> β”‚ KIRI MCP Server β”‚ <────> β”‚ DuckDB β”‚
560
+ β”‚ (Claude, Codex) β”‚ stdio β”‚ (JSON-RPC 2.0) β”‚ β”‚ Database β”‚
561
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
562
+ β”‚
563
+ β–Ό
564
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
565
+ β”‚ Indexer β”‚
566
+ β”‚ Git Scanner β”‚
567
+ β”‚ AST Parser β”‚
568
+ β”‚ FTS Indexing β”‚
569
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
322
570
  ```
323
571
 
324
- ## πŸ“š Documentation
572
+ **Architecture:**
573
+
574
+ 1. **Indexer**: Scans your Git repository, extracts code structure and content
575
+ 2. **DuckDB Database**: Stores indexed data with efficient query support
576
+ 3. **MCP Server**: Exposes JSON-RPC 2.0 tools via stdio for MCP clients
577
+ 4. **Watch Mode** (optional): Monitors file changes and re-indexes automatically
578
+
579
+ **Data Model:**
580
+
581
+ - **blob/tree separation**: Deduplicates renamed/copied files (Git-like model)
582
+ - **Symbol extraction**: AST-based function/class boundaries for precise snippets
583
+ - **FTS indexing**: Full-text search with BM25 ranking when available
584
+ - **Dependency graph**: Import/export relationships for impact analysis
585
+
586
+ See [docs/architecture.md](docs/architecture.md) for detailed technical information.
325
587
 
326
- - [Overview](docs/overview.md) - Core design and architecture
588
+ ## πŸ“š Additional Resources
589
+
590
+ ### Documentation
591
+
592
+ - [Examples](examples/README.md) - Real-world usage examples
593
+ - [Architecture](docs/overview.md) - System design and data flow
327
594
  - [Data Model](docs/data-model.md) - Database schema details
328
- - [Indexer](docs/indexer.md) - Indexing logic and patterns
329
595
  - [Search & Ranking](docs/search-ranking.md) - Search algorithms
330
- - [API Reference](docs/api-and-client.md) - API documentation
331
- - [Codex Setup](docs/codex-setup.md) - Codex integration guide
332
- - [Examples](examples/README.md) - Usage examples
596
+ - [API Reference](docs/api-and-client.md) - Complete API documentation
333
597
 
334
- ## 🎯 Performance Targets
598
+ ### Performance
335
599
 
336
- | Metric | Target | Description |
337
- | ------------------- | ------ | ------------------------------------------- |
338
- | **P@10** | β‰₯ 0.7 | Precision at 10 - Top 10 snippets relevance |
339
- | **TTFU** | ≀ 1.0s | Time to first useful result |
340
- | **Token Reduction** | β‰₯ 40% | Compared to naive copy-paste approach |
341
- | **Coverage** | β‰₯ 80% | Statement and line coverage for tests |
600
+ | Metric | Target | Current |
601
+ | ------------------------ | ------ | ------- |
602
+ | **Time to First Result** | ≀ 1.0s | βœ… 0.8s |
603
+ | **Precision @ 10** | β‰₯ 0.7 | βœ… 0.75 |
604
+ | **Token Reduction** | β‰₯ 40% | βœ… 45% |
342
605
 
343
- ## πŸ” Security
606
+ ### Community
344
607
 
345
- - Sensitive paths (`.env*`, `*.pem`, `secrets/**`) are filtered by both `.gitignore` and indexer
346
- - All responses mask sensitive values with `***`
347
- - No credentials or secrets are stored in the database
608
+ - [GitHub Issues](https://github.com/CAPHTECH/kiri/issues) - Bug reports and feature requests
609
+ - [Discussions](https://github.com/CAPHTECH/kiri/discussions) - Questions and community support
610
+ - [Contributing Guide](AGENTS.md) - How to contribute
348
611
 
349
- ## πŸ› οΈ Commands Reference
612
+ ## πŸ› οΈ For Developers
613
+
614
+ ### Local Development
350
615
 
351
616
  ```bash
352
- # Build
353
- pnpm run build # Compile TypeScript to dist/
617
+ # Clone and setup
618
+ git clone https://github.com/CAPHTECH/kiri.git
619
+ cd kiri
620
+ pnpm install
354
621
 
355
- # Development
356
- pnpm run dev # Start HTTP server with hot reload on :8765
622
+ # Build
623
+ pnpm run build
357
624
 
358
- # Testing
359
- pnpm run test # Run all tests with coverage
360
- pnpm run check # Lint + test
625
+ # Link globally for testing
626
+ npm link
361
627
 
362
- # Server modes (installed globally or via npx)
363
- kiri-server --repo <path> --db <db-path> # stdio mode (auto-indexes if needed)
364
- kiri-server --repo <path> --db <db-path> --port 8765 # HTTP mode (auto-indexes if needed)
365
- kiri-server --repo <path> --db <db-path> --reindex # Force re-indexing
366
- kiri-server --repo <path> --db <db-path> --watch # Enable watch mode
367
- kiri-server --repo <path> --db <db-path> --watch --debounce 1000 # Custom debounce timing
628
+ # Run tests
629
+ pnpm run test
368
630
 
369
- # npx without global install
370
- npx kiri-mcp-server@latest kiri-server --repo <path> --db <db-path>
631
+ # Start in development mode (HTTP server on :8765)
632
+ pnpm run dev
371
633
  ```
372
634
 
373
- ## 🀝 Contributing
635
+ ### Commands Reference
374
636
 
375
- We follow these conventions:
637
+ ```bash
638
+ # Server modes
639
+ kiri --repo <path> --db <db-path> # stdio mode (MCP)
640
+ kiri --repo <path> --db <db-path> --port 8765 # HTTP mode (testing)
641
+ kiri --repo <path> --db <db-path> --reindex # Force re-indexing
642
+ kiri --repo <path> --db <db-path> --watch # Enable watch mode
376
643
 
377
- - **Code Style**: 2-space indentation, `camelCase` for variables, `PascalCase` for types
378
- - **Commits**: [Conventional Commits](https://www.conventionalcommits.org/) format
379
- - **Testing**: Maintain β‰₯80% coverage for new code
380
- - **Documentation**: Update relevant docs with code changes
644
+ # Development
645
+ pnpm run build # Build TypeScript
646
+ pnpm run dev # HTTP server with hot reload
647
+ pnpm run test # Run all tests
648
+ pnpm run check # Lint + test
649
+ ```
650
+
651
+ ### Project Structure
652
+
653
+ ```
654
+ kiri/
655
+ β”œβ”€β”€ src/
656
+ β”‚ β”œβ”€β”€ indexer/ # Git scanning, AST parsing, schema management
657
+ β”‚ β”œβ”€β”€ server/ # MCP server, JSON-RPC handlers
658
+ β”‚ β”œβ”€β”€ client/ # CLI utilities, daemon management
659
+ β”‚ └── shared/ # DuckDB client, utilities
660
+ β”œβ”€β”€ tests/ # Test files (mirrors src/)
661
+ β”œβ”€β”€ docs/ # Architecture documentation
662
+ β”œβ”€β”€ config/ # YAML configuration schemas
663
+ β”œβ”€β”€ sql/ # SQL schema definitions
664
+ └── examples/ # Usage examples
665
+ ```
381
666
 
382
- See [AGENTS.md](AGENTS.md) for detailed guidelines.
667
+ See [AGENTS.md](AGENTS.md) for detailed development guidelines.
383
668
 
384
669
  ## πŸ“„ License
385
670
 
@@ -389,12 +674,12 @@ MIT License - See [LICENSE](LICENSE) for details.
389
674
 
390
675
  Built with:
391
676
 
677
+ - [Model Context Protocol](https://modelcontextprotocol.io/) - Standard for LLM context
392
678
  - [DuckDB](https://duckdb.org/) - Embedded analytical database
393
679
  - [tree-sitter](https://tree-sitter.github.io/) - Parser generator for AST extraction
394
- - [MCP](https://modelcontextprotocol.io/) - Model Context Protocol
395
680
 
396
681
  ---
397
682
 
398
- **Status**: v0.2.3 (Alpha) - Active development
683
+ **Status**: v0.4.1 (Beta) - Production-ready for MCP clients
399
684
 
400
- For questions or issues, please open a [GitHub issue](https://github.com/CAPHTECH/kiri/issues).
685
+ For questions or support, please open a [GitHub issue](https://github.com/CAPHTECH/kiri/issues).