kiri-mcp-server 0.4.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 +540 -255
- package/dist/package.json +3 -2
- package/dist/src/client/start-daemon.js +2 -2
- package/dist/src/client/start-daemon.js.map +1 -1
- package/dist/src/indexer/codeintel.d.ts.map +1 -1
- package/dist/src/indexer/codeintel.js +345 -1
- package/dist/src/indexer/codeintel.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,385 +1,670 @@
|
|
|
1
|
-
# KIRI
|
|
1
|
+
# KIRI MCP Server
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Intelligent code context extraction for LLMs via Model Context Protocol
|
|
4
4
|
|
|
5
|
-
[](package.json)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://modelcontextprotocol.io/)
|
|
8
9
|
|
|
9
|
-
**KIRI** is
|
|
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
|
-
## π―
|
|
12
|
+
## π― Why KIRI?
|
|
12
13
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
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
|
-
##
|
|
21
|
+
## βοΈ Prerequisites
|
|
22
|
+
|
|
23
|
+
Before using KIRI, ensure you have:
|
|
22
24
|
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
40
|
+
### Step 1: Install KIRI
|
|
35
41
|
|
|
36
|
-
|
|
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
|
-
|
|
50
|
+
> **Note**: This installs the `kiri` command globally. You can verify with `kiri --version`.
|
|
47
51
|
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
npm link
|
|
59
|
-
```
|
|
56
|
+
### Step 2: Configure Your MCP Client
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
#### For Claude Code
|
|
62
59
|
|
|
63
|
-
|
|
60
|
+
Edit `~/.claude/mcp.json`:
|
|
64
61
|
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
kiri-server --repo . --db .kiri/index.duckdb --reindex
|
|
86
|
+
**Timeout Configuration (Claude Code)**
|
|
73
87
|
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
>
|
|
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
|
-
|
|
106
|
+
| Variable | Default | Description |
|
|
107
|
+
| --------------------------- | ------- | ------------------------------------------------------------------------------ |
|
|
108
|
+
| `KIRI_DAEMON_READY_TIMEOUT` | `240` | Daemon initialization timeout in seconds. Increase for very large repositories |
|
|
84
109
|
|
|
85
|
-
|
|
110
|
+
#### For Codex CLI
|
|
86
111
|
|
|
87
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
121
|
+
**With Global Installation:**
|
|
96
122
|
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
130
|
+
| Parameter | Default | Description |
|
|
131
|
+
| --------------------- | ------- | ----------------------------------------------------------------------------- |
|
|
132
|
+
| `startup_timeout_sec` | `30` | Daemon initialization timeout in seconds. Set to `240` for large repositories |
|
|
103
133
|
|
|
104
|
-
|
|
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
|
-
|
|
136
|
+
### Step 3: Restart Your MCP Client
|
|
109
137
|
|
|
110
|
-
KIRI
|
|
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
|
-
|
|
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
|
-
|
|
142
|
+
Once configured, you can use KIRI tools in your conversations with Claude:
|
|
121
143
|
|
|
122
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
151
|
+
KIRI provides 5 MCP tools for intelligent code exploration:
|
|
129
152
|
|
|
130
|
-
###
|
|
153
|
+
### 1. context_bundle
|
|
131
154
|
|
|
132
|
-
|
|
155
|
+
**Extract relevant code context based on task goals**
|
|
133
156
|
|
|
134
|
-
|
|
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
|
-
|
|
139
|
-
// Find implementation files (default behavior)
|
|
140
|
-
mcp__kiri__files_search({ query: "filesSearch implementation" });
|
|
159
|
+
**When to use:**
|
|
141
160
|
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
178
|
+
**Parameters:**
|
|
150
179
|
|
|
151
|
-
|
|
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
|
-
|
|
187
|
+
### 2. files_search
|
|
154
188
|
|
|
155
|
-
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
166
|
-
|
|
201
|
+
```typescript
|
|
202
|
+
// Request
|
|
203
|
+
{
|
|
204
|
+
"query": "MCP server handler",
|
|
205
|
+
"limit": 20
|
|
206
|
+
}
|
|
167
207
|
|
|
168
|
-
|
|
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
|
-
**
|
|
211
|
+
**Query Syntax:**
|
|
173
212
|
|
|
174
|
-
|
|
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
|
-
|
|
217
|
+
**Parameters:**
|
|
177
218
|
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
228
|
+
### 3. snippets_get
|
|
183
229
|
|
|
184
|
-
|
|
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
|
-
"
|
|
187
|
-
|
|
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
|
-
|
|
252
|
+
**Parameters:**
|
|
202
253
|
|
|
203
|
-
|
|
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
|
-
"
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
**
|
|
291
|
+
**Parameters:**
|
|
222
292
|
|
|
223
|
-
|
|
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
|
-
|
|
300
|
+
### 5. semantic_rerank
|
|
226
301
|
|
|
227
|
-
|
|
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
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
**
|
|
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
|
-
|
|
339
|
+
### 1. Understanding a New Codebase
|
|
247
340
|
|
|
248
|
-
|
|
341
|
+
**Goal**: Quickly understand how authentication works in an unfamiliar project
|
|
249
342
|
|
|
250
343
|
```
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
###
|
|
352
|
+
### 2. Finding Related Code
|
|
265
353
|
|
|
266
|
-
|
|
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
|
-
|
|
356
|
+
```
|
|
357
|
+
You: "Find all API endpoint handlers"
|
|
271
358
|
|
|
272
|
-
|
|
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
|
-
|
|
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
|
-
|
|
367
|
+
**Goal**: Understand what will be affected by changing a utility function
|
|
281
368
|
|
|
282
|
-
|
|
369
|
+
```
|
|
370
|
+
You: "If I change the parseRequest function in utils.ts, what will be affected?"
|
|
283
371
|
|
|
284
|
-
|
|
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
|
-
|
|
287
|
-
# Run all tests with coverage (requires β₯80%)
|
|
288
|
-
pnpm run test
|
|
378
|
+
### 4. Code Review Preparation
|
|
289
379
|
|
|
290
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
301
|
-
|
|
398
|
+
# Enable watch mode (recommended for active development)
|
|
399
|
+
kiri --repo . --db .kiri/index.duckdb --watch
|
|
302
400
|
|
|
303
|
-
#
|
|
304
|
-
|
|
401
|
+
# Customize debounce timing (default: 500ms)
|
|
402
|
+
kiri --repo . --db .kiri/index.duckdb --watch --debounce 1000
|
|
305
403
|
```
|
|
306
404
|
|
|
307
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
598
|
+
### Performance
|
|
335
599
|
|
|
336
|
-
| Metric
|
|
337
|
-
|
|
|
338
|
-
| **
|
|
339
|
-
| **
|
|
340
|
-
| **Token Reduction**
|
|
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
|
-
|
|
606
|
+
### Community
|
|
344
607
|
|
|
345
|
-
-
|
|
346
|
-
-
|
|
347
|
-
-
|
|
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
|
-
## π οΈ
|
|
612
|
+
## π οΈ For Developers
|
|
613
|
+
|
|
614
|
+
### Local Development
|
|
350
615
|
|
|
351
616
|
```bash
|
|
352
|
-
#
|
|
353
|
-
|
|
617
|
+
# Clone and setup
|
|
618
|
+
git clone https://github.com/CAPHTECH/kiri.git
|
|
619
|
+
cd kiri
|
|
620
|
+
pnpm install
|
|
354
621
|
|
|
355
|
-
#
|
|
356
|
-
pnpm run
|
|
622
|
+
# Build
|
|
623
|
+
pnpm run build
|
|
357
624
|
|
|
358
|
-
#
|
|
359
|
-
|
|
360
|
-
pnpm run check # Lint + test
|
|
625
|
+
# Link globally for testing
|
|
626
|
+
npm link
|
|
361
627
|
|
|
362
|
-
#
|
|
363
|
-
|
|
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
|
-
#
|
|
370
|
-
|
|
631
|
+
# Start in development mode (HTTP server on :8765)
|
|
632
|
+
pnpm run dev
|
|
371
633
|
```
|
|
372
634
|
|
|
373
|
-
|
|
635
|
+
### Commands Reference
|
|
374
636
|
|
|
375
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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.
|
|
683
|
+
**Status**: v0.4.1 (Beta) - Production-ready for MCP clients
|
|
399
684
|
|
|
400
|
-
For questions or
|
|
685
|
+
For questions or support, please open a [GitHub issue](https://github.com/CAPHTECH/kiri/issues).
|