syntax-map-mcp 0.1.1 → 0.1.2
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/CHANGELOG.md +28 -0
- package/README.md +12 -5
- package/dist/analysis/index.js +218 -30
- package/dist/analysis/references.js +1 -1
- package/dist/analysis/summary.js +37 -11
- package/dist/tools.js +27 -3
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.2 - 2026-05-04
|
|
6
|
+
|
|
7
|
+
- `summarize_file`의 `exports` 추출을 AST 기반으로 변경해 문자열 내부 텍스트가 export로 잘못 반환되지 않도록 했습니다.
|
|
8
|
+
- `summarize_file` 응답에 `sources`를 추가해 `symbols`, `imports`, `exports` 추출 방식이 AST 기반임을 확인할 수 있게 했습니다.
|
|
9
|
+
- 인덱스 검색 도구에 `contextBefore`, `contextAfter` 옵션을 추가해 snippet 주변 라인을 함께 조회할 수 있게 했습니다.
|
|
10
|
+
- 패키지 버전을 `0.1.2`로 올렸습니다.
|
|
11
|
+
- `search_symbols` 결과에 현재 파일의 해당 줄 `snippet`을 추가했습니다.
|
|
12
|
+
- `find_indexed_references`를 추가해 SQLite 인덱스에서 식별자 참조를 검색할 수 있게 했습니다.
|
|
13
|
+
- `search_symbols`, `find_indexed_definition`, `find_indexed_references`가 `isStale`, `staleFiles`, `refreshed`를 반환하도록 했습니다.
|
|
14
|
+
- 인덱스 검색 도구에 `refreshIfStale` 옵션을 추가했습니다.
|
|
15
|
+
- `index_workspace`와 `get_index_status` 응답에 참조 인덱스 개수 `references`를 추가했습니다.
|
|
16
|
+
|
|
17
|
+
## 0.1.1 - 2026-05-04
|
|
18
|
+
|
|
19
|
+
- `find_indexed_definition`을 추가해 SQLite 인덱스에서 정확한 심볼 정의와 `snippet`을 조회할 수 있게 했습니다.
|
|
20
|
+
- README의 실행 예시와 MCP 설정 예시를 `npx -y syntax-map-mcp` 기반으로 변경했습니다.
|
|
21
|
+
- npm 페이지에서 GitHub 저장소가 노출되도록 `repository`, `homepage`, `bugs`, `license` 메타데이터를 추가했습니다.
|
|
22
|
+
- npm publish 경고를 피하도록 `bin` 경로를 `dist/cli.js` 형식으로 정규화했습니다.
|
|
23
|
+
|
|
24
|
+
## 0.1.0 - 2026-05-04
|
|
25
|
+
|
|
26
|
+
- Tree-sitter 기반 MCP 서버 초기 버전을 배포했습니다.
|
|
27
|
+
- JavaScript, TypeScript, TSX, Python 파일의 심볼, 정의, 참조, 요약, tree-sitter query, 컨텍스트 생성을 지원했습니다.
|
|
28
|
+
- SQLite 기반 workspace 심볼 인덱스를 추가했습니다.
|
package/README.md
CHANGED
|
@@ -33,20 +33,27 @@ npx -y syntax-map-mcp --workspace-root /path/to/workspace
|
|
|
33
33
|
- `list_symbols`: 파일 하나의 top-level 심볼 목록 반환
|
|
34
34
|
- `find_definition`: 여러 파일에서 이름과 선택적 kind로 정의 검색
|
|
35
35
|
- `find_references`: 여러 파일에서 식별자 참조 검색
|
|
36
|
-
- `summarize_file`: 파일 언어, 라인 수, imports, exports, symbols 요약
|
|
36
|
+
- `summarize_file`: 파일 언어, 라인 수, AST 기반 imports, exports, symbols 요약
|
|
37
37
|
- `run_query`: 파일 하나에 tree-sitter query 실행
|
|
38
38
|
- `build_context`: 여러 파일 요약을 markdown 컨텍스트로 구성
|
|
39
|
-
- `index_workspace`: 지원 소스 파일을 파싱해 SQLite
|
|
40
|
-
- `search_symbols`: SQLite 인덱스에서 심볼 이름 검색
|
|
39
|
+
- `index_workspace`: 지원 소스 파일을 파싱해 SQLite 심볼/참조 인덱스 생성 또는 갱신
|
|
40
|
+
- `search_symbols`: SQLite 인덱스에서 심볼 이름 검색 및 snippet 반환
|
|
41
41
|
- `find_indexed_definition`: SQLite 인덱스에서 정확한 심볼 정의 검색 및 snippet 반환
|
|
42
|
-
- `
|
|
42
|
+
- `find_indexed_references`: SQLite 인덱스에서 식별자 참조 검색 및 snippet 반환
|
|
43
|
+
- `get_index_status`: 인덱스 경로, 인덱싱된 파일 수, 심볼 수, 참조 수, stale 파일 수 반환
|
|
43
44
|
- `clear_index`: SQLite 인덱스 파일 삭제
|
|
44
45
|
|
|
45
46
|
## SQLite 인덱스
|
|
46
47
|
|
|
47
48
|
`index_workspace`는 `workspaceRoot` 아래의 `.syntax-map-mcp/index.sqlite`에 인덱스를 저장합니다. 인덱싱 대상은 `.js`, `.jsx`, `.ts`, `.tsx`, `.py` 파일이며, `.git`, `.syntax-map-mcp`, `dist`, `node_modules` 디렉터리는 제외합니다.
|
|
48
49
|
|
|
49
|
-
파일 변경 여부는 `mtimeMs`와 `size`로 판단합니다. 다시 `index_workspace`를 호출하면 변경된 파일만 재파싱하고, 삭제된 파일은 인덱스에서 제거합니다. `find_indexed_definition
|
|
50
|
+
파일 변경 여부는 `mtimeMs`와 `size`로 판단합니다. 다시 `index_workspace`를 호출하면 변경된 파일만 재파싱하고, 삭제된 파일은 인덱스에서 제거합니다. `search_symbols`, `find_indexed_definition`, `find_indexed_references`는 `isStale`, `staleFiles`, `refreshed`를 반환해 검색 결과가 최신 인덱스 기반인지 알려줍니다. 세 도구에 `refreshIfStale: true`를 전달하면 stale 파일이 있을 때 먼저 인덱스를 갱신한 뒤 검색합니다. 인덱스 검색 도구는 인덱스에 저장된 위치를 조회한 뒤 현재 파일에서 해당 줄 snippet을 읽어 반환합니다. `contextBefore`, `contextAfter`를 0-10 사이 정수로 전달하면 snippet 주변 라인도 함께 반환합니다. 자동 watch 모드는 아직 포함하지 않았습니다.
|
|
51
|
+
|
|
52
|
+
`summarize_file`은 `sources` 필드로 `symbols`, `imports`, `exports`가 어떤 방식으로 추출되었는지 반환합니다.
|
|
53
|
+
|
|
54
|
+
## 변경 이력
|
|
55
|
+
|
|
56
|
+
버전별 변경 내용은 [CHANGELOG.md](./CHANGELOG.md)를 참고하세요.
|
|
50
57
|
|
|
51
58
|
## MCP 설정 예시
|
|
52
59
|
|
package/dist/analysis/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import path from 'node:path';
|
|
|
3
3
|
import initSqlJs from 'sql.js';
|
|
4
4
|
import { listSymbols } from './symbols.js';
|
|
5
5
|
import { parseSourceFile } from '../parser.js';
|
|
6
|
+
import { runTreeSitterQuery } from './query.js';
|
|
7
|
+
import { referenceQueryForLanguage } from './references.js';
|
|
6
8
|
const INDEX_DIRECTORY = '.syntax-map-mcp';
|
|
7
9
|
const INDEX_FILE = 'index.sqlite';
|
|
8
10
|
function indexPathForWorkspace(workspace) {
|
|
@@ -63,8 +65,22 @@ function initSchema(database) {
|
|
|
63
65
|
FOREIGN KEY(file_path) REFERENCES files(path) ON DELETE CASCADE
|
|
64
66
|
);
|
|
65
67
|
|
|
68
|
+
CREATE TABLE IF NOT EXISTS reference_captures (
|
|
69
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
70
|
+
file_path TEXT NOT NULL,
|
|
71
|
+
language TEXT NOT NULL,
|
|
72
|
+
name TEXT NOT NULL,
|
|
73
|
+
node_type TEXT NOT NULL,
|
|
74
|
+
start_row INTEGER NOT NULL,
|
|
75
|
+
start_column INTEGER NOT NULL,
|
|
76
|
+
end_row INTEGER NOT NULL,
|
|
77
|
+
end_column INTEGER NOT NULL,
|
|
78
|
+
FOREIGN KEY(file_path) REFERENCES files(path) ON DELETE CASCADE
|
|
79
|
+
);
|
|
80
|
+
|
|
66
81
|
CREATE INDEX IF NOT EXISTS symbols_name_idx ON symbols(name);
|
|
67
82
|
CREATE INDEX IF NOT EXISTS symbols_kind_idx ON symbols(kind);
|
|
83
|
+
CREATE INDEX IF NOT EXISTS reference_captures_name_idx ON reference_captures(name);
|
|
68
84
|
`);
|
|
69
85
|
}
|
|
70
86
|
function selectStoredFiles(database) {
|
|
@@ -90,6 +106,53 @@ function isCurrent(stored, current) {
|
|
|
90
106
|
stored.size === current.size &&
|
|
91
107
|
stored.mtimeMs === current.mtimeMs);
|
|
92
108
|
}
|
|
109
|
+
async function countStaleFiles(workspace, database) {
|
|
110
|
+
const storedFiles = selectStoredFiles(database);
|
|
111
|
+
const currentFiles = await workspace.listSourceFiles();
|
|
112
|
+
const currentPaths = new Set(currentFiles.map(file => file.relativePath));
|
|
113
|
+
let staleFiles = 0;
|
|
114
|
+
for (const file of currentFiles) {
|
|
115
|
+
if (!isCurrent(storedFiles.get(file.relativePath), file)) {
|
|
116
|
+
staleFiles += 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const storedPath of storedFiles.keys()) {
|
|
120
|
+
if (!currentPaths.has(storedPath)) {
|
|
121
|
+
staleFiles += 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return staleFiles;
|
|
125
|
+
}
|
|
126
|
+
async function openIndexForRead(workspace, input) {
|
|
127
|
+
const indexPath = indexPathForWorkspace(workspace);
|
|
128
|
+
let database = await openDatabase(indexPath);
|
|
129
|
+
initSchema(database);
|
|
130
|
+
const initialStaleFiles = await countStaleFiles(workspace, database);
|
|
131
|
+
if (!input.refreshIfStale || initialStaleFiles === 0) {
|
|
132
|
+
return {
|
|
133
|
+
database,
|
|
134
|
+
indexPath,
|
|
135
|
+
isStale: initialStaleFiles > 0,
|
|
136
|
+
staleFiles: initialStaleFiles,
|
|
137
|
+
refreshed: false
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
database.close();
|
|
141
|
+
const refreshedIndex = await indexWorkspace(workspace);
|
|
142
|
+
if (!refreshedIndex.ok) {
|
|
143
|
+
throw new Error(refreshedIndex.error.message);
|
|
144
|
+
}
|
|
145
|
+
database = await openDatabase(indexPath);
|
|
146
|
+
initSchema(database);
|
|
147
|
+
const staleFiles = await countStaleFiles(workspace, database);
|
|
148
|
+
return {
|
|
149
|
+
database,
|
|
150
|
+
indexPath,
|
|
151
|
+
isStale: staleFiles > 0,
|
|
152
|
+
staleFiles,
|
|
153
|
+
refreshed: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
93
156
|
function upsertFile(database, input) {
|
|
94
157
|
database.run(`
|
|
95
158
|
INSERT INTO files (path, language, size, mtime_ms, parse_status, error_message, indexed_at)
|
|
@@ -145,12 +208,39 @@ function insertSymbol(database, input) {
|
|
|
145
208
|
input.symbol.selectionRange?.end.column ?? null
|
|
146
209
|
]);
|
|
147
210
|
}
|
|
211
|
+
function insertReference(database, input) {
|
|
212
|
+
database.run(`
|
|
213
|
+
INSERT INTO reference_captures (
|
|
214
|
+
file_path,
|
|
215
|
+
language,
|
|
216
|
+
name,
|
|
217
|
+
node_type,
|
|
218
|
+
start_row,
|
|
219
|
+
start_column,
|
|
220
|
+
end_row,
|
|
221
|
+
end_column
|
|
222
|
+
)
|
|
223
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
224
|
+
`, [
|
|
225
|
+
input.filePath,
|
|
226
|
+
input.language,
|
|
227
|
+
input.name,
|
|
228
|
+
input.nodeType,
|
|
229
|
+
input.range.start.row,
|
|
230
|
+
input.range.start.column,
|
|
231
|
+
input.range.end.row,
|
|
232
|
+
input.range.end.column
|
|
233
|
+
]);
|
|
234
|
+
}
|
|
148
235
|
function deleteFile(database, filePath) {
|
|
149
236
|
database.run('DELETE FROM files WHERE path = ?', [filePath]);
|
|
150
237
|
}
|
|
151
238
|
function deleteSymbolsForFile(database, filePath) {
|
|
152
239
|
database.run('DELETE FROM symbols WHERE file_path = ?', [filePath]);
|
|
153
240
|
}
|
|
241
|
+
function deleteReferencesForFile(database, filePath) {
|
|
242
|
+
database.run('DELETE FROM reference_captures WHERE file_path = ?', [filePath]);
|
|
243
|
+
}
|
|
154
244
|
function scalarCount(database, sql) {
|
|
155
245
|
const result = database.exec(sql)[0];
|
|
156
246
|
if (!result)
|
|
@@ -163,8 +253,23 @@ function sqlLikePattern(query) {
|
|
|
163
253
|
function rowValue(row, key) {
|
|
164
254
|
return row[key];
|
|
165
255
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
256
|
+
function snippetDetails(text, row, options) {
|
|
257
|
+
if (text === undefined)
|
|
258
|
+
return { snippet: '' };
|
|
259
|
+
const lines = text.split(/\r?\n/);
|
|
260
|
+
const snippet = lines[row] ?? '';
|
|
261
|
+
const beforeCount = options.contextBefore ?? 0;
|
|
262
|
+
const afterCount = options.contextAfter ?? 0;
|
|
263
|
+
if (beforeCount === 0 && afterCount === 0) {
|
|
264
|
+
return { snippet };
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
snippet,
|
|
268
|
+
context: {
|
|
269
|
+
before: lines.slice(Math.max(0, row - beforeCount), row),
|
|
270
|
+
after: lines.slice(row + 1, row + 1 + afterCount)
|
|
271
|
+
}
|
|
272
|
+
};
|
|
168
273
|
}
|
|
169
274
|
export async function indexWorkspace(workspace) {
|
|
170
275
|
const indexPath = indexPathForWorkspace(workspace);
|
|
@@ -197,6 +302,7 @@ export async function indexWorkspace(workspace) {
|
|
|
197
302
|
errorMessage: file.error.message
|
|
198
303
|
});
|
|
199
304
|
deleteSymbolsForFile(database, fileInfo.relativePath);
|
|
305
|
+
deleteReferencesForFile(database, fileInfo.relativePath);
|
|
200
306
|
indexedFiles += 1;
|
|
201
307
|
continue;
|
|
202
308
|
}
|
|
@@ -209,6 +315,7 @@ export async function indexWorkspace(workspace) {
|
|
|
209
315
|
errorMessage: parsed.error.message
|
|
210
316
|
});
|
|
211
317
|
deleteSymbolsForFile(database, fileInfo.relativePath);
|
|
318
|
+
deleteReferencesForFile(database, fileInfo.relativePath);
|
|
212
319
|
indexedFiles += 1;
|
|
213
320
|
continue;
|
|
214
321
|
}
|
|
@@ -219,6 +326,7 @@ export async function indexWorkspace(workspace) {
|
|
|
219
326
|
errorMessage: null
|
|
220
327
|
});
|
|
221
328
|
deleteSymbolsForFile(database, fileInfo.relativePath);
|
|
329
|
+
deleteReferencesForFile(database, fileInfo.relativePath);
|
|
222
330
|
for (const symbol of listSymbols(parsed)) {
|
|
223
331
|
insertSymbol(database, {
|
|
224
332
|
filePath: fileInfo.relativePath,
|
|
@@ -226,6 +334,19 @@ export async function indexWorkspace(workspace) {
|
|
|
226
334
|
symbol
|
|
227
335
|
});
|
|
228
336
|
}
|
|
337
|
+
const references = runTreeSitterQuery(parsed, referenceQueryForLanguage(parsed.language));
|
|
338
|
+
if (!references.ok) {
|
|
339
|
+
throw new Error(references.error.message);
|
|
340
|
+
}
|
|
341
|
+
for (const reference of references.captures) {
|
|
342
|
+
insertReference(database, {
|
|
343
|
+
filePath: fileInfo.relativePath,
|
|
344
|
+
language: parsed.language,
|
|
345
|
+
name: reference.text,
|
|
346
|
+
nodeType: reference.nodeType,
|
|
347
|
+
range: reference.range
|
|
348
|
+
});
|
|
349
|
+
}
|
|
229
350
|
indexedFiles += 1;
|
|
230
351
|
}
|
|
231
352
|
await saveDatabase(database, indexPath);
|
|
@@ -235,7 +356,8 @@ export async function indexWorkspace(workspace) {
|
|
|
235
356
|
indexedFiles,
|
|
236
357
|
skippedFiles,
|
|
237
358
|
removedFiles,
|
|
238
|
-
symbols: scalarCount(database, 'SELECT COUNT(*) FROM symbols')
|
|
359
|
+
symbols: scalarCount(database, 'SELECT COUNT(*) FROM symbols'),
|
|
360
|
+
references: scalarCount(database, 'SELECT COUNT(*) FROM reference_captures')
|
|
239
361
|
};
|
|
240
362
|
}
|
|
241
363
|
catch (error) {
|
|
@@ -246,10 +368,10 @@ export async function indexWorkspace(workspace) {
|
|
|
246
368
|
}
|
|
247
369
|
}
|
|
248
370
|
export async function findIndexedDefinitions(workspace, input) {
|
|
249
|
-
|
|
250
|
-
const database = await openDatabase(indexPath);
|
|
371
|
+
let readState;
|
|
251
372
|
try {
|
|
252
|
-
|
|
373
|
+
readState = await openIndexForRead(workspace, input);
|
|
374
|
+
const { database } = readState;
|
|
253
375
|
const where = ['name = ?'];
|
|
254
376
|
const params = [input.name];
|
|
255
377
|
if (input.kinds && input.kinds.length > 0) {
|
|
@@ -320,7 +442,7 @@ export async function findIndexedDefinitions(workspace, input) {
|
|
|
320
442
|
column: Number(selectionEndColumn)
|
|
321
443
|
}
|
|
322
444
|
},
|
|
323
|
-
|
|
445
|
+
...snippetDetails(file.ok ? file.text : undefined, startRow, input)
|
|
324
446
|
});
|
|
325
447
|
}
|
|
326
448
|
}
|
|
@@ -329,7 +451,10 @@ export async function findIndexedDefinitions(workspace, input) {
|
|
|
329
451
|
}
|
|
330
452
|
return {
|
|
331
453
|
ok: true,
|
|
332
|
-
indexPath,
|
|
454
|
+
indexPath: readState.indexPath,
|
|
455
|
+
isStale: readState.isStale,
|
|
456
|
+
staleFiles: readState.staleFiles,
|
|
457
|
+
refreshed: readState.refreshed,
|
|
333
458
|
total: definitions.length,
|
|
334
459
|
definitions
|
|
335
460
|
};
|
|
@@ -338,14 +463,81 @@ export async function findIndexedDefinitions(workspace, input) {
|
|
|
338
463
|
return failure(error instanceof Error ? error.message : String(error));
|
|
339
464
|
}
|
|
340
465
|
finally {
|
|
341
|
-
database.close();
|
|
466
|
+
readState?.database.close();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
export async function findIndexedReferences(workspace, input) {
|
|
470
|
+
let readState;
|
|
471
|
+
try {
|
|
472
|
+
readState = await openIndexForRead(workspace, input);
|
|
473
|
+
const { database } = readState;
|
|
474
|
+
const limit = input.limit ?? 50;
|
|
475
|
+
const statement = database.prepare(`
|
|
476
|
+
SELECT
|
|
477
|
+
file_path,
|
|
478
|
+
language,
|
|
479
|
+
name,
|
|
480
|
+
node_type,
|
|
481
|
+
start_row,
|
|
482
|
+
start_column,
|
|
483
|
+
end_row,
|
|
484
|
+
end_column
|
|
485
|
+
FROM reference_captures
|
|
486
|
+
WHERE name = ?
|
|
487
|
+
ORDER BY file_path ASC, start_row ASC
|
|
488
|
+
LIMIT ?
|
|
489
|
+
`, [input.name, limit]);
|
|
490
|
+
const references = [];
|
|
491
|
+
try {
|
|
492
|
+
while (statement.step()) {
|
|
493
|
+
const row = statement.getAsObject();
|
|
494
|
+
const filePath = String(rowValue(row, 'file_path'));
|
|
495
|
+
const startRow = Number(rowValue(row, 'start_row'));
|
|
496
|
+
const file = await workspace.readSourceFile(filePath);
|
|
497
|
+
references.push({
|
|
498
|
+
path: filePath,
|
|
499
|
+
language: rowValue(row, 'language'),
|
|
500
|
+
name: String(rowValue(row, 'name')),
|
|
501
|
+
nodeType: String(rowValue(row, 'node_type')),
|
|
502
|
+
range: {
|
|
503
|
+
start: {
|
|
504
|
+
row: startRow,
|
|
505
|
+
column: Number(rowValue(row, 'start_column'))
|
|
506
|
+
},
|
|
507
|
+
end: {
|
|
508
|
+
row: Number(rowValue(row, 'end_row')),
|
|
509
|
+
column: Number(rowValue(row, 'end_column'))
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
...snippetDetails(file.ok ? file.text : undefined, startRow, input)
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
finally {
|
|
517
|
+
statement.free();
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
ok: true,
|
|
521
|
+
indexPath: readState.indexPath,
|
|
522
|
+
isStale: readState.isStale,
|
|
523
|
+
staleFiles: readState.staleFiles,
|
|
524
|
+
refreshed: readState.refreshed,
|
|
525
|
+
total: references.length,
|
|
526
|
+
references
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
catch (error) {
|
|
530
|
+
return failure(error instanceof Error ? error.message : String(error));
|
|
531
|
+
}
|
|
532
|
+
finally {
|
|
533
|
+
readState?.database.close();
|
|
342
534
|
}
|
|
343
535
|
}
|
|
344
536
|
export async function searchSymbols(workspace, input) {
|
|
345
|
-
|
|
346
|
-
const database = await openDatabase(indexPath);
|
|
537
|
+
let readState;
|
|
347
538
|
try {
|
|
348
|
-
|
|
539
|
+
readState = await openIndexForRead(workspace, input);
|
|
540
|
+
const { database } = readState;
|
|
349
541
|
const where = ['name LIKE ? ESCAPE "\\"'];
|
|
350
542
|
const params = [sqlLikePattern(input.query)];
|
|
351
543
|
if (input.kinds && input.kinds.length > 0) {
|
|
@@ -382,15 +574,18 @@ export async function searchSymbols(workspace, input) {
|
|
|
382
574
|
const selectionStartColumn = rowValue(row, 'selection_start_column');
|
|
383
575
|
const selectionEndRow = rowValue(row, 'selection_end_row');
|
|
384
576
|
const selectionEndColumn = rowValue(row, 'selection_end_column');
|
|
577
|
+
const filePath = String(rowValue(row, 'file_path'));
|
|
578
|
+
const startRow = Number(rowValue(row, 'start_row'));
|
|
579
|
+
const file = await workspace.readSourceFile(filePath);
|
|
385
580
|
symbols.push({
|
|
386
|
-
path:
|
|
581
|
+
path: filePath,
|
|
387
582
|
language: rowValue(row, 'language'),
|
|
388
583
|
name: String(rowValue(row, 'name')),
|
|
389
584
|
kind: rowValue(row, 'kind'),
|
|
390
585
|
parentName: rowValue(row, 'parent_name') === null ? undefined : String(rowValue(row, 'parent_name')),
|
|
391
586
|
range: {
|
|
392
587
|
start: {
|
|
393
|
-
row:
|
|
588
|
+
row: startRow,
|
|
394
589
|
column: Number(rowValue(row, 'start_column'))
|
|
395
590
|
},
|
|
396
591
|
end: {
|
|
@@ -412,7 +607,8 @@ export async function searchSymbols(workspace, input) {
|
|
|
412
607
|
row: Number(selectionEndRow),
|
|
413
608
|
column: Number(selectionEndColumn)
|
|
414
609
|
}
|
|
415
|
-
}
|
|
610
|
+
},
|
|
611
|
+
...snippetDetails(file.ok ? file.text : undefined, startRow, input)
|
|
416
612
|
});
|
|
417
613
|
}
|
|
418
614
|
}
|
|
@@ -421,7 +617,10 @@ export async function searchSymbols(workspace, input) {
|
|
|
421
617
|
}
|
|
422
618
|
return {
|
|
423
619
|
ok: true,
|
|
424
|
-
indexPath,
|
|
620
|
+
indexPath: readState.indexPath,
|
|
621
|
+
isStale: readState.isStale,
|
|
622
|
+
staleFiles: readState.staleFiles,
|
|
623
|
+
refreshed: readState.refreshed,
|
|
425
624
|
total: symbols.length,
|
|
426
625
|
symbols
|
|
427
626
|
};
|
|
@@ -430,7 +629,7 @@ export async function searchSymbols(workspace, input) {
|
|
|
430
629
|
return failure(error instanceof Error ? error.message : String(error));
|
|
431
630
|
}
|
|
432
631
|
finally {
|
|
433
|
-
database.close();
|
|
632
|
+
readState?.database.close();
|
|
434
633
|
}
|
|
435
634
|
}
|
|
436
635
|
export async function getIndexStatus(workspace) {
|
|
@@ -438,24 +637,13 @@ export async function getIndexStatus(workspace) {
|
|
|
438
637
|
const database = await openDatabase(indexPath);
|
|
439
638
|
try {
|
|
440
639
|
initSchema(database);
|
|
441
|
-
const
|
|
442
|
-
const currentFiles = await workspace.listSourceFiles();
|
|
443
|
-
let staleFiles = 0;
|
|
444
|
-
for (const file of currentFiles) {
|
|
445
|
-
if (!isCurrent(storedFiles.get(file.relativePath), file)) {
|
|
446
|
-
staleFiles += 1;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
for (const storedPath of storedFiles.keys()) {
|
|
450
|
-
if (!currentFiles.some(file => file.relativePath === storedPath)) {
|
|
451
|
-
staleFiles += 1;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
640
|
+
const staleFiles = await countStaleFiles(workspace, database);
|
|
454
641
|
return {
|
|
455
642
|
ok: true,
|
|
456
643
|
indexPath,
|
|
457
644
|
indexedFiles: scalarCount(database, 'SELECT COUNT(*) FROM files WHERE parse_status = "ok"'),
|
|
458
645
|
symbols: scalarCount(database, 'SELECT COUNT(*) FROM symbols'),
|
|
646
|
+
references: scalarCount(database, 'SELECT COUNT(*) FROM reference_captures'),
|
|
459
647
|
staleFiles
|
|
460
648
|
};
|
|
461
649
|
}
|
|
@@ -24,7 +24,7 @@ export async function findReferences(workspace, input) {
|
|
|
24
24
|
}
|
|
25
25
|
return { ok: true, references };
|
|
26
26
|
}
|
|
27
|
-
function referenceQueryForLanguage(language) {
|
|
27
|
+
export function referenceQueryForLanguage(language) {
|
|
28
28
|
switch (language) {
|
|
29
29
|
case 'typescript':
|
|
30
30
|
case 'tsx':
|
package/dist/analysis/summary.js
CHANGED
|
@@ -13,8 +13,13 @@ export async function summarizeFile(workspace, filePath) {
|
|
|
13
13
|
language: parsed.language,
|
|
14
14
|
lineCount: countLines(file.text),
|
|
15
15
|
symbols: listSymbols(parsed),
|
|
16
|
-
imports: findImports(
|
|
17
|
-
exports: findExports(
|
|
16
|
+
imports: findImports(parsed),
|
|
17
|
+
exports: findExports(parsed),
|
|
18
|
+
sources: {
|
|
19
|
+
symbols: 'ast',
|
|
20
|
+
imports: 'ast',
|
|
21
|
+
exports: 'ast'
|
|
22
|
+
}
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
function countLines(text) {
|
|
@@ -22,15 +27,36 @@ function countLines(text) {
|
|
|
22
27
|
return 0;
|
|
23
28
|
return text.replace(/\r\n|\r|\n$/, '').split(/\r\n|\r|\n/).length;
|
|
24
29
|
}
|
|
25
|
-
function findImports(
|
|
26
|
-
return
|
|
30
|
+
function findImports(parsed) {
|
|
31
|
+
return parsed.tree.rootNode.namedChildren
|
|
32
|
+
.filter(node => isImportNode(parsed.language, node.type))
|
|
33
|
+
.map(node => firstLine(node.text));
|
|
27
34
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
35
|
+
function isImportNode(language, nodeType) {
|
|
36
|
+
switch (language) {
|
|
37
|
+
case 'python':
|
|
38
|
+
return nodeType === 'import_statement' || nodeType === 'import_from_statement';
|
|
39
|
+
case 'javascript':
|
|
40
|
+
case 'typescript':
|
|
41
|
+
case 'tsx':
|
|
42
|
+
return nodeType === 'import_statement';
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
33
|
-
.
|
|
34
|
-
.map(
|
|
35
|
-
|
|
45
|
+
function findExports(parsed) {
|
|
46
|
+
return parsed.tree.rootNode.namedChildren
|
|
47
|
+
.filter(node => isExportNode(parsed.language, node.type))
|
|
48
|
+
.map(node => firstLine(node.text));
|
|
49
|
+
}
|
|
50
|
+
function isExportNode(language, nodeType) {
|
|
51
|
+
switch (language) {
|
|
52
|
+
case 'javascript':
|
|
53
|
+
case 'typescript':
|
|
54
|
+
case 'tsx':
|
|
55
|
+
return nodeType === 'export_statement';
|
|
56
|
+
case 'python':
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function firstLine(text) {
|
|
61
|
+
return text.split(/\r\n|\r|\n/, 1)[0].trim();
|
|
36
62
|
}
|
package/dist/tools.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { buildContext as buildContextAnalysis } from './analysis/context.js';
|
|
3
3
|
import { findDefinitions } from './analysis/definitions.js';
|
|
4
|
-
import { clearIndex as clearWorkspaceIndex, findIndexedDefinitions, getIndexStatus as getWorkspaceIndexStatus, indexWorkspace as indexWorkspaceAnalysis, searchSymbols as searchIndexedSymbols } from './analysis/index.js';
|
|
4
|
+
import { clearIndex as clearWorkspaceIndex, findIndexedDefinitions, findIndexedReferences, getIndexStatus as getWorkspaceIndexStatus, indexWorkspace as indexWorkspaceAnalysis, searchSymbols as searchIndexedSymbols } from './analysis/index.js';
|
|
5
5
|
import { runTreeSitterQuery } from './analysis/query.js';
|
|
6
6
|
import { findReferences as findReferencesAnalysis } from './analysis/references.js';
|
|
7
7
|
import { summarizeFile as summarizeFileAnalysis } from './analysis/summary.js';
|
|
@@ -10,6 +10,7 @@ import { parseSourceFile } from './parser.js';
|
|
|
10
10
|
import { jsonResult, toolFailure } from './result.js';
|
|
11
11
|
const symbolKindSchema = z.enum(['function', 'method', 'class', 'variable', 'interface', 'type']);
|
|
12
12
|
const detailSchema = z.enum(['compact', 'full']);
|
|
13
|
+
const contextLineCountSchema = z.number().int().min(0).max(10);
|
|
13
14
|
export function createToolHandlers(workspace) {
|
|
14
15
|
return {
|
|
15
16
|
async listSymbols(input) {
|
|
@@ -80,6 +81,12 @@ export function createToolHandlers(workspace) {
|
|
|
80
81
|
return toolFailure(result.error.code, result.error.message);
|
|
81
82
|
return jsonResult(result);
|
|
82
83
|
},
|
|
84
|
+
async findIndexedReferences(input) {
|
|
85
|
+
const result = await findIndexedReferences(workspace, input);
|
|
86
|
+
if (!result.ok)
|
|
87
|
+
return toolFailure(result.error.code, result.error.message);
|
|
88
|
+
return jsonResult(result);
|
|
89
|
+
},
|
|
83
90
|
async getIndexStatus(_input) {
|
|
84
91
|
const result = await getWorkspaceIndexStatus(workspace);
|
|
85
92
|
if (!result.ok)
|
|
@@ -154,7 +161,10 @@ export function registerTools(server, workspace) {
|
|
|
154
161
|
inputSchema: {
|
|
155
162
|
query: z.string(),
|
|
156
163
|
kinds: z.array(symbolKindSchema).optional(),
|
|
157
|
-
limit: z.number().int().positive().max(500).optional()
|
|
164
|
+
limit: z.number().int().positive().max(500).optional(),
|
|
165
|
+
refreshIfStale: z.boolean().optional(),
|
|
166
|
+
contextBefore: contextLineCountSchema.optional(),
|
|
167
|
+
contextAfter: contextLineCountSchema.optional()
|
|
158
168
|
}
|
|
159
169
|
}, handlers.searchSymbols);
|
|
160
170
|
server.registerTool('find_indexed_definition', {
|
|
@@ -163,9 +173,23 @@ export function registerTools(server, workspace) {
|
|
|
163
173
|
inputSchema: {
|
|
164
174
|
name: z.string(),
|
|
165
175
|
kinds: z.array(symbolKindSchema).optional(),
|
|
166
|
-
limit: z.number().int().positive().max(500).optional()
|
|
176
|
+
limit: z.number().int().positive().max(500).optional(),
|
|
177
|
+
refreshIfStale: z.boolean().optional(),
|
|
178
|
+
contextBefore: contextLineCountSchema.optional(),
|
|
179
|
+
contextAfter: contextLineCountSchema.optional()
|
|
167
180
|
}
|
|
168
181
|
}, handlers.findIndexedDefinition);
|
|
182
|
+
server.registerTool('find_indexed_references', {
|
|
183
|
+
title: 'Find indexed references',
|
|
184
|
+
description: 'Find identifier references from the SQLite workspace index with snippets.',
|
|
185
|
+
inputSchema: {
|
|
186
|
+
name: z.string(),
|
|
187
|
+
limit: z.number().int().positive().max(500).optional(),
|
|
188
|
+
refreshIfStale: z.boolean().optional(),
|
|
189
|
+
contextBefore: contextLineCountSchema.optional(),
|
|
190
|
+
contextAfter: contextLineCountSchema.optional()
|
|
191
|
+
}
|
|
192
|
+
}, handlers.findIndexedReferences);
|
|
169
193
|
server.registerTool('get_index_status', {
|
|
170
194
|
title: 'Get index status',
|
|
171
195
|
description: 'Return SQLite index path, indexed file count, symbol count, and stale file count.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "syntax-map-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Tree-sitter based code analysis MCP server",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
20
|
"README.md",
|
|
21
|
+
"CHANGELOG.md",
|
|
21
22
|
"LICENSE"
|
|
22
23
|
],
|
|
23
24
|
"publishConfig": {
|