@angular-modernizer/adapter-mcp 1.0.0 → 1.2.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.
Files changed (131) hide show
  1. package/README.md +81 -65
  2. package/dist/cli.js +8 -0
  3. package/dist/core/project-analyzer.d.ts +3 -12
  4. package/dist/core/project-analyzer.js +3 -12
  5. package/dist/index.d.ts +118 -3
  6. package/dist/index.js +46 -3
  7. package/dist/mcp-watcher.d.ts +28 -8
  8. package/dist/mcp-watcher.js +7 -7
  9. package/dist/scan-host/scan-host.d.ts +119 -0
  10. package/dist/scan-host/scan-host.js +376 -0
  11. package/dist/scan-host/scan-protocol.d.ts +35 -0
  12. package/dist/scan-host/scan-protocol.js +6 -0
  13. package/dist/scan-host/scan-worker.d.ts +14 -0
  14. package/dist/scan-host/scan-worker.js +48 -0
  15. package/dist/server/limited-stdio-transport.d.ts +7 -0
  16. package/dist/server/mcp-server.d.ts +11 -7
  17. package/dist/server/mcp-server.js +4 -7
  18. package/dist/server/sdk-server.d.ts +1 -0
  19. package/dist/server/tool-registry.d.ts +3 -7
  20. package/dist/server/tool-registry.js +1 -7
  21. package/dist/streaming/progress-store.d.ts +22 -5
  22. package/dist/streaming/progress-store.js +9 -5
  23. package/dist/tools/analyze-build-impact.d.ts +58 -36
  24. package/dist/tools/analyze-build-impact.js +36 -29
  25. package/dist/tools/analyze-core-to-shared.d.ts +42 -12
  26. package/dist/tools/analyze-core-to-shared.js +11 -10
  27. package/dist/tools/analyze-parser-performance.d.ts +23 -22
  28. package/dist/tools/analyze-parser-performance.js +20 -18
  29. package/dist/tools/analyze-project.d.ts +87 -14
  30. package/dist/tools/analyze-project.js +140 -122
  31. package/dist/tools/check-incremental-compatibility.d.ts +13 -11
  32. package/dist/tools/check-incremental-compatibility.js +11 -8
  33. package/dist/tools/collect-feedback.d.ts +41 -26
  34. package/dist/tools/collect-feedback.js +32 -23
  35. package/dist/tools/compare-health.d.ts +76 -19
  36. package/dist/tools/compare-health.js +26 -19
  37. package/dist/tools/extract-libraries.d.ts +44 -20
  38. package/dist/tools/extract-libraries.js +16 -17
  39. package/dist/tools/find-angular-symbol.d.ts +27 -25
  40. package/dist/tools/find-angular-symbol.js +19 -16
  41. package/dist/tools/find-component-hosts.d.ts +33 -27
  42. package/dist/tools/find-component-hosts.js +27 -24
  43. package/dist/tools/find-usages.d.ts +25 -23
  44. package/dist/tools/find-usages.js +21 -18
  45. package/dist/tools/get-bootstrap-execution.d.ts +35 -27
  46. package/dist/tools/get-bootstrap-execution.js +28 -25
  47. package/dist/tools/get-call-graph.d.ts +19 -14
  48. package/dist/tools/get-call-graph.js +26 -23
  49. package/dist/tools/get-operation-progress-tool.d.ts +12 -6
  50. package/dist/tools/get-operation-progress-tool.js +11 -6
  51. package/dist/tools/get-operation-progress.d.ts +26 -0
  52. package/dist/tools/helpers/analysis-output.d.ts +5 -0
  53. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  54. package/dist/tools/helpers/batch-kernel.js +12 -0
  55. package/dist/tools/helpers/compact-output.d.ts +2 -1
  56. package/dist/tools/helpers/compact-output.js +2 -1
  57. package/dist/tools/helpers/health-delta.d.ts +27 -14
  58. package/dist/tools/helpers/health-delta.js +11 -14
  59. package/dist/tools/helpers/project-cache.d.ts +123 -36
  60. package/dist/tools/helpers/project-cache.js +227 -43
  61. package/dist/tools/helpers/rule-runner.d.ts +23 -16
  62. package/dist/tools/helpers/rule-runner.js +24 -17
  63. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  64. package/dist/tools/helpers/scan-engine.js +197 -0
  65. package/dist/tools/helpers/scan-plan.d.ts +1 -1
  66. package/dist/tools/helpers/scan-plan.js +1 -1
  67. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  68. package/dist/tools/helpers/suggestion-generator.js +0 -12
  69. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  70. package/dist/tools/helpers/tool-cache.js +15 -0
  71. package/dist/tools/helpers/tool-context.d.ts +11 -8
  72. package/dist/tools/helpers/tool-context.js +5 -8
  73. package/dist/tools/inspect-form-group.d.ts +34 -27
  74. package/dist/tools/inspect-form-group.js +27 -24
  75. package/dist/tools/inspect-i18n.d.ts +31 -25
  76. package/dist/tools/inspect-i18n.js +23 -20
  77. package/dist/tools/inspect-template.d.ts +32 -25
  78. package/dist/tools/inspect-template.js +26 -23
  79. package/dist/tools/learn-patterns.d.ts +88 -12
  80. package/dist/tools/learn-patterns.js +17 -11
  81. package/dist/tools/list-imports.d.ts +45 -28
  82. package/dist/tools/list-imports.js +26 -23
  83. package/dist/tools/orchestrate-migration.d.ts +31 -9
  84. package/dist/tools/orchestrate-migration.js +12 -7
  85. package/dist/tools/parse-stack-trace.d.ts +23 -21
  86. package/dist/tools/parse-stack-trace.js +10 -7
  87. package/dist/tools/plan-migration.d.ts +67 -27
  88. package/dist/tools/plan-migration.js +22 -21
  89. package/dist/tools/resolve-type.d.ts +20 -10
  90. package/dist/tools/resolve-type.js +21 -13
  91. package/dist/tools/review-feedback.d.ts +27 -24
  92. package/dist/tools/review-feedback.js +24 -20
  93. package/dist/tools/rollback-changes.d.ts +13 -9
  94. package/dist/tools/rollback-changes.js +10 -7
  95. package/dist/tools/run-angular-cli.d.ts +12 -10
  96. package/dist/tools/run-angular-cli.js +11 -8
  97. package/dist/tools/run-build.d.ts +13 -11
  98. package/dist/tools/run-build.js +11 -8
  99. package/dist/tools/run-schematic.d.ts +12 -10
  100. package/dist/tools/run-schematic.js +11 -8
  101. package/dist/tools/scan-all.d.ts +69 -12
  102. package/dist/tools/scan-all.js +55 -122
  103. package/dist/tools/scan-angular.d.ts +41 -9
  104. package/dist/tools/scan-angular.js +66 -135
  105. package/dist/tools/scan-architecture.d.ts +75 -14
  106. package/dist/tools/scan-architecture.js +180 -185
  107. package/dist/tools/scan-solid.d.ts +40 -9
  108. package/dist/tools/scan-solid.js +64 -133
  109. package/dist/tools/search-codebase.d.ts +32 -26
  110. package/dist/tools/search-codebase.js +15 -12
  111. package/dist/tools/server-status.d.ts +116 -24
  112. package/dist/tools/server-status.js +85 -26
  113. package/dist/tools/suggest-improvements.d.ts +22 -19
  114. package/dist/tools/suggest-improvements.js +21 -17
  115. package/dist/tools/trace-output-flow.d.ts +34 -27
  116. package/dist/tools/trace-output-flow.js +27 -24
  117. package/dist/tools/transform-code.d.ts +71 -10
  118. package/dist/tools/transform-code.js +148 -54
  119. package/dist/tools/validate-before-transform.d.ts +24 -9
  120. package/dist/tools/validate-before-transform.js +10 -7
  121. package/dist/tools/validate-project-compatibility.d.ts +18 -13
  122. package/dist/tools/validate-project-compatibility.js +17 -11
  123. package/dist/tools/validate-transformation.d.ts +28 -11
  124. package/dist/tools/validate-transformation.js +14 -8
  125. package/dist/tools/verify-citations.d.ts +37 -16
  126. package/dist/tools/verify-citations.js +19 -16
  127. package/dist/types.d.ts +40 -10
  128. package/dist/types.js +0 -5
  129. package/package.json +12 -18
  130. package/dist/tools/shared/scan-types.d.ts +0 -200
  131. package/dist/tools/shared/scan-types.js +0 -7
@@ -1,22 +1,14 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Scan SOLID Principles Tool
3
- *
4
- * MCP tool for scanning Angular codebases for SOLID principle violations.
5
- * Runs only the SolidPlugin (7 rules: DIP, SRP, LSP, OCP, ISP).
6
- */
7
1
  import { findTsConfig } from './helpers/find-ts-config.js';
8
- import { Kernel, createToolCacheConfig, loadConfig, } from '@angular-modernizer/core';
9
- import { SolidPlugin } from '@angular-modernizer/plugin-solid';
10
- import { ContextFactory } from '@angular-modernizer/plugin-system';
11
- import { createPublicApi } from '@angular-modernizer/api';
12
2
  import { glob } from 'glob';
13
3
  import { resolve, relative } from 'node:path';
14
4
  import { readFileSync, existsSync } from 'node:fs';
15
5
  import { describeScan, SCAN_EXECUTION_SCHEMA, scanOutputSchema, } from './helpers/analysis-output.js';
16
- import { cancelledExecution, fileProgressMessage, yieldIfCancellable, } from './helpers/tool-context.js';
17
- import { loadSourceFiles } from './helpers/load-source-files.js';
6
+ import { cancelledExecution, fileProgressMessage, } from './helpers/tool-context.js';
7
+ import { runScan } from '../scan-host/scan-host.js';
8
+ import { openToolCache } from './helpers/tool-cache.js';
18
9
  /**
19
- * Scan for SOLID principle violations using the SolidPlugin.
10
+ * MCP tool `scan-solid`: scans for SOLID principle violations. Runs only the
11
+ * SolidPlugin (7 rules: DIP, SRP, LSP, OCP, ISP).
20
12
  */
21
13
  export class ScanSolidTool {
22
14
  name = 'scan-solid';
@@ -29,6 +21,10 @@ export class ScanSolidTool {
29
21
  };
30
22
  description = 'Scan for SOLID principle violations (DIP, SRP, LSP, OCP, ISP). maxResults (default 1000) and resultOffset ' +
31
23
  'page the violations; counts cover all of them, summary is a short text.';
24
+ /**
25
+ * JSON Schema of the tool arguments.
26
+ * @hidden
27
+ */
32
28
  inputSchema = {
33
29
  type: 'object',
34
30
  additionalProperties: false,
@@ -101,6 +97,10 @@ export class ScanSolidTool {
101
97
  },
102
98
  required: ['rootPath'],
103
99
  };
100
+ /**
101
+ * JSON Schema of the tool result (`structuredContent`).
102
+ * @hidden
103
+ */
104
104
  outputSchema = scanOutputSchema({ execution: SCAN_EXECUTION_SCHEMA });
105
105
  async execute(args, ctx = {}) {
106
106
  const params = args;
@@ -115,16 +115,6 @@ export class ScanSolidTool {
115
115
  if (!tsConfigPath) {
116
116
  throw new Error('Could not find tsconfig.json');
117
117
  }
118
- // Initialize kernel with SolidPlugin and caching
119
- const kernel = new Kernel({
120
- tsConfigPath,
121
- plugins: [new SolidPlugin()],
122
- fileSystem: undefined,
123
- projectOptions: {
124
- skipAddingFilesFromTsConfig: true, // We'll add filtered files manually
125
- },
126
- cacheConfig: createToolCacheConfig(mergedParams.rootPath, 'solid'),
127
- });
128
118
  // Find files to analyze
129
119
  const includePatterns = mergedParams.includePatterns ?? ['**/*.{ts,tsx}'];
130
120
  const excludePatterns = mergedParams.excludePatterns ?? [
@@ -150,16 +140,7 @@ export class ScanSolidTool {
150
140
  const uniqueFiles = Array.from(new Set(allFiles)).sort();
151
141
  const filesToAnalyze = uniqueFiles; // Analyze ALL files found (batch processing prevents memory issues)
152
142
  const maxFiles = mergedParams.maxFiles ?? 100; // Batch size (default 100)
153
- // Initialize kernel
154
- await kernel.initialize();
155
- // Load rules config from .angular-modernizer.json for per-rule overrides (BUG-3)
156
- const fullConfig = loadConfig(mergedParams.rootPath);
157
- const rulesConfig = fullConfig.rules;
158
- // Get analysis rules from the already-initialized plugin instances so that
159
- // ruleConfigs from .angular-modernizer.json are applied correctly.
160
- const allRules = kernel
161
- .getAllPlugins()
162
- .flatMap((p) => p.getAnalysisRules());
143
+ const cache = await openToolCache(mergedParams.rootPath, 'solid');
163
144
  // ============================================================================
164
145
  // CACHE READ SYSTEM
165
146
  // ============================================================================
@@ -179,27 +160,20 @@ export class ScanSolidTool {
179
160
  // Cache directory: .angular-modernizer-cache/solid/
180
161
  // Cache invalidation: Automatic via mtime/content hash checking
181
162
  // ============================================================================
182
- const cacheManagerForRead = kernel.getCacheManager();
183
163
  const cachedResults = []; // eslint-disable-line @typescript-eslint/no-explicit-any
184
- let filesToProcess = [];
185
- if (cacheManagerForRead) {
186
- for (const filePath of filesToAnalyze) {
187
- const cached = await cacheManagerForRead.getAnalysisResult(filePath);
188
- if (cached?.results && cached.results.length > 0) {
189
- cachedResults.push(...cached.results);
190
- }
191
- else {
192
- // File not cached or has changed
193
- filesToProcess.push(filePath);
194
- }
164
+ const filesToProcess = [];
165
+ for (const filePath of filesToAnalyze) {
166
+ const cached = await cache.getAnalysisResult(filePath);
167
+ if (cached?.results && cached.results.length > 0) {
168
+ // File is cached and hasn't changed
169
+ cachedResults.push(...cached.results);
170
+ }
171
+ else {
172
+ // File not cached or has changed
173
+ filesToProcess.push(filePath);
195
174
  }
196
- const stats = cacheManagerForRead.getStats();
197
- console.info(`Cache: ${cachedResults.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${stats.hitRate.toFixed(1)}%)`);
198
- }
199
- else {
200
- // No cache manager, analyze all files
201
- filesToProcess = filesToAnalyze;
202
175
  }
176
+ console.info(`Cache: ${cachedResults.length} results from cache, ${filesToProcess.length} files to analyze (hit rate: ${cache.getStats().hitRate.toFixed(1)}%)`);
203
177
  // ============================================================================
204
178
  // BATCH PROCESSING SYSTEM
205
179
  // ============================================================================
@@ -234,73 +208,33 @@ export class ScanSolidTool {
234
208
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
235
209
  const results = [...cachedResults];
236
210
  let filesAnalyzed = cachedResults.length;
237
- // Process each batch; cancellation is checked between files
211
+ // Kernel, batches and rules run in a scan worker (scan-host), so the
212
+ // server keeps reading stdin while the type checker is built.
238
213
  const cachedFiles = filesToAnalyze.length - totalFiles;
239
214
  let processedFiles = 0;
240
- let cancelled = false;
241
- for (let batchNum = 0; batchNum < totalBatches && !cancelled; batchNum++) {
242
- const batchStart = batchNum * batchSize;
243
- const batchEnd = Math.min(batchStart + batchSize, totalFiles);
244
- const batchFiles = filesToProcess.slice(batchStart, batchEnd);
245
- console.info(`\nBatch ${batchNum + 1}/${totalBatches}: Processing files ${batchStart + 1}-${batchEnd} (${batchFiles.length} files)`);
246
- // Clear project and add batch files
247
- const project = kernel.getProject();
248
- // Remove all source files from previous batch
249
- const existingFiles = project.getSourceFiles();
250
- for (const file of existingFiles) {
251
- project.removeSourceFile(file);
252
- }
253
- // Add current batch files; a cancel during the load stops the scan
254
- const loaded = await loadSourceFiles(project, batchFiles, { signal: ctx.signal });
255
- if (loaded.cancelled) {
256
- cancelled = true;
257
- break;
258
- }
259
- console.info(`Batch ${batchNum + 1}: Project now has ${project.getSourceFiles().length} source files`);
260
- // Create PublicApi for this batch
261
- const api = createPublicApi(project); // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
262
- // Analyze files in this batch
263
- let batchViolationCount = 0;
264
- for (const sourceFile of project.getSourceFiles()) {
265
- await yieldIfCancellable(ctx.signal);
266
- if (ctx.signal?.aborted === true) {
267
- cancelled = true;
268
- break;
269
- }
270
- for (const rule of allRules) {
271
- try {
272
- const ruleResults = await rule.analyze(ContextFactory.createAnalysisContext({
273
- sourceFile,
274
- project,
275
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
276
- api,
277
- config: rulesConfig,
278
- }));
279
- for (const result of ruleResults) {
280
- results.push({
281
- ruleId: result.ruleId,
282
- severity: result.severity ?? rule.severity,
283
- message: result.message,
284
- filePath: result.filePath,
285
- line: result.line,
286
- column: result.column,
287
- category: rule.category,
288
- suggestedFix: result.suggestedFix,
289
- metadata: result.metadata,
290
- });
291
- batchViolationCount++;
292
- }
293
- }
294
- catch (error) {
295
- console.warn(`Failed to analyze with rule ${rule.id}:`, error);
296
- }
297
- }
215
+ if (totalFiles > 0) {
216
+ ctx.progress?.(cachedFiles, filesToAnalyze.length, `loading project, ${totalFiles} files to analyze`);
217
+ }
218
+ const engine = await runScan({
219
+ tool: this.name,
220
+ plugins: 'solid',
221
+ tsConfigPath,
222
+ rootPath: mergedParams.rootPath,
223
+ files: filesToProcess,
224
+ mode: 'batches',
225
+ batchSize,
226
+ analyzeProjectFiles: true,
227
+ }, {
228
+ file: (event) => {
229
+ results.push(...event.findings);
298
230
  processedFiles++;
299
231
  ctx.progress?.(cachedFiles + processedFiles, filesToAnalyze.length, fileProgressMessage(cachedFiles + processedFiles, filesToAnalyze.length, results.length));
300
- }
301
- filesAnalyzed += batchFiles.length;
302
- console.info(`Batch ${batchNum + 1}: Found ${batchViolationCount} violations in ${batchFiles.length} files`);
303
- }
232
+ },
233
+ batchDone: (files) => {
234
+ filesAnalyzed += files;
235
+ },
236
+ }, { signal: ctx.signal });
237
+ const cancelled = engine.cancelled;
304
238
  console.info(`\nBatch processing complete: ${totalBatches} batch(es), ${filesAnalyzed} total files analyzed, ${results.length} total violations`);
305
239
  // ============================================================================
306
240
  // CACHE WRITE SYSTEM
@@ -330,26 +264,23 @@ export class ScanSolidTool {
330
264
  // - First run: Writes cache (adds ~1-2% overhead)
331
265
  // - Second run: Reads cache (1.5x-39x speedup depending on scan type)
332
266
  // ============================================================================
333
- const cacheManager = kernel.getCacheManager();
334
- if (cacheManager) {
335
- // Group results by file path
336
- const resultsByFile = new Map();
337
- for (const result of results) {
338
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
339
- const filePath = result.filePath;
340
- if (!resultsByFile.has(filePath)) {
341
- resultsByFile.set(filePath, []);
342
- }
343
- resultsByFile.get(filePath).push(result);
344
- }
345
- // Write each file's results to cache
346
- for (const [filePath, fileResults] of resultsByFile.entries()) {
347
- await cacheManager.setAnalysisResult(filePath, fileResults);
267
+ // Group results by file path
268
+ const resultsByFile = new Map();
269
+ for (const result of results) {
270
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
271
+ const filePath = result.filePath;
272
+ if (!resultsByFile.has(filePath)) {
273
+ resultsByFile.set(filePath, []);
348
274
  }
349
- // Log cache effectiveness
350
- const stats = cacheManager.getStats();
351
- console.info(`Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
275
+ resultsByFile.get(filePath).push(result);
276
+ }
277
+ // Write each file's results to cache
278
+ for (const [filePath, fileResults] of resultsByFile.entries()) {
279
+ await cache.setAnalysisResult(filePath, fileResults);
352
280
  }
281
+ // Log cache effectiveness
282
+ const stats = cache.getStats();
283
+ console.info(`Cached ${resultsByFile.size} files (hit rate: ${stats.hitRate.toFixed(1)}%)`);
353
284
  // Filter by specific rules if requested
354
285
  let violations = results
355
286
  .filter((r) => r.ruleId && r.filePath)
@@ -388,7 +319,7 @@ export class ScanSolidTool {
388
319
  hasMore: offset + maxResults < totalViolations,
389
320
  };
390
321
  const duration = Date.now() - startTime;
391
- const ruleIds = allRules.map((r) => r.id);
322
+ const ruleIds = engine.ruleIds;
392
323
  return {
393
324
  violations: paginatedViolations,
394
325
  counts,
@@ -1,36 +1,19 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Search Codebase Tool
3
- *
4
- * MCP tool for searching across all TypeScript source files in a project.
5
- * Supports three modes: literal text, regular expression, and TypeScript
6
- * named-declaration (symbol) lookup.
7
- *
8
- * @remarks
9
- * Use during bug investigation to locate where a string constant is defined,
10
- * find every file that references a specific error message, or locate the
11
- * declaration of an unknown symbol encountered in a stack trace.
12
- *
13
- * @example
14
- * ```typescript
15
- * // Via MCP:
16
- * // tool: search-codebase
17
- * // args: { query: 'TODO', mode: 'text', projectRoot: '/project' }
18
- * // args: { query: 'UserService', mode: 'symbol', projectRoot: '/project' }
19
- * // args: { query: 'selector:\\s*["\']app-[^"\']+', mode: 'pattern', projectRoot: '/project' }
20
- * ```
21
- */
22
- import { type MCPTool, type ToolAnnotations } from '../types.js';
1
+ import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
23
2
  import { type SearchCoverage, type SearchResult } from '@angular-modernizer/api';
24
3
  import { ProjectCache } from './helpers/project-cache.js';
25
4
  /**
26
5
  * Output of the search-codebase tool.
27
6
  */
28
- interface SearchCodebaseOutput {
7
+ export interface SearchCodebaseOutput {
8
+ /** Matches, at most `maxResults` (default 100). */
29
9
  results: SearchResult[];
10
+ /** Number of returned matches. */
30
11
  totalCount: number;
12
+ /** Short text summary of the matches. */
31
13
  summary: string;
32
14
  /** Which files the search covered, including the tsconfig used. */
33
15
  coverage: SearchCoverage & {
16
+ /** The tsconfig whose program was searched. */
34
17
  tsConfigPath: string;
35
18
  /** Present when 0 hits were found: why that does not prove absence. */
36
19
  hint?: string;
@@ -39,7 +22,23 @@ interface SearchCodebaseOutput {
39
22
  warnings?: string[];
40
23
  }
41
24
  /**
42
- * MCP tool that searches TypeScript source files by text, regex, or symbol.
25
+ * MCP tool for searching across all TypeScript source files in a project.
26
+ * Supports three modes: literal text, regular expression, and TypeScript
27
+ * named-declaration (symbol) lookup.
28
+ *
29
+ * @remarks
30
+ * Use during bug investigation to locate where a string constant is defined,
31
+ * find every file that references a specific error message, or locate the
32
+ * declaration of an unknown symbol encountered in a stack trace.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Via MCP:
37
+ * // tool: search-codebase
38
+ * // args: { query: 'TODO', mode: 'text', projectRoot: '/project' }
39
+ * // args: { query: 'UserService', mode: 'symbol', projectRoot: '/project' }
40
+ * // args: { query: 'selector:\\s*["\']app-[^"\']+', mode: 'pattern', projectRoot: '/project' }
41
+ * ```
43
42
  */
44
43
  export declare class SearchCodebaseTool implements MCPTool {
45
44
  private readonly projects;
@@ -48,6 +47,10 @@ export declare class SearchCodebaseTool implements MCPTool {
48
47
  readonly annotations: ToolAnnotations;
49
48
  constructor(projects?: ProjectCache);
50
49
  readonly description: string;
50
+ /**
51
+ * JSON Schema of the tool arguments.
52
+ * @hidden
53
+ */
51
54
  readonly inputSchema: {
52
55
  type: string;
53
56
  additionalProperties: boolean;
@@ -84,6 +87,10 @@ export declare class SearchCodebaseTool implements MCPTool {
84
87
  };
85
88
  required: string[];
86
89
  };
90
+ /**
91
+ * JSON Schema of the tool result (`structuredContent`).
92
+ * @hidden
93
+ */
87
94
  readonly outputSchema: {
88
95
  type: string;
89
96
  properties: {
@@ -160,12 +167,11 @@ export declare class SearchCodebaseTool implements MCPTool {
160
167
  };
161
168
  required: string[];
162
169
  };
163
- execute(args: Record<string, unknown>): Promise<SearchCodebaseOutput>;
170
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<SearchCodebaseOutput>;
164
171
  /**
165
172
  * Explains why 0 hits is not proof of absence, naming what was excluded.
166
173
  */
167
174
  private buildZeroHitHint;
168
175
  private buildSummary;
169
176
  }
170
- export {};
171
177
  //# sourceMappingURL=search-codebase.d.ts.map
@@ -1,6 +1,9 @@
1
+ import { CodebaseSearcher, } from '@angular-modernizer/api';
2
+ import { existsSync } from 'node:fs';
3
+ import { findTsConfig } from './helpers/find-ts-config.js';
4
+ import { ProjectCache, acquireProject } from './helpers/project-cache.js';
5
+ import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
1
6
  /**
2
- * @angular-modernizer/adapter-mcp - Search Codebase Tool
3
- *
4
7
  * MCP tool for searching across all TypeScript source files in a project.
5
8
  * Supports three modes: literal text, regular expression, and TypeScript
6
9
  * named-declaration (symbol) lookup.
@@ -19,14 +22,6 @@
19
22
  * // args: { query: 'selector:\\s*["\']app-[^"\']+', mode: 'pattern', projectRoot: '/project' }
20
23
  * ```
21
24
  */
22
- import { CodebaseSearcher, } from '@angular-modernizer/api';
23
- import { existsSync } from 'node:fs';
24
- import { findTsConfig } from './helpers/find-ts-config.js';
25
- import { ProjectCache } from './helpers/project-cache.js';
26
- import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
27
- /**
28
- * MCP tool that searches TypeScript source files by text, regex, or symbol.
29
- */
30
25
  export class SearchCodebaseTool {
31
26
  projects;
32
27
  name = 'search-codebase';
@@ -50,6 +45,10 @@ export class SearchCodebaseTool {
50
45
  'object (programFileCount, extraFileCount); 0 hits only prove absence within the ' +
51
46
  'covered files. Use during bug investigation to locate error strings, find symbol ' +
52
47
  'declarations, or discover all files that reference a specific pattern.';
48
+ /**
49
+ * JSON Schema of the tool arguments.
50
+ * @hidden
51
+ */
53
52
  inputSchema = {
54
53
  type: 'object',
55
54
  additionalProperties: false,
@@ -89,6 +88,10 @@ export class SearchCodebaseTool {
89
88
  },
90
89
  required: ['query', 'mode', 'projectRoot'],
91
90
  };
91
+ /**
92
+ * JSON Schema of the tool result (`structuredContent`).
93
+ * @hidden
94
+ */
92
95
  outputSchema = {
93
96
  type: 'object',
94
97
  properties: {
@@ -133,7 +136,7 @@ export class SearchCodebaseTool {
133
136
  },
134
137
  required: ['results', 'totalCount', 'summary', 'coverage'],
135
138
  };
136
- async execute(args) {
139
+ async execute(args, ctx = {}) {
137
140
  const params = args;
138
141
  if (!params.query) {
139
142
  throw new Error('query is required');
@@ -151,7 +154,7 @@ export class SearchCodebaseTool {
151
154
  if (!tsConfigPath) {
152
155
  throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
153
156
  }
154
- const project = this.projects.get(tsConfigPath);
157
+ const project = await acquireProject(this.projects, tsConfigPath, ctx);
155
158
  const searcher = new CodebaseSearcher(project);
156
159
  const { results, coverage } = searcher.searchWithCoverage(params.query, {
157
160
  mode: params.mode,
@@ -1,95 +1,132 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Server Status Tool
3
- *
4
- * MCP tool that reports on the running server itself: memory, uptime, the
5
- * negotiated protocol era and revision, the ts-morph projects held in the
6
- * shared cache, response sizes, and whether the build on disk changed after
7
- * the server started.
8
- *
9
- * @remarks
10
- * A session keeps the code it started with; after `pnpm run build` it serves
11
- * stale tools until the client reconnects. `build.rebuiltSinceStart` makes
12
- * that visible from inside the session. The check compares the newest `.js`
13
- * mtime per package `dist/` at start and at call time; it walks the
14
- * directories on every call (a few hundred files, milliseconds).
15
- *
16
- * @example
17
- * ```typescript
18
- * // Via MCP:
19
- * // tool: server-status
20
- * // args: {}
21
- * ```
22
- */
23
1
  import { type MCPTool, type ToolAnnotations } from '../types.js';
24
2
  import { type ServerRuntimeStats } from '../server/mcp-server.js';
3
+ import { type ScanHostStatus } from '../scan-host/scan-host.js';
25
4
  import { type CachedProjectInfo, type EvictionStats, type ProjectCache } from './helpers/project-cache.js';
26
5
  /** A package `dist/` directory to watch for rebuilds. */
27
6
  export interface DistDirectory {
7
+ /** Package folder name, e.g. `core`. */
28
8
  name: string;
9
+ /** Absolute path of the package's `dist/` directory. */
29
10
  dir: string;
30
11
  }
31
12
  /** Build state of one package. */
32
13
  export interface DistPackageState {
14
+ /** Package folder name. */
33
15
  name: string;
16
+ /** Absolute path of the package's `dist/` directory. */
34
17
  dir: string;
35
18
  /** Newest `.js` mtime when the server started. */
36
19
  builtAtStart?: string;
37
20
  /** Newest `.js` mtime now. */
38
21
  builtNow?: string;
22
+ /** The newest `.js` mtime changed since the server started. */
39
23
  rebuilt: boolean;
40
24
  }
41
25
  /** Output of the server-status tool. */
42
26
  export interface ServerStatusOutput {
27
+ /** The server process. */
43
28
  process: {
29
+ /** Process id. */
44
30
  pid: number;
31
+ /** Parent process id. */
45
32
  ppid: number;
33
+ /** Node.js version. */
46
34
  nodeVersion: string;
35
+ /** `process.platform`. */
47
36
  platform: string;
37
+ /** Working directory of the server. */
48
38
  cwd: string;
39
+ /** Uptime in seconds, rounded. */
49
40
  uptimeSec: number;
41
+ /** Memory usage in MB. */
50
42
  memoryMB: {
43
+ /** Resident set size. */
51
44
  rss: number;
45
+ /** V8 heap in use. */
52
46
  heapUsed: number;
47
+ /** V8 heap allocated. */
53
48
  heapTotal: number;
49
+ /** Memory of C++ objects bound to JavaScript objects. */
54
50
  external: number;
55
51
  /** V8 heap limit; the process aborts when the heap reaches it. */
56
52
  heapLimit: number;
57
53
  };
58
54
  };
55
+ /** Server runtime figures and version. */
59
56
  server: ServerRuntimeStats & {
60
57
  /** Version of @angular-modernizer/adapter-mcp, as sent in serverInfo. */
61
58
  version: string;
62
59
  };
60
+ /** The shared ts-morph project cache. */
63
61
  projects: {
62
+ /** Number of cached projects. */
64
63
  cached: number;
64
+ /** Maximum number of cached projects. */
65
65
  capacity: number;
66
66
  /** Heap limit checked after each project load; 0 means off. */
67
67
  maxHeapMB: number;
68
+ /** One entry per cached project. */
68
69
  entries: CachedProjectInfo[];
70
+ /** Evictions since the server started. */
69
71
  evictions: EvictionStats;
70
72
  };
73
+ /** Scan workers: scans analyze in a worker thread unless switched off. */
74
+ scanWorkers: ScanHostStatus;
75
+ /** Build state of the package `dist/` directories. */
71
76
  build: {
77
+ /**
78
+ * A package was rebuilt after the server started; the session runs old
79
+ * code and must reconnect.
80
+ */
72
81
  rebuiltSinceStart: boolean;
82
+ /** State per watched package. */
73
83
  packages: DistPackageState[];
74
84
  };
85
+ /** Short text of the status. */
75
86
  summary: string;
76
87
  }
77
88
  /**
78
- * MCP tool that reports server process, cache and build state.
89
+ * MCP tool that reports on the running server itself: memory, uptime, the
90
+ * negotiated protocol era and revision, the ts-morph projects held in the
91
+ * shared cache, response sizes, and whether the build on disk changed after
92
+ * the server started.
93
+ *
94
+ * @remarks
95
+ * A session keeps the code it started with; after a rebuild it serves stale
96
+ * tools until the client reconnects. `build.rebuiltSinceStart` makes that
97
+ * visible from inside the session. The check compares the newest `.js` mtime
98
+ * per package `dist/` at start and at call time; it walks the directories on
99
+ * every call (a few hundred files, milliseconds).
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Via MCP:
104
+ * // tool: server-status
105
+ * // args: {}
106
+ * ```
79
107
  */
80
108
  export declare class ServerStatusTool implements MCPTool {
81
109
  private readonly projects;
82
110
  private readonly runtime;
83
111
  private readonly distDirectories;
112
+ private readonly scanWorkers;
84
113
  readonly name = "server-status";
85
114
  readonly title = "Server Status";
86
115
  readonly annotations: ToolAnnotations;
87
116
  readonly description: string;
117
+ /**
118
+ * JSON Schema of the tool arguments.
119
+ * @hidden
120
+ */
88
121
  readonly inputSchema: {
89
122
  type: string;
90
123
  additionalProperties: boolean;
91
124
  properties: {};
92
125
  };
126
+ /**
127
+ * JSON Schema of the tool result (`structuredContent`).
128
+ * @hidden
129
+ */
93
130
  readonly outputSchema: {
94
131
  type: string;
95
132
  properties: {
@@ -318,6 +355,60 @@ export declare class ServerStatusTool implements MCPTool {
318
355
  };
319
356
  required: string[];
320
357
  };
358
+ scanWorkers: {
359
+ type: string;
360
+ properties: {
361
+ enabled: {
362
+ type: string;
363
+ };
364
+ maxHeapMB: {
365
+ type: string;
366
+ };
367
+ standby: {
368
+ type: string;
369
+ };
370
+ running: {
371
+ type: string;
372
+ items: {
373
+ type: string;
374
+ properties: {
375
+ threadId: {
376
+ type: string;
377
+ };
378
+ tool: {
379
+ type: string;
380
+ };
381
+ startedAt: {
382
+ type: string;
383
+ };
384
+ files: {
385
+ type: string;
386
+ };
387
+ filesDone: {
388
+ type: string;
389
+ };
390
+ heapUsedMB: {
391
+ type: string;
392
+ };
393
+ };
394
+ required: string[];
395
+ };
396
+ };
397
+ queued: {
398
+ type: string;
399
+ };
400
+ started: {
401
+ type: string;
402
+ };
403
+ cancelled: {
404
+ type: string;
405
+ };
406
+ failed: {
407
+ type: string;
408
+ };
409
+ };
410
+ required: string[];
411
+ };
321
412
  build: {
322
413
  type: string;
323
414
  properties: {
@@ -362,8 +453,9 @@ export declare class ServerStatusTool implements MCPTool {
362
453
  * @param projects - The project cache shared by the investigation tools.
363
454
  * @param runtime - Server start time, tool count, response sizes and protocol.
364
455
  * @param distDirectories - Package `dist/` directories to watch; missing ones are skipped.
456
+ * @param scanWorkers - State of the scan workers; default the server's scan host.
365
457
  */
366
- constructor(projects: ProjectCache, runtime: () => ServerRuntimeStats, distDirectories?: readonly DistDirectory[]);
458
+ constructor(projects: ProjectCache, runtime: () => ServerRuntimeStats, distDirectories?: readonly DistDirectory[], scanWorkers?: () => ScanHostStatus);
367
459
  execute(_args: Record<string, unknown>): Promise<ServerStatusOutput>;
368
460
  private buildSummary;
369
461
  }