@angular-modernizer/adapter-mcp 0.3.0 → 1.1.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 (298) hide show
  1. package/README.md +181 -282
  2. package/dist/cli.js +21 -13
  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 +122 -6
  6. package/dist/index.js +49 -5
  7. package/dist/mcp-watcher.d.ts +32 -7
  8. package/dist/mcp-watcher.js +16 -15
  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 +75 -0
  16. package/dist/server/limited-stdio-transport.js +115 -0
  17. package/dist/server/mcp-server.d.ts +20 -18
  18. package/dist/server/mcp-server.js +42 -79
  19. package/dist/server/package-version.d.ts +16 -0
  20. package/dist/server/package-version.js +37 -0
  21. package/dist/server/sdk-server.d.ts +71 -0
  22. package/dist/server/sdk-server.js +113 -0
  23. package/dist/server/tool-registry.d.ts +6 -9
  24. package/dist/server/tool-registry.js +6 -12
  25. package/dist/streaming/progress-store.d.ts +22 -5
  26. package/dist/streaming/progress-store.js +9 -5
  27. package/dist/tools/analyze-build-impact.d.ts +276 -35
  28. package/dist/tools/analyze-build-impact.js +175 -28
  29. package/dist/tools/analyze-core-to-shared.d.ts +176 -16
  30. package/dist/tools/analyze-core-to-shared.js +124 -19
  31. package/dist/tools/analyze-parser-performance.d.ts +209 -15
  32. package/dist/tools/analyze-parser-performance.js +119 -56
  33. package/dist/tools/analyze-project.d.ts +349 -17
  34. package/dist/tools/analyze-project.js +282 -97
  35. package/dist/tools/check-incremental-compatibility.d.ts +74 -12
  36. package/dist/tools/check-incremental-compatibility.js +69 -10
  37. package/dist/tools/collect-feedback.d.ts +225 -21
  38. package/dist/tools/collect-feedback.js +199 -118
  39. package/dist/tools/compare-health.d.ts +413 -0
  40. package/dist/tools/compare-health.js +479 -0
  41. package/dist/tools/extract-libraries.d.ts +200 -24
  42. package/dist/tools/extract-libraries.js +131 -27
  43. package/dist/tools/find-angular-symbol.d.ts +92 -24
  44. package/dist/tools/find-angular-symbol.js +70 -20
  45. package/dist/tools/find-component-hosts.d.ts +603 -27
  46. package/dist/tools/find-component-hosts.js +223 -19
  47. package/dist/tools/find-usages.d.ts +102 -22
  48. package/dist/tools/find-usages.js +81 -21
  49. package/dist/tools/get-bootstrap-execution.d.ts +183 -25
  50. package/dist/tools/get-bootstrap-execution.js +109 -25
  51. package/dist/tools/get-call-graph.d.ts +127 -12
  52. package/dist/tools/get-call-graph.js +84 -19
  53. package/dist/tools/get-operation-progress-tool.d.ts +126 -8
  54. package/dist/tools/get-operation-progress-tool.js +124 -12
  55. package/dist/tools/get-operation-progress.d.ts +27 -1
  56. package/dist/tools/get-operation-progress.js +5 -5
  57. package/dist/tools/helpers/analysis-output.d.ts +182 -0
  58. package/dist/tools/helpers/analysis-output.js +165 -0
  59. package/dist/tools/helpers/batch-kernel.d.ts +14 -0
  60. package/dist/tools/helpers/batch-kernel.js +12 -0
  61. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  62. package/dist/tools/helpers/build-schemas.js +23 -0
  63. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  64. package/dist/tools/helpers/citation-file-source.js +82 -0
  65. package/dist/tools/helpers/compact-output.d.ts +2 -1
  66. package/dist/tools/helpers/compact-output.js +2 -1
  67. package/dist/tools/helpers/finding-window.d.ts +43 -0
  68. package/dist/tools/helpers/finding-window.js +64 -0
  69. package/dist/tools/helpers/health-delta.d.ts +99 -0
  70. package/dist/tools/helpers/health-delta.js +236 -0
  71. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  72. package/dist/tools/helpers/investigation-schemas.js +48 -0
  73. package/dist/tools/helpers/library-imports.d.ts +57 -0
  74. package/dist/tools/helpers/library-imports.js +151 -0
  75. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  76. package/dist/tools/helpers/load-source-files.js +34 -0
  77. package/dist/tools/helpers/output-contract.d.ts +32 -0
  78. package/dist/tools/helpers/output-contract.js +32 -0
  79. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  80. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  81. package/dist/tools/helpers/process-output.d.ts +19 -0
  82. package/dist/tools/helpers/process-output.js +31 -0
  83. package/dist/tools/helpers/project-cache.d.ts +60 -37
  84. package/dist/tools/helpers/project-cache.js +54 -37
  85. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  86. package/dist/tools/helpers/project-decorators.js +22 -0
  87. package/dist/tools/helpers/rule-matcher.js +5 -0
  88. package/dist/tools/helpers/rule-runner.d.ts +25 -13
  89. package/dist/tools/helpers/rule-runner.js +45 -24
  90. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  91. package/dist/tools/helpers/scan-cache.js +34 -0
  92. package/dist/tools/helpers/scan-engine.d.ts +107 -0
  93. package/dist/tools/helpers/scan-engine.js +197 -0
  94. package/dist/tools/helpers/scan-plan.d.ts +5 -2
  95. package/dist/tools/helpers/scan-plan.js +18 -3
  96. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  97. package/dist/tools/helpers/scope-paths.js +32 -0
  98. package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
  99. package/dist/tools/helpers/suggestion-generator.js +0 -12
  100. package/dist/tools/helpers/tool-cache.d.ts +11 -0
  101. package/dist/tools/helpers/tool-cache.js +15 -0
  102. package/dist/tools/helpers/tool-context.d.ts +63 -0
  103. package/dist/tools/helpers/tool-context.js +79 -0
  104. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  105. package/dist/tools/helpers/transform-safety.js +87 -0
  106. package/dist/tools/helpers/validation-output.d.ts +53 -0
  107. package/dist/tools/helpers/validation-output.js +48 -0
  108. package/dist/tools/inspect-form-group.d.ts +262 -24
  109. package/dist/tools/inspect-form-group.js +134 -13
  110. package/dist/tools/inspect-i18n.d.ts +410 -23
  111. package/dist/tools/inspect-i18n.js +213 -13
  112. package/dist/tools/inspect-template.d.ts +260 -22
  113. package/dist/tools/inspect-template.js +174 -13
  114. package/dist/tools/learn-patterns.d.ts +210 -13
  115. package/dist/tools/learn-patterns.js +113 -12
  116. package/dist/tools/list-imports.d.ts +152 -34
  117. package/dist/tools/list-imports.js +124 -18
  118. package/dist/tools/orchestrate-migration.d.ts +159 -14
  119. package/dist/tools/orchestrate-migration.js +147 -20
  120. package/dist/tools/parse-stack-trace.d.ts +78 -21
  121. package/dist/tools/parse-stack-trace.js +44 -7
  122. package/dist/tools/plan-migration.d.ts +395 -26
  123. package/dist/tools/plan-migration.js +173 -22
  124. package/dist/tools/resolve-type.d.ts +57 -9
  125. package/dist/tools/resolve-type.js +49 -12
  126. package/dist/tools/review-feedback.d.ts +214 -16
  127. package/dist/tools/review-feedback.js +142 -57
  128. package/dist/tools/rollback-changes.d.ts +88 -7
  129. package/dist/tools/rollback-changes.js +74 -19
  130. package/dist/tools/run-angular-cli.d.ts +57 -12
  131. package/dist/tools/run-angular-cli.js +76 -13
  132. package/dist/tools/run-build.d.ts +127 -13
  133. package/dist/tools/run-build.js +128 -16
  134. package/dist/tools/run-schematic.d.ts +82 -12
  135. package/dist/tools/run-schematic.js +115 -18
  136. package/dist/tools/scan-all.d.ts +88 -23
  137. package/dist/tools/scan-all.js +161 -220
  138. package/dist/tools/scan-angular.d.ts +60 -19
  139. package/dist/tools/scan-angular.js +100 -141
  140. package/dist/tools/scan-architecture.d.ts +92 -24
  141. package/dist/tools/scan-architecture.js +268 -211
  142. package/dist/tools/scan-solid.d.ts +59 -19
  143. package/dist/tools/scan-solid.js +98 -139
  144. package/dist/tools/search-codebase.d.ts +110 -23
  145. package/dist/tools/search-codebase.js +67 -11
  146. package/dist/tools/server-status.d.ts +392 -26
  147. package/dist/tools/server-status.js +260 -27
  148. package/dist/tools/suggest-improvements.d.ts +105 -10
  149. package/dist/tools/suggest-improvements.js +91 -51
  150. package/dist/tools/trace-output-flow.d.ts +713 -26
  151. package/dist/tools/trace-output-flow.js +396 -33
  152. package/dist/tools/transform-code-batch.d.ts +3 -0
  153. package/dist/tools/transform-code-batch.js +10 -5
  154. package/dist/tools/transform-code.d.ts +402 -18
  155. package/dist/tools/transform-code.js +708 -649
  156. package/dist/tools/validate-before-transform.d.ts +136 -7
  157. package/dist/tools/validate-before-transform.js +65 -9
  158. package/dist/tools/validate-project-compatibility.d.ts +82 -15
  159. package/dist/tools/validate-project-compatibility.js +84 -15
  160. package/dist/tools/validate-transformation.d.ts +243 -8
  161. package/dist/tools/validate-transformation.js +127 -23
  162. package/dist/tools/verify-citations.d.ts +202 -0
  163. package/dist/tools/verify-citations.js +221 -0
  164. package/dist/types.d.ts +78 -11
  165. package/dist/types.js +0 -5
  166. package/dist/utils/format-tool-response.d.ts +22 -59
  167. package/dist/utils/format-tool-response.js +25 -134
  168. package/package.json +31 -20
  169. package/dist/cli.d.ts.map +0 -1
  170. package/dist/cli.js.map +0 -1
  171. package/dist/core/project-analyzer.d.ts.map +0 -1
  172. package/dist/core/project-analyzer.js.map +0 -1
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/mcp-watcher.d.ts.map +0 -1
  176. package/dist/mcp-watcher.js.map +0 -1
  177. package/dist/server/json-rpc-handler.d.ts +0 -98
  178. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  179. package/dist/server/json-rpc-handler.js +0 -301
  180. package/dist/server/json-rpc-handler.js.map +0 -1
  181. package/dist/server/mcp-server.d.ts.map +0 -1
  182. package/dist/server/mcp-server.js.map +0 -1
  183. package/dist/server/stdio-guard.d.ts.map +0 -1
  184. package/dist/server/stdio-guard.js.map +0 -1
  185. package/dist/server/tool-registry.d.ts.map +0 -1
  186. package/dist/server/tool-registry.js.map +0 -1
  187. package/dist/streaming/progress-store.d.ts.map +0 -1
  188. package/dist/streaming/progress-store.js.map +0 -1
  189. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  190. package/dist/tools/analyze-build-impact.js.map +0 -1
  191. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  192. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  193. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  194. package/dist/tools/analyze-parser-performance.js.map +0 -1
  195. package/dist/tools/analyze-project.d.ts.map +0 -1
  196. package/dist/tools/analyze-project.js.map +0 -1
  197. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  198. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  199. package/dist/tools/collect-feedback.d.ts.map +0 -1
  200. package/dist/tools/collect-feedback.js.map +0 -1
  201. package/dist/tools/extract-libraries.d.ts.map +0 -1
  202. package/dist/tools/extract-libraries.js.map +0 -1
  203. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  204. package/dist/tools/find-angular-symbol.js.map +0 -1
  205. package/dist/tools/find-component-hosts.d.ts.map +0 -1
  206. package/dist/tools/find-component-hosts.js.map +0 -1
  207. package/dist/tools/find-usages.d.ts.map +0 -1
  208. package/dist/tools/find-usages.js.map +0 -1
  209. package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
  210. package/dist/tools/get-bootstrap-execution.js.map +0 -1
  211. package/dist/tools/get-call-graph.d.ts.map +0 -1
  212. package/dist/tools/get-call-graph.js.map +0 -1
  213. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  214. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  215. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  216. package/dist/tools/get-operation-progress.js.map +0 -1
  217. package/dist/tools/helpers/compact-output.d.ts.map +0 -1
  218. package/dist/tools/helpers/compact-output.js.map +0 -1
  219. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  220. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  221. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  222. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  223. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  224. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  225. package/dist/tools/helpers/project-cache.d.ts.map +0 -1
  226. package/dist/tools/helpers/project-cache.js.map +0 -1
  227. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  228. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  229. package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
  230. package/dist/tools/helpers/rule-runner.js.map +0 -1
  231. package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
  232. package/dist/tools/helpers/scan-plan.js.map +0 -1
  233. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
  234. package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
  235. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  236. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  237. package/dist/tools/inspect-form-group.d.ts.map +0 -1
  238. package/dist/tools/inspect-form-group.js.map +0 -1
  239. package/dist/tools/inspect-i18n.d.ts.map +0 -1
  240. package/dist/tools/inspect-i18n.js.map +0 -1
  241. package/dist/tools/inspect-template.d.ts.map +0 -1
  242. package/dist/tools/inspect-template.js.map +0 -1
  243. package/dist/tools/learn-patterns.d.ts.map +0 -1
  244. package/dist/tools/learn-patterns.js.map +0 -1
  245. package/dist/tools/list-imports.d.ts.map +0 -1
  246. package/dist/tools/list-imports.js.map +0 -1
  247. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  248. package/dist/tools/orchestrate-migration.js.map +0 -1
  249. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  250. package/dist/tools/parse-stack-trace.js.map +0 -1
  251. package/dist/tools/plan-migration.d.ts.map +0 -1
  252. package/dist/tools/plan-migration.js.map +0 -1
  253. package/dist/tools/resolve-type.d.ts.map +0 -1
  254. package/dist/tools/resolve-type.js.map +0 -1
  255. package/dist/tools/review-feedback.d.ts.map +0 -1
  256. package/dist/tools/review-feedback.js.map +0 -1
  257. package/dist/tools/rollback-changes.d.ts.map +0 -1
  258. package/dist/tools/rollback-changes.js.map +0 -1
  259. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  260. package/dist/tools/run-angular-cli.js.map +0 -1
  261. package/dist/tools/run-build.d.ts.map +0 -1
  262. package/dist/tools/run-build.js.map +0 -1
  263. package/dist/tools/run-schematic.d.ts.map +0 -1
  264. package/dist/tools/run-schematic.js.map +0 -1
  265. package/dist/tools/scan-all.d.ts.map +0 -1
  266. package/dist/tools/scan-all.js.map +0 -1
  267. package/dist/tools/scan-angular.d.ts.map +0 -1
  268. package/dist/tools/scan-angular.js.map +0 -1
  269. package/dist/tools/scan-architecture.d.ts.map +0 -1
  270. package/dist/tools/scan-architecture.js.map +0 -1
  271. package/dist/tools/scan-solid.d.ts.map +0 -1
  272. package/dist/tools/scan-solid.js.map +0 -1
  273. package/dist/tools/search-codebase.d.ts.map +0 -1
  274. package/dist/tools/search-codebase.js.map +0 -1
  275. package/dist/tools/server-status.d.ts.map +0 -1
  276. package/dist/tools/server-status.js.map +0 -1
  277. package/dist/tools/shared/scan-types.d.ts +0 -200
  278. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  279. package/dist/tools/shared/scan-types.js +0 -7
  280. package/dist/tools/shared/scan-types.js.map +0 -1
  281. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  282. package/dist/tools/suggest-improvements.js.map +0 -1
  283. package/dist/tools/trace-output-flow.d.ts.map +0 -1
  284. package/dist/tools/trace-output-flow.js.map +0 -1
  285. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  286. package/dist/tools/transform-code-batch.js.map +0 -1
  287. package/dist/tools/transform-code.d.ts.map +0 -1
  288. package/dist/tools/transform-code.js.map +0 -1
  289. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  290. package/dist/tools/validate-before-transform.js.map +0 -1
  291. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  292. package/dist/tools/validate-project-compatibility.js.map +0 -1
  293. package/dist/tools/validate-transformation.d.ts.map +0 -1
  294. package/dist/tools/validate-transformation.js.map +0 -1
  295. package/dist/types.d.ts.map +0 -1
  296. package/dist/types.js.map +0 -1
  297. package/dist/utils/format-tool-response.d.ts.map +0 -1
  298. package/dist/utils/format-tool-response.js.map +0 -1
@@ -1,22 +1,67 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Run Build Tool
3
- *
4
- * MCP tool for executing build systems and validating code transformations.
5
- * Supports Angular CLI, Nx, Webpack, Vite, and auto-detection.
6
- * Includes incremental build mode for efficient validation.
7
- */
8
1
  import { spawn, execSync } from 'node:child_process';
9
2
  import { existsSync, readFileSync } from 'node:fs';
10
3
  import { join } from 'node:path';
11
- import { loadConfig, } from '@angular-modernizer/core';
4
+ import { loadConfig, processGroupOptions, terminateOnAbort, terminateProcessTree, } from '@angular-modernizer/core';
5
+ import { INCOMPATIBILITY_ISSUES_SCHEMA } from './helpers/build-schemas.js';
6
+ import { STRING_ARRAY } from './helpers/investigation-schemas.js';
7
+ import { outputTail, seconds } from './helpers/process-output.js';
8
+ /** Build warnings spelled out in the summary; the rest is in `warnings`. */
9
+ const SUMMARY_BUILD_WARNINGS = 5;
10
+ /** Text summary: outcome, build mode, warnings, blockers and the tail of the output on failure. */
11
+ function describeBuild(result) {
12
+ const ending = result.timedOut === true
13
+ ? `timed out after ${seconds(result.executionTime)}`
14
+ : `exited ${result.exitCode} after ${seconds(result.executionTime)}`;
15
+ const lines = [
16
+ `Build ${result.success ? 'passed' : 'failed'} (${result.buildSystem}): \`${result.fullCommand}\` ${ending}.`,
17
+ ];
18
+ const inc = result.incremental;
19
+ if (inc !== undefined) {
20
+ lines.push(inc.enabled
21
+ ? `Incremental (${inc.scope ?? 'unknown scope'}): ${inc.filesBuilt ?? 0} file(s) built, ` +
22
+ `${inc.filesSkipped ?? 0} skipped${inc.speedup === undefined ? '' : `; ${inc.speedup}`}.`
23
+ : `Full build${inc.fallbackReason === undefined ? '' : `: ${inc.fallbackReason}`}.`);
24
+ }
25
+ const blockers = (result.incompatibilityIssues ?? []).filter((i) => i.detected && i.severity === 'blocker');
26
+ if (blockers.length > 0) {
27
+ lines.push(`Blockers for incremental builds: ${blockers.map((b) => b.type).join(', ')}.`);
28
+ }
29
+ const warnings = result.warnings ?? [];
30
+ if (warnings.length > 0) {
31
+ lines.push(`${warnings.length} build warning(s):`);
32
+ lines.push(...warnings.slice(0, SUMMARY_BUILD_WARNINGS).map((w) => `- ${w}`));
33
+ }
34
+ if (!result.success) {
35
+ const tail = outputTail(result.errors) ?? outputTail(result.output);
36
+ if (tail !== undefined) {
37
+ lines.push(`Last output:\n${tail}`);
38
+ }
39
+ }
40
+ return lines.join('\n');
41
+ }
12
42
  /**
13
- * MCP tool for executing build systems.
43
+ * MCP tool for executing build systems and validating code transformations.
44
+ * Supports Angular CLI, Nx, Webpack, Vite, and auto-detection.
45
+ * Includes incremental build mode for efficient validation.
14
46
  */
15
47
  export class RunBuildTool {
16
48
  name = 'run-build';
17
- description = 'Execute build systems to validate code transformations. Supports incremental mode for 2-4x faster builds by validating only changed files and their dependencies. Automatically detects incompatibilities and falls back to full build when needed.';
49
+ title = 'Run Build';
50
+ annotations = {
51
+ readOnlyHint: false,
52
+ destructiveHint: true,
53
+ idempotentHint: true,
54
+ openWorldHint: false,
55
+ };
56
+ description = 'Execute build systems to validate code transformations. Supports incremental mode for 2-4x faster builds by validating only changed files and their dependencies. Automatically detects incompatibilities and falls back to full build when needed. ' +
57
+ 'The result has the full build output; summary is a short text with the outcome, the build mode and, on failure, the last output lines.';
58
+ /**
59
+ * JSON Schema of the tool arguments.
60
+ * @hidden
61
+ */
18
62
  inputSchema = {
19
63
  type: 'object',
64
+ additionalProperties: false,
20
65
  properties: {
21
66
  rootPath: {
22
67
  type: 'string',
@@ -75,7 +120,61 @@ export class RunBuildTool {
75
120
  },
76
121
  required: ['rootPath'],
77
122
  };
78
- async execute(args) {
123
+ /**
124
+ * JSON Schema of the tool result (`structuredContent`).
125
+ * @hidden
126
+ */
127
+ outputSchema = {
128
+ type: 'object',
129
+ properties: {
130
+ success: { type: 'boolean' },
131
+ buildSystem: { type: 'string' },
132
+ command: { type: 'string' },
133
+ fullCommand: { type: 'string' },
134
+ exitCode: { type: 'integer' },
135
+ output: { type: 'string' },
136
+ errors: { type: 'string' },
137
+ executionTime: { type: 'number' },
138
+ timedOut: { type: 'boolean' },
139
+ artifacts: STRING_ARRAY,
140
+ warnings: {
141
+ type: 'array',
142
+ items: { type: 'string' },
143
+ description: 'Warnings the build printed.',
144
+ },
145
+ incremental: {
146
+ type: 'object',
147
+ properties: {
148
+ enabled: { type: 'boolean' },
149
+ scope: { type: 'string' },
150
+ filesBuilt: { type: 'integer' },
151
+ filesSkipped: { type: 'integer' },
152
+ cacheHit: { type: 'boolean' },
153
+ speedup: { type: 'string' },
154
+ fallbackReason: { type: 'string' },
155
+ },
156
+ required: ['enabled'],
157
+ },
158
+ incompatibilityIssues: INCOMPATIBILITY_ISSUES_SCHEMA,
159
+ summary: { type: 'string' },
160
+ },
161
+ required: [
162
+ 'success',
163
+ 'buildSystem',
164
+ 'command',
165
+ 'fullCommand',
166
+ 'exitCode',
167
+ 'output',
168
+ 'errors',
169
+ 'executionTime',
170
+ 'summary',
171
+ ],
172
+ };
173
+ async execute(args, ctx = {}) {
174
+ const result = await this.runBuild(args, ctx.signal);
175
+ return { ...result, summary: describeBuild(result) };
176
+ }
177
+ async runBuild(args, signal) {
79
178
  const params = args;
80
179
  if (!params.rootPath) {
81
180
  throw new Error('rootPath is required');
@@ -117,10 +216,13 @@ export class RunBuildTool {
117
216
  // Attempt incremental build if enabled
118
217
  if (attemptIncremental) {
119
218
  try {
120
- return await this.executeIncrementalBuild(rootPath, params, systemInfo, options, timeout);
219
+ return await this.executeIncrementalBuild(rootPath, params, systemInfo, options, timeout, signal);
121
220
  }
122
221
  catch (error) {
123
- // Fallback to full build on any error
222
+ // A cancelled build stops; any other error falls back to a full build
223
+ if (signal?.aborted === true) {
224
+ throw error;
225
+ }
124
226
  incrementalMetadata = {
125
227
  enabled: false,
126
228
  fallbackReason: error instanceof Error
@@ -135,6 +237,7 @@ export class RunBuildTool {
135
237
  const result = await this.executeBuildCommand(buildArgs, {
136
238
  cwd: rootPath,
137
239
  timeout,
240
+ signal,
138
241
  });
139
242
  const executionTime = Date.now() - startTime;
140
243
  const { warnings, artifacts } = this.parseBuildOutput(result.stdout);
@@ -215,7 +318,7 @@ export class RunBuildTool {
215
318
  /**
216
319
  * Executes an incremental build using IncompatibilityDetector and IncrementalBuildValidator
217
320
  */
218
- async executeIncrementalBuild(rootPath, params, systemInfo, options, timeout) {
321
+ async executeIncrementalBuild(rootPath, params, systemInfo, options, timeout, signal) {
219
322
  // Dynamic import to avoid circular dependencies
220
323
  const { Project } = await import('ts-morph');
221
324
  const { IncompatibilityDetector, IncrementalBuildValidator, IncrementalAnalyzer, } = await import('@angular-modernizer/core');
@@ -237,6 +340,7 @@ export class RunBuildTool {
237
340
  const result = await this.executeBuildCommand(buildArgs, {
238
341
  cwd: rootPath,
239
342
  timeout,
343
+ signal,
240
344
  });
241
345
  const executionTime = Date.now() - startTime;
242
346
  const { warnings, artifacts } = this.parseBuildOutput(result.stdout);
@@ -313,6 +417,7 @@ export class RunBuildTool {
313
417
  baseBranch: 'HEAD',
314
418
  forceFiles: params.changedFiles,
315
419
  includeDependents: true,
420
+ signal,
316
421
  });
317
422
  // Calculate speedup with better messaging
318
423
  const fullBuildEstimate = validationResult.scope.estimatedBuildTime * 1000;
@@ -494,16 +599,19 @@ export class RunBuildTool {
494
599
  stdio: ['pipe', 'pipe', 'pipe'],
495
600
  shell: true,
496
601
  env: { ...process.env, CI: 'true' },
602
+ ...processGroupOptions(),
497
603
  });
498
604
  let stdout = '';
499
605
  let stderr = '';
500
- // Set up timeout
606
+ // Set up timeout; the build runs under a shell, so the whole process tree goes
501
607
  const timeoutId = setTimeout(() => {
502
- buildProcess.kill('SIGTERM');
608
+ terminateProcessTree(buildProcess);
503
609
  reject(new Error(`Build command timed out after ${options.timeout}ms`));
504
610
  }, options.timeout);
611
+ const stopOnAbort = terminateOnAbort(buildProcess, options.signal);
505
612
  const cleanup = () => {
506
613
  clearTimeout(timeoutId);
614
+ stopOnAbort();
507
615
  };
508
616
  buildProcess.stdout.on('data', (data) => {
509
617
  stdout += data.toString();
@@ -513,6 +621,10 @@ export class RunBuildTool {
513
621
  });
514
622
  buildProcess.on('close', (code) => {
515
623
  cleanup();
624
+ if (options.signal?.aborted === true) {
625
+ reject(new Error('Build cancelled'));
626
+ return;
627
+ }
516
628
  resolve({
517
629
  exitCode: code ?? 0,
518
630
  stdout,
@@ -1,15 +1,8 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Run Schematic Tool
3
- *
4
- * MCP tool for executing Angular schematics programmatically.
5
- * Enables AI assistants to run code generation and migration schematics
6
- * from built-in Angular collections or custom schematic libraries.
7
- */
8
- import { type MCPTool } from '../types.js';
1
+ import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
9
2
  /**
10
3
  * Result of schematic execution.
11
4
  */
12
- interface SchematicResult {
5
+ export interface SchematicResult {
13
6
  /**
14
7
  * Whether the schematic executed successfully.
15
8
  */
@@ -66,15 +59,28 @@ interface SchematicResult {
66
59
  * Warnings or informational messages.
67
60
  */
68
61
  warnings: string[];
62
+ /**
63
+ * Short text: command, exit code, generated files, conflicts, and the last output lines on failure.
64
+ */
65
+ summary: string;
69
66
  }
70
67
  /**
71
- * MCP tool for executing Angular schematics.
68
+ * MCP tool for executing Angular schematics programmatically.
69
+ * Enables AI assistants to run code generation and migration schematics
70
+ * from built-in Angular collections or custom schematic libraries.
72
71
  */
73
72
  export declare class RunSchematicTool implements MCPTool {
74
73
  name: string;
74
+ title: string;
75
+ annotations: ToolAnnotations;
75
76
  description: string;
77
+ /**
78
+ * JSON Schema of the tool arguments.
79
+ * @hidden
80
+ */
76
81
  inputSchema: {
77
82
  type: string;
83
+ additionalProperties: boolean;
78
84
  properties: {
79
85
  schematic: {
80
86
  type: string;
@@ -131,7 +137,72 @@ export declare class RunSchematicTool implements MCPTool {
131
137
  };
132
138
  required: string[];
133
139
  };
134
- execute(args: Record<string, unknown>): Promise<SchematicResult>;
140
+ /**
141
+ * JSON Schema of the tool result (`structuredContent`).
142
+ * @hidden
143
+ */
144
+ outputSchema: {
145
+ type: string;
146
+ properties: {
147
+ success: {
148
+ type: string;
149
+ };
150
+ schematic: {
151
+ type: string;
152
+ };
153
+ collection: {
154
+ type: string;
155
+ };
156
+ target: {
157
+ type: string;
158
+ };
159
+ fullCommand: {
160
+ type: string;
161
+ };
162
+ exitCode: {
163
+ type: string;
164
+ };
165
+ stdout: {
166
+ type: string;
167
+ };
168
+ stderr: {
169
+ type: string;
170
+ };
171
+ filesGenerated: {
172
+ readonly type: "array";
173
+ readonly items: {
174
+ readonly type: "string";
175
+ };
176
+ };
177
+ conflicts: {
178
+ readonly type: "array";
179
+ readonly items: {
180
+ readonly type: "string";
181
+ };
182
+ };
183
+ executionTime: {
184
+ type: string;
185
+ };
186
+ timedOut: {
187
+ type: string;
188
+ };
189
+ cwd: {
190
+ type: string;
191
+ };
192
+ warnings: {
193
+ type: string;
194
+ items: {
195
+ type: string;
196
+ };
197
+ description: string;
198
+ };
199
+ summary: {
200
+ type: string;
201
+ };
202
+ };
203
+ required: string[];
204
+ };
205
+ execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<SchematicResult>;
135
206
  /**
136
207
  * Validate schematic name format.
137
208
  */
@@ -169,5 +240,4 @@ export declare class RunSchematicTool implements MCPTool {
169
240
  */
170
241
  private extractWarnings;
171
242
  }
172
- export {};
173
243
  //# sourceMappingURL=run-schematic.d.ts.map
@@ -1,13 +1,41 @@
1
- /**
2
- * @angular-modernizer/adapter-mcp - Run Schematic Tool
3
- *
4
- * MCP tool for executing Angular schematics programmatically.
5
- * Enables AI assistants to run code generation and migration schematics
6
- * from built-in Angular collections or custom schematic libraries.
7
- */
8
1
  import { spawn } from 'node:child_process';
2
+ import { processGroupOptions, terminateOnAbort, terminateProcessTree, } from '@angular-modernizer/core';
9
3
  import { existsSync } from 'node:fs';
10
4
  import { resolve, dirname } from 'node:path';
5
+ import { STRING_ARRAY } from './helpers/investigation-schemas.js';
6
+ import { outputTail, seconds } from './helpers/process-output.js';
7
+ /** Generated files spelled out in the summary; the rest is in `filesGenerated`. */
8
+ const SUMMARY_FILES = 10;
9
+ /** Text summary: outcome, files, conflicts, warnings and the tail of the output on failure. */
10
+ function describeSchematic(result) {
11
+ const ending = result.timedOut === true
12
+ ? `timed out after ${seconds(result.executionTime)}`
13
+ : `exited ${result.exitCode} after ${seconds(result.executionTime)}`;
14
+ const lines = [
15
+ `Schematic ${result.collection}:${result.schematic} ${result.success ? 'passed' : 'failed'}: ` +
16
+ `\`${result.fullCommand}\` ${ending} in ${result.cwd}.`,
17
+ ];
18
+ if (result.filesGenerated.length > 0) {
19
+ lines.push(`${result.filesGenerated.length} file(s) generated or updated:`);
20
+ lines.push(...result.filesGenerated.slice(0, SUMMARY_FILES).map((f) => `- ${f}`));
21
+ }
22
+ if (result.conflicts.length > 0) {
23
+ lines.push(`${result.conflicts.length} conflict(s): ${result.conflicts.join('; ')}`);
24
+ }
25
+ if (result.warnings.length > 0) {
26
+ lines.push(`${result.warnings.length} warning(s).`);
27
+ }
28
+ if (!result.success) {
29
+ const tail = outputTail(result.stderr) ?? outputTail(result.stdout);
30
+ if (tail !== undefined) {
31
+ lines.push(`Last output:\n${tail}`);
32
+ }
33
+ }
34
+ return lines.join('\n');
35
+ }
36
+ function withSummary(result) {
37
+ return { ...result, summary: describeSchematic(result) };
38
+ }
11
39
  /**
12
40
  * Safe schematic options whitelist.
13
41
  * Only these options are allowed to prevent security issues and ensure compatibility.
@@ -44,17 +72,32 @@ const SAFE_SCHEMATIC_OPTIONS = new Set([
44
72
  // Additional safe options
45
73
  'dry-run',
46
74
  'force',
47
- 'skip-confirmation',
75
+ 'interactive',
48
76
  'defaults',
49
77
  ]);
50
78
  /**
51
- * MCP tool for executing Angular schematics.
79
+ * MCP tool for executing Angular schematics programmatically.
80
+ * Enables AI assistants to run code generation and migration schematics
81
+ * from built-in Angular collections or custom schematic libraries.
52
82
  */
53
83
  export class RunSchematicTool {
54
84
  name = 'run-schematic';
55
- description = 'Execute Angular schematics for code generation and automated migrations';
85
+ title = 'Run Schematic';
86
+ annotations = {
87
+ readOnlyHint: false,
88
+ destructiveHint: true,
89
+ idempotentHint: false,
90
+ openWorldHint: true,
91
+ };
92
+ description = 'Execute Angular schematics for code generation and automated migrations. ' +
93
+ 'The result has the full stdout and stderr; summary is a short text with the outcome, the generated files and, on failure, the last output lines.';
94
+ /**
95
+ * JSON Schema of the tool arguments.
96
+ * @hidden
97
+ */
56
98
  inputSchema = {
57
99
  type: 'object',
100
+ additionalProperties: false,
58
101
  properties: {
59
102
  schematic: {
60
103
  type: 'string',
@@ -87,7 +130,7 @@ export class RunSchematicTool {
87
130
  },
88
131
  skipPrompts: {
89
132
  type: 'boolean',
90
- description: 'Skip interactive prompts',
133
+ description: 'Skip interactive prompts (passes --interactive=false to ng generate)',
91
134
  default: true,
92
135
  },
93
136
  dryRun: {
@@ -111,7 +154,51 @@ export class RunSchematicTool {
111
154
  },
112
155
  required: ['schematic', 'target'],
113
156
  };
114
- async execute(args) {
157
+ /**
158
+ * JSON Schema of the tool result (`structuredContent`).
159
+ * @hidden
160
+ */
161
+ outputSchema = {
162
+ type: 'object',
163
+ properties: {
164
+ success: { type: 'boolean' },
165
+ schematic: { type: 'string' },
166
+ collection: { type: 'string' },
167
+ target: { type: 'string' },
168
+ fullCommand: { type: 'string' },
169
+ exitCode: { type: 'integer' },
170
+ stdout: { type: 'string' },
171
+ stderr: { type: 'string' },
172
+ filesGenerated: STRING_ARRAY,
173
+ conflicts: STRING_ARRAY,
174
+ executionTime: { type: 'number' },
175
+ timedOut: { type: 'boolean' },
176
+ cwd: { type: 'string' },
177
+ warnings: {
178
+ type: 'array',
179
+ items: { type: 'string' },
180
+ description: 'Warnings the schematic printed.',
181
+ },
182
+ summary: { type: 'string' },
183
+ },
184
+ required: [
185
+ 'success',
186
+ 'schematic',
187
+ 'collection',
188
+ 'target',
189
+ 'fullCommand',
190
+ 'exitCode',
191
+ 'stdout',
192
+ 'stderr',
193
+ 'filesGenerated',
194
+ 'conflicts',
195
+ 'executionTime',
196
+ 'cwd',
197
+ 'warnings',
198
+ 'summary',
199
+ ],
200
+ };
201
+ async execute(args, ctx = {}) {
115
202
  const params = args;
116
203
  // Validate required parameters
117
204
  if (!params.schematic || typeof params.schematic !== 'string') {
@@ -150,13 +237,14 @@ export class RunSchematicTool {
150
237
  const result = await this.executeSchematic(commandArgs, {
151
238
  cwd: projectRoot,
152
239
  timeout: executionOptions.timeout ?? 300000,
240
+ signal: ctx.signal,
153
241
  });
154
242
  const executionTime = Date.now() - startTime;
155
243
  // Parse output for generated files and conflicts
156
244
  const filesGenerated = this.extractGeneratedFiles(result.stdout);
157
245
  const conflicts = this.extractConflicts(result.stderr);
158
246
  const warnings = this.extractWarnings(result.stdout, result.stderr);
159
- return {
247
+ return withSummary({
160
248
  success: result.exitCode === 0,
161
249
  schematic,
162
250
  collection,
@@ -170,11 +258,11 @@ export class RunSchematicTool {
170
258
  executionTime,
171
259
  cwd: projectRoot,
172
260
  warnings,
173
- };
261
+ });
174
262
  }
175
263
  catch (error) {
176
264
  if (error instanceof Error && error.message.includes('timed out')) {
177
- return {
265
+ return withSummary({
178
266
  success: false,
179
267
  schematic,
180
268
  collection,
@@ -189,7 +277,7 @@ export class RunSchematicTool {
189
277
  timedOut: true,
190
278
  cwd: projectRoot,
191
279
  warnings: [],
192
- };
280
+ });
193
281
  }
194
282
  throw new Error(`Schematic execution failed: ${error instanceof Error ? error.message : String(error)}`);
195
283
  }
@@ -311,8 +399,10 @@ export class RunSchematicTool {
311
399
  if (executionOptions.force) {
312
400
  args.push('--force');
313
401
  }
402
+ // ng generate has no --skip-confirmation (only ng add and ng update do);
403
+ // --interactive=false turns the prompts off.
314
404
  if (executionOptions.skipPrompts ?? true) {
315
- args.push('--skip-confirmation');
405
+ args.push('--interactive=false');
316
406
  }
317
407
  return args;
318
408
  }
@@ -326,16 +416,19 @@ export class RunSchematicTool {
326
416
  env: process.env,
327
417
  stdio: ['pipe', 'pipe', 'pipe'],
328
418
  shell: true,
419
+ ...processGroupOptions(),
329
420
  });
330
421
  let stdout = '';
331
422
  let stderr = '';
332
423
  // Set up timeout
333
424
  const timeoutId = setTimeout(() => {
334
- ngProcess.kill('SIGTERM');
425
+ terminateProcessTree(ngProcess);
335
426
  reject(new Error(`Schematic execution timed out after ${options.timeout}ms`));
336
427
  }, options.timeout);
428
+ const stopOnAbort = terminateOnAbort(ngProcess, options.signal);
337
429
  const cleanup = () => {
338
430
  clearTimeout(timeoutId);
431
+ stopOnAbort();
339
432
  };
340
433
  ngProcess.stdout.on('data', (data) => {
341
434
  stdout += data.toString();
@@ -345,6 +438,10 @@ export class RunSchematicTool {
345
438
  });
346
439
  ngProcess.on('close', (code) => {
347
440
  cleanup();
441
+ if (options.signal?.aborted === true) {
442
+ reject(new Error('Command cancelled'));
443
+ return;
444
+ }
348
445
  resolve({
349
446
  exitCode: code ?? 0,
350
447
  stdout,