@aiready/ast-mcp-server 0.4.8 → 0.6.0
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/dist/index.cjs +180 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +176 -41
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -31,10 +31,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
));
|
|
32
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
33
|
|
|
34
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.
|
|
34
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.9_tsx@4.21.0_typescript@6.0.2_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js
|
|
35
35
|
var getImportMetaUrl, importMetaUrl;
|
|
36
36
|
var init_cjs_shims = __esm({
|
|
37
|
-
"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.
|
|
37
|
+
"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.9_tsx@4.21.0_typescript@6.0.2_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
38
|
"use strict";
|
|
39
39
|
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
40
40
|
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
@@ -186,6 +186,9 @@ var CheckSymbolGroundingSchema = import_zod.z.object({
|
|
|
186
186
|
symbol: import_zod.z.string().describe("Symbol name to assess grounding for"),
|
|
187
187
|
path: import_zod.z.string().describe("Project root directory")
|
|
188
188
|
});
|
|
189
|
+
var CodebaseAuditSchema = import_zod.z.object({
|
|
190
|
+
path: import_zod.z.string().describe("Project root directory to audit for debt and bloat")
|
|
191
|
+
});
|
|
189
192
|
|
|
190
193
|
// src/tools/resolve-definition.ts
|
|
191
194
|
init_cjs_shims();
|
|
@@ -584,9 +587,9 @@ var TypeScriptAdapter = class {
|
|
|
584
587
|
await symbolIndex.buildIndex(searchPath);
|
|
585
588
|
}
|
|
586
589
|
}
|
|
587
|
-
async resolveDefinition(symbolName,
|
|
588
|
-
validateWorkspacePath(
|
|
589
|
-
await this.ensureIndex(
|
|
590
|
+
async resolveDefinition(symbolName, path7) {
|
|
591
|
+
validateWorkspacePath(path7);
|
|
592
|
+
await this.ensureIndex(path7);
|
|
590
593
|
const indexHits = symbolIndex.lookup(symbolName);
|
|
591
594
|
if (indexHits.length > 0) {
|
|
592
595
|
const results = [];
|
|
@@ -614,33 +617,33 @@ var TypeScriptAdapter = class {
|
|
|
614
617
|
}
|
|
615
618
|
return results;
|
|
616
619
|
}
|
|
617
|
-
if (import_fs3.default.statSync(
|
|
620
|
+
if (import_fs3.default.statSync(path7).isDirectory()) {
|
|
618
621
|
return [];
|
|
619
622
|
}
|
|
620
|
-
const tsconfig = await projectManager.findNearestTsConfig(
|
|
623
|
+
const tsconfig = await projectManager.findNearestTsConfig(path7);
|
|
621
624
|
if (!tsconfig) return [];
|
|
622
625
|
try {
|
|
623
626
|
const result = await this.pool.execute(
|
|
624
627
|
"resolve_definition",
|
|
625
628
|
{
|
|
626
629
|
tsconfig,
|
|
627
|
-
file:
|
|
630
|
+
file: path7,
|
|
628
631
|
symbol: symbolName
|
|
629
632
|
}
|
|
630
633
|
);
|
|
631
634
|
return result;
|
|
632
635
|
} catch {
|
|
633
636
|
const project = projectManager.ensureProject(tsconfig);
|
|
634
|
-
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
637
|
+
const sourceFile = project.addSourceFileAtPathIfExists(path7);
|
|
635
638
|
if (!sourceFile) return [];
|
|
636
639
|
const exported = sourceFile.getExportedDeclarations().get(symbolName);
|
|
637
640
|
if (!exported) return [];
|
|
638
641
|
return exported.map((decl) => this.mapToDefinitionLocation(decl));
|
|
639
642
|
}
|
|
640
643
|
}
|
|
641
|
-
async findReferences(symbolName,
|
|
642
|
-
validateWorkspacePath(
|
|
643
|
-
await this.ensureIndex(
|
|
644
|
+
async findReferences(symbolName, path7, limit = 50, offset = 0) {
|
|
645
|
+
validateWorkspacePath(path7);
|
|
646
|
+
await this.ensureIndex(path7);
|
|
644
647
|
const hits = symbolIndex.lookup(symbolName);
|
|
645
648
|
if (hits.length === 0) return { references: [], total_count: 0 };
|
|
646
649
|
const hit = hits[0];
|
|
@@ -653,7 +656,7 @@ var TypeScriptAdapter = class {
|
|
|
653
656
|
const { searchCode: searchCode2 } = await Promise.resolve().then(() => (init_search_code(), search_code_exports));
|
|
654
657
|
const searchResults = await searchCode2(
|
|
655
658
|
symbolName,
|
|
656
|
-
|
|
659
|
+
path7,
|
|
657
660
|
"**/*.{ts,tsx,js,jsx}",
|
|
658
661
|
1e3,
|
|
659
662
|
false
|
|
@@ -690,9 +693,9 @@ var TypeScriptAdapter = class {
|
|
|
690
693
|
total_count: unique.length
|
|
691
694
|
};
|
|
692
695
|
}
|
|
693
|
-
async findImplementations(symbolName,
|
|
694
|
-
validateWorkspacePath(
|
|
695
|
-
await this.ensureIndex(
|
|
696
|
+
async findImplementations(symbolName, path7, limit = 50, offset = 0) {
|
|
697
|
+
validateWorkspacePath(path7);
|
|
698
|
+
await this.ensureIndex(path7);
|
|
696
699
|
const hits = symbolIndex.lookup(symbolName);
|
|
697
700
|
if (hits.length === 0) return { implementations: [], total_count: 0 };
|
|
698
701
|
const hit = hits[0];
|
|
@@ -723,7 +726,7 @@ var TypeScriptAdapter = class {
|
|
|
723
726
|
const { searchCode: searchCode2 } = await Promise.resolve().then(() => (init_search_code(), search_code_exports));
|
|
724
727
|
const searchResults = await searchCode2(
|
|
725
728
|
symbolName,
|
|
726
|
-
|
|
729
|
+
path7,
|
|
727
730
|
"**/*.{ts,tsx,js,jsx}",
|
|
728
731
|
1e3,
|
|
729
732
|
false
|
|
@@ -902,33 +905,33 @@ var TypeScriptAdapter = class {
|
|
|
902
905
|
var typescriptAdapter = new TypeScriptAdapter();
|
|
903
906
|
|
|
904
907
|
// src/utils/tool-utils.ts
|
|
905
|
-
async function wrapAdapterCall(methodName, symbol,
|
|
908
|
+
async function wrapAdapterCall(methodName, symbol, path7, ...args) {
|
|
906
909
|
const method = typescriptAdapter[methodName];
|
|
907
|
-
return await method.apply(typescriptAdapter, [symbol,
|
|
910
|
+
return await method.apply(typescriptAdapter, [symbol, path7, ...args]);
|
|
908
911
|
}
|
|
909
912
|
|
|
910
913
|
// src/tools/resolve-definition.ts
|
|
911
|
-
async function resolveDefinition(symbol,
|
|
914
|
+
async function resolveDefinition(symbol, path7) {
|
|
912
915
|
return await wrapAdapterCall(
|
|
913
916
|
"resolveDefinition",
|
|
914
917
|
symbol,
|
|
915
|
-
|
|
918
|
+
path7
|
|
916
919
|
);
|
|
917
920
|
}
|
|
918
921
|
|
|
919
922
|
// src/tools/find-references.ts
|
|
920
923
|
init_cjs_shims();
|
|
921
|
-
async function findReferences(symbol,
|
|
922
|
-
return await wrapAdapterCall("findReferences", symbol,
|
|
924
|
+
async function findReferences(symbol, path7, limit = 50, offset = 0) {
|
|
925
|
+
return await wrapAdapterCall("findReferences", symbol, path7, limit, offset);
|
|
923
926
|
}
|
|
924
927
|
|
|
925
928
|
// src/tools/find-implementations.ts
|
|
926
929
|
init_cjs_shims();
|
|
927
|
-
async function findImplementations(symbol,
|
|
930
|
+
async function findImplementations(symbol, path7, limit = 50, offset = 0) {
|
|
928
931
|
return await wrapAdapterCall(
|
|
929
932
|
"findImplementations",
|
|
930
933
|
symbol,
|
|
931
|
-
|
|
934
|
+
path7,
|
|
932
935
|
limit,
|
|
933
936
|
offset
|
|
934
937
|
);
|
|
@@ -975,8 +978,8 @@ async function getSymbolDocs(symbol, filePath) {
|
|
|
975
978
|
|
|
976
979
|
// src/tools/build-symbol-index.ts
|
|
977
980
|
init_cjs_shims();
|
|
978
|
-
async function buildSymbolIndex(
|
|
979
|
-
return await symbolIndex.buildIndex(
|
|
981
|
+
async function buildSymbolIndex(path7) {
|
|
982
|
+
return await symbolIndex.buildIndex(path7);
|
|
980
983
|
}
|
|
981
984
|
|
|
982
985
|
// src/tools/call-hierarchy.ts
|
|
@@ -1136,6 +1139,117 @@ async function checkSymbolGrounding(symbol, filePath) {
|
|
|
1136
1139
|
};
|
|
1137
1140
|
}
|
|
1138
1141
|
|
|
1142
|
+
// src/tools/codebase-audit.ts
|
|
1143
|
+
init_cjs_shims();
|
|
1144
|
+
var import_child_process2 = require("child_process");
|
|
1145
|
+
var import_util2 = require("util");
|
|
1146
|
+
var import_ripgrep2 = require("@vscode/ripgrep");
|
|
1147
|
+
var fs4 = __toESM(require("fs"), 1);
|
|
1148
|
+
var path6 = __toESM(require("path"), 1);
|
|
1149
|
+
init_security();
|
|
1150
|
+
var execFileAsync2 = (0, import_util2.promisify)(import_child_process2.execFile);
|
|
1151
|
+
async function codebaseAudit(rootDir) {
|
|
1152
|
+
const safePath = validateWorkspacePath(rootDir);
|
|
1153
|
+
let debtMarkers = 0;
|
|
1154
|
+
try {
|
|
1155
|
+
const { stdout } = await execFileAsync2(import_ripgrep2.rgPath, [
|
|
1156
|
+
"--count-matches",
|
|
1157
|
+
"--fixed-strings",
|
|
1158
|
+
"-e",
|
|
1159
|
+
"TODO",
|
|
1160
|
+
"-e",
|
|
1161
|
+
"FIXME",
|
|
1162
|
+
"--glob",
|
|
1163
|
+
"!**/node_modules/**",
|
|
1164
|
+
"--glob",
|
|
1165
|
+
"!**/.git/**",
|
|
1166
|
+
"--glob",
|
|
1167
|
+
"!**/dist/**",
|
|
1168
|
+
safePath
|
|
1169
|
+
]);
|
|
1170
|
+
const lines = stdout.split("\n").filter(Boolean);
|
|
1171
|
+
for (const line of lines) {
|
|
1172
|
+
const match = line.match(/:(\d+)$/);
|
|
1173
|
+
if (match) {
|
|
1174
|
+
debtMarkers += parseInt(match[1], 10);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
if (error.code !== 1) {
|
|
1179
|
+
console.error("[Audit] Error counting debt markers:", error);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
const emptyDirs = [];
|
|
1183
|
+
const scanEmpty = (dir) => {
|
|
1184
|
+
const files = fs4.readdirSync(dir);
|
|
1185
|
+
if (files.length === 0) {
|
|
1186
|
+
emptyDirs.push(path6.relative(safePath, dir));
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
for (const file of files) {
|
|
1190
|
+
const fullPath = path6.join(dir, file);
|
|
1191
|
+
if (fs4.statSync(fullPath).isDirectory()) {
|
|
1192
|
+
if (["node_modules", ".git", "dist", ".sst", ".turbo", ".next"].includes(
|
|
1193
|
+
file
|
|
1194
|
+
))
|
|
1195
|
+
continue;
|
|
1196
|
+
scanEmpty(fullPath);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
scanEmpty(safePath);
|
|
1201
|
+
const orphanedFiles = [];
|
|
1202
|
+
const allFiles = [];
|
|
1203
|
+
const collectFiles = (dir) => {
|
|
1204
|
+
const files = fs4.readdirSync(dir);
|
|
1205
|
+
for (const file of files) {
|
|
1206
|
+
const fullPath = path6.join(dir, file);
|
|
1207
|
+
if (fs4.statSync(fullPath).isDirectory()) {
|
|
1208
|
+
if (["node_modules", ".git", "dist", ".sst", ".turbo", ".next"].includes(
|
|
1209
|
+
file
|
|
1210
|
+
))
|
|
1211
|
+
continue;
|
|
1212
|
+
collectFiles(fullPath);
|
|
1213
|
+
} else if (file.endsWith(".ts") || file.endsWith(".js") || file.endsWith(".tsx") || file.endsWith(".jsx")) {
|
|
1214
|
+
allFiles.push(fullPath);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
collectFiles(safePath);
|
|
1219
|
+
for (const file of allFiles) {
|
|
1220
|
+
const base = path6.basename(file, path6.extname(file));
|
|
1221
|
+
if (base === "index" || base.endsWith(".test") || base.endsWith(".spec") || base === "sst.config")
|
|
1222
|
+
continue;
|
|
1223
|
+
let referenced = false;
|
|
1224
|
+
try {
|
|
1225
|
+
const { status } = await execFileAsync2(import_ripgrep2.rgPath, [
|
|
1226
|
+
"--quiet",
|
|
1227
|
+
"--fixed-strings",
|
|
1228
|
+
"--word-regexp",
|
|
1229
|
+
"--glob",
|
|
1230
|
+
`!${path6.relative(safePath, file)}`,
|
|
1231
|
+
"--glob",
|
|
1232
|
+
"!**/node_modules/**",
|
|
1233
|
+
"--glob",
|
|
1234
|
+
"!**/.git/**",
|
|
1235
|
+
base,
|
|
1236
|
+
safePath
|
|
1237
|
+
]);
|
|
1238
|
+
if (status === 0) referenced = true;
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
if (e.code === 0) referenced = true;
|
|
1241
|
+
}
|
|
1242
|
+
if (!referenced) {
|
|
1243
|
+
orphanedFiles.push(path6.relative(safePath, file));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
debtMarkers,
|
|
1248
|
+
emptyDirs,
|
|
1249
|
+
orphanedFiles
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1139
1253
|
// src/index.ts
|
|
1140
1254
|
var import_types2 = require("@modelcontextprotocol/sdk/types.js");
|
|
1141
1255
|
var ASTExplorerServer = class {
|
|
@@ -1321,6 +1435,20 @@ var ASTExplorerServer = class {
|
|
|
1321
1435
|
},
|
|
1322
1436
|
required: ["symbol", "path"]
|
|
1323
1437
|
}
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
name: "codebase_audit",
|
|
1441
|
+
description: "Performs a codebase-level audit for technical debt (TODOs) and bloat (empty dirs, orphans).",
|
|
1442
|
+
inputSchema: {
|
|
1443
|
+
type: "object",
|
|
1444
|
+
properties: {
|
|
1445
|
+
path: {
|
|
1446
|
+
type: "string",
|
|
1447
|
+
description: "Project root directory to audit"
|
|
1448
|
+
}
|
|
1449
|
+
},
|
|
1450
|
+
required: ["path"]
|
|
1451
|
+
}
|
|
1324
1452
|
}
|
|
1325
1453
|
]
|
|
1326
1454
|
};
|
|
@@ -1330,8 +1458,8 @@ var ASTExplorerServer = class {
|
|
|
1330
1458
|
try {
|
|
1331
1459
|
switch (name) {
|
|
1332
1460
|
case "resolve_definition": {
|
|
1333
|
-
const { symbol, path:
|
|
1334
|
-
const results = await resolveDefinition(symbol,
|
|
1461
|
+
const { symbol, path: path7 } = ResolveDefinitionSchema.parse(args);
|
|
1462
|
+
const results = await resolveDefinition(symbol, path7);
|
|
1335
1463
|
return {
|
|
1336
1464
|
content: [
|
|
1337
1465
|
{ type: "text", text: JSON.stringify(results, null, 2) }
|
|
@@ -1339,8 +1467,8 @@ var ASTExplorerServer = class {
|
|
|
1339
1467
|
};
|
|
1340
1468
|
}
|
|
1341
1469
|
case "find_references": {
|
|
1342
|
-
const { symbol, path:
|
|
1343
|
-
const results = await findReferences(symbol,
|
|
1470
|
+
const { symbol, path: path7, limit, offset } = FindReferencesSchema.parse(args);
|
|
1471
|
+
const results = await findReferences(symbol, path7, limit, offset);
|
|
1344
1472
|
return {
|
|
1345
1473
|
content: [
|
|
1346
1474
|
{ type: "text", text: JSON.stringify(results, null, 2) }
|
|
@@ -1348,10 +1476,10 @@ var ASTExplorerServer = class {
|
|
|
1348
1476
|
};
|
|
1349
1477
|
}
|
|
1350
1478
|
case "find_implementations": {
|
|
1351
|
-
const { symbol, path:
|
|
1479
|
+
const { symbol, path: path7, limit, offset } = FindImplementationsSchema.parse(args);
|
|
1352
1480
|
const results = await findImplementations(
|
|
1353
1481
|
symbol,
|
|
1354
|
-
|
|
1482
|
+
path7,
|
|
1355
1483
|
limit,
|
|
1356
1484
|
offset
|
|
1357
1485
|
);
|
|
@@ -1371,10 +1499,10 @@ var ASTExplorerServer = class {
|
|
|
1371
1499
|
};
|
|
1372
1500
|
}
|
|
1373
1501
|
case "search_code": {
|
|
1374
|
-
const { pattern, path:
|
|
1502
|
+
const { pattern, path: path7, filePattern, limit, offset, regex } = SearchCodeSchema.parse(args);
|
|
1375
1503
|
const results = await searchCode(
|
|
1376
1504
|
pattern,
|
|
1377
|
-
|
|
1505
|
+
path7,
|
|
1378
1506
|
filePattern,
|
|
1379
1507
|
limit,
|
|
1380
1508
|
regex,
|
|
@@ -1387,22 +1515,22 @@ var ASTExplorerServer = class {
|
|
|
1387
1515
|
};
|
|
1388
1516
|
}
|
|
1389
1517
|
case "get_symbol_docs": {
|
|
1390
|
-
const { symbol, path:
|
|
1391
|
-
const docs = await getSymbolDocs(symbol,
|
|
1518
|
+
const { symbol, path: path7 } = GetSymbolDocsSchema.parse(args);
|
|
1519
|
+
const docs = await getSymbolDocs(symbol, path7);
|
|
1392
1520
|
return {
|
|
1393
1521
|
content: [{ type: "text", text: JSON.stringify(docs, null, 2) }]
|
|
1394
1522
|
};
|
|
1395
1523
|
}
|
|
1396
1524
|
case "build_symbol_index": {
|
|
1397
|
-
const { path:
|
|
1398
|
-
const stats = await buildSymbolIndex(
|
|
1525
|
+
const { path: path7 } = BuildSymbolIndexSchema.parse(args);
|
|
1526
|
+
const stats = await buildSymbolIndex(path7);
|
|
1399
1527
|
return {
|
|
1400
1528
|
content: [{ type: "text", text: JSON.stringify(stats, null, 2) }]
|
|
1401
1529
|
};
|
|
1402
1530
|
}
|
|
1403
1531
|
case "get_call_hierarchy": {
|
|
1404
|
-
const { symbol, path:
|
|
1405
|
-
const hierarchy = await getCallHierarchy(symbol,
|
|
1532
|
+
const { symbol, path: path7, direction } = GetCallHierarchySchema.parse(args);
|
|
1533
|
+
const hierarchy = await getCallHierarchy(symbol, path7, direction);
|
|
1406
1534
|
return {
|
|
1407
1535
|
content: [
|
|
1408
1536
|
{ type: "text", text: JSON.stringify(hierarchy, null, 2) }
|
|
@@ -1410,8 +1538,17 @@ var ASTExplorerServer = class {
|
|
|
1410
1538
|
};
|
|
1411
1539
|
}
|
|
1412
1540
|
case "check_symbol_grounding": {
|
|
1413
|
-
const { symbol, path:
|
|
1414
|
-
const result = await checkSymbolGrounding(symbol,
|
|
1541
|
+
const { symbol, path: path7 } = CheckSymbolGroundingSchema.parse(args);
|
|
1542
|
+
const result = await checkSymbolGrounding(symbol, path7);
|
|
1543
|
+
return {
|
|
1544
|
+
content: [
|
|
1545
|
+
{ type: "text", text: JSON.stringify(result, null, 2) }
|
|
1546
|
+
]
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
case "codebase_audit": {
|
|
1550
|
+
const { path: path7 } = CodebaseAuditSchema.parse(args);
|
|
1551
|
+
const result = await codebaseAudit(path7);
|
|
1415
1552
|
return {
|
|
1416
1553
|
content: [
|
|
1417
1554
|
{ type: "text", text: JSON.stringify(result, null, 2) }
|