@angular-modernizer/adapter-mcp 0.2.0 → 1.0.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 (255) hide show
  1. package/README.md +188 -235
  2. package/dist/cli.js +77 -27
  3. package/dist/index.d.ts +11 -3
  4. package/dist/index.js +10 -2
  5. package/dist/mcp-watcher.d.ts +6 -1
  6. package/dist/mcp-watcher.js +14 -10
  7. package/dist/server/limited-stdio-transport.d.ts +68 -0
  8. package/dist/server/limited-stdio-transport.js +115 -0
  9. package/dist/server/mcp-server.d.ts +41 -12
  10. package/dist/server/mcp-server.js +113 -94
  11. package/dist/server/package-version.d.ts +16 -0
  12. package/dist/server/package-version.js +37 -0
  13. package/dist/server/sdk-server.d.ts +70 -0
  14. package/dist/server/sdk-server.js +113 -0
  15. package/dist/server/stdio-guard.d.ts +20 -0
  16. package/dist/server/stdio-guard.js +48 -0
  17. package/dist/server/tool-registry.d.ts +3 -2
  18. package/dist/server/tool-registry.js +5 -5
  19. package/dist/tools/analyze-build-impact.d.ts +346 -14
  20. package/dist/tools/analyze-build-impact.js +315 -31
  21. package/dist/tools/analyze-core-to-shared.d.ts +134 -4
  22. package/dist/tools/analyze-core-to-shared.js +113 -9
  23. package/dist/tools/analyze-parser-performance.d.ts +200 -7
  24. package/dist/tools/analyze-parser-performance.js +108 -47
  25. package/dist/tools/analyze-project.d.ts +267 -5
  26. package/dist/tools/analyze-project.js +196 -8
  27. package/dist/tools/check-incremental-compatibility.d.ts +61 -1
  28. package/dist/tools/check-incremental-compatibility.js +58 -2
  29. package/dist/tools/collect-feedback.d.ts +199 -10
  30. package/dist/tools/collect-feedback.js +171 -99
  31. package/dist/tools/compare-health.d.ts +356 -0
  32. package/dist/tools/compare-health.js +472 -0
  33. package/dist/tools/extract-libraries.d.ts +156 -4
  34. package/dist/tools/extract-libraries.js +115 -10
  35. package/dist/tools/find-angular-symbol.d.ts +98 -9
  36. package/dist/tools/find-angular-symbol.js +104 -12
  37. package/dist/tools/find-component-hosts.d.ts +684 -0
  38. package/dist/tools/find-component-hosts.js +441 -0
  39. package/dist/tools/find-usages.d.ts +99 -4
  40. package/dist/tools/find-usages.js +131 -11
  41. package/dist/tools/get-bootstrap-execution.d.ts +258 -0
  42. package/dist/tools/get-bootstrap-execution.js +324 -0
  43. package/dist/tools/get-call-graph.d.ts +139 -4
  44. package/dist/tools/get-call-graph.js +123 -13
  45. package/dist/tools/get-operation-progress-tool.d.ts +114 -2
  46. package/dist/tools/get-operation-progress-tool.js +114 -7
  47. package/dist/tools/get-operation-progress.d.ts +1 -1
  48. package/dist/tools/get-operation-progress.js +5 -5
  49. package/dist/tools/helpers/analysis-output.d.ts +177 -0
  50. package/dist/tools/helpers/analysis-output.js +165 -0
  51. package/dist/tools/helpers/build-schemas.d.ts +36 -0
  52. package/dist/tools/helpers/build-schemas.js +23 -0
  53. package/dist/tools/helpers/citation-file-source.d.ts +10 -0
  54. package/dist/tools/helpers/citation-file-source.js +82 -0
  55. package/dist/tools/helpers/compact-output.d.ts +61 -0
  56. package/dist/tools/helpers/compact-output.js +83 -0
  57. package/dist/tools/helpers/finding-window.d.ts +43 -0
  58. package/dist/tools/helpers/finding-window.js +64 -0
  59. package/dist/tools/helpers/health-delta.d.ts +86 -0
  60. package/dist/tools/helpers/health-delta.js +239 -0
  61. package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
  62. package/dist/tools/helpers/investigation-schemas.js +48 -0
  63. package/dist/tools/helpers/library-imports.d.ts +57 -0
  64. package/dist/tools/helpers/library-imports.js +151 -0
  65. package/dist/tools/helpers/load-source-files.d.ts +30 -0
  66. package/dist/tools/helpers/load-source-files.js +34 -0
  67. package/dist/tools/helpers/output-contract.d.ts +32 -0
  68. package/dist/tools/helpers/output-contract.js +32 -0
  69. package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
  70. package/dist/tools/helpers/platform-root-resolver.js +75 -48
  71. package/dist/tools/helpers/process-output.d.ts +19 -0
  72. package/dist/tools/helpers/process-output.js +31 -0
  73. package/dist/tools/helpers/project-cache.d.ts +184 -0
  74. package/dist/tools/helpers/project-cache.js +331 -0
  75. package/dist/tools/helpers/project-decorators.d.ts +14 -0
  76. package/dist/tools/helpers/project-decorators.js +22 -0
  77. package/dist/tools/helpers/rule-matcher.js +5 -0
  78. package/dist/tools/helpers/rule-runner.d.ts +72 -0
  79. package/dist/tools/helpers/rule-runner.js +131 -0
  80. package/dist/tools/helpers/scan-cache.d.ts +22 -0
  81. package/dist/tools/helpers/scan-cache.js +34 -0
  82. package/dist/tools/helpers/scan-plan.d.ts +48 -0
  83. package/dist/tools/helpers/scan-plan.js +166 -0
  84. package/dist/tools/helpers/scope-paths.d.ts +17 -0
  85. package/dist/tools/helpers/scope-paths.js +32 -0
  86. package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
  87. package/dist/tools/helpers/stack-frame-file-index.js +71 -0
  88. package/dist/tools/helpers/tool-context.d.ts +60 -0
  89. package/dist/tools/helpers/tool-context.js +82 -0
  90. package/dist/tools/helpers/transform-safety.d.ts +40 -0
  91. package/dist/tools/helpers/transform-safety.js +87 -0
  92. package/dist/tools/helpers/validation-output.d.ts +53 -0
  93. package/dist/tools/helpers/validation-output.js +48 -0
  94. package/dist/tools/inspect-form-group.d.ts +324 -0
  95. package/dist/tools/inspect-form-group.js +279 -0
  96. package/dist/tools/inspect-i18n.d.ts +466 -0
  97. package/dist/tools/inspect-i18n.js +400 -0
  98. package/dist/tools/inspect-template.d.ts +320 -0
  99. package/dist/tools/inspect-template.js +324 -0
  100. package/dist/tools/learn-patterns.d.ts +122 -1
  101. package/dist/tools/learn-patterns.js +97 -2
  102. package/dist/tools/list-imports.d.ts +128 -11
  103. package/dist/tools/list-imports.js +128 -8
  104. package/dist/tools/orchestrate-migration.d.ts +129 -5
  105. package/dist/tools/orchestrate-migration.js +166 -12
  106. package/dist/tools/parse-stack-trace.d.ts +59 -2
  107. package/dist/tools/parse-stack-trace.js +52 -4
  108. package/dist/tools/plan-migration.d.ts +418 -1
  109. package/dist/tools/plan-migration.js +355 -8
  110. package/dist/tools/resolve-type.d.ts +42 -1
  111. package/dist/tools/resolve-type.js +37 -4
  112. package/dist/tools/review-feedback.d.ts +206 -11
  113. package/dist/tools/review-feedback.js +132 -51
  114. package/dist/tools/rollback-changes.d.ts +79 -2
  115. package/dist/tools/rollback-changes.js +66 -14
  116. package/dist/tools/run-angular-cli.d.ts +45 -2
  117. package/dist/tools/run-angular-cli.js +67 -7
  118. package/dist/tools/run-build.d.ts +114 -2
  119. package/dist/tools/run-build.js +117 -8
  120. package/dist/tools/run-schematic.d.ts +70 -2
  121. package/dist/tools/run-schematic.js +104 -10
  122. package/dist/tools/scan-all.d.ts +24 -16
  123. package/dist/tools/scan-all.js +145 -137
  124. package/dist/tools/scan-angular.d.ts +20 -11
  125. package/dist/tools/scan-angular.js +52 -24
  126. package/dist/tools/scan-architecture.d.ts +42 -14
  127. package/dist/tools/scan-architecture.js +206 -163
  128. package/dist/tools/scan-solid.d.ts +20 -11
  129. package/dist/tools/scan-solid.js +52 -24
  130. package/dist/tools/search-codebase.d.ts +85 -1
  131. package/dist/tools/search-codebase.js +61 -4
  132. package/dist/tools/server-status.d.ts +370 -0
  133. package/dist/tools/server-status.js +369 -0
  134. package/dist/tools/suggest-improvements.d.ts +97 -5
  135. package/dist/tools/suggest-improvements.js +80 -44
  136. package/dist/tools/trace-output-flow.d.ts +791 -0
  137. package/dist/tools/trace-output-flow.js +668 -0
  138. package/dist/tools/transform-code-batch.d.ts +3 -0
  139. package/dist/tools/transform-code-batch.js +10 -5
  140. package/dist/tools/transform-code.d.ts +335 -12
  141. package/dist/tools/transform-code.js +649 -608
  142. package/dist/tools/validate-before-transform.d.ts +116 -2
  143. package/dist/tools/validate-before-transform.js +55 -2
  144. package/dist/tools/validate-project-compatibility.d.ts +64 -2
  145. package/dist/tools/validate-project-compatibility.js +67 -4
  146. package/dist/tools/validate-transformation.d.ts +220 -2
  147. package/dist/tools/validate-transformation.js +113 -15
  148. package/dist/tools/verify-citations.d.ts +181 -0
  149. package/dist/tools/verify-citations.js +218 -0
  150. package/dist/types.d.ts +45 -1
  151. package/dist/utils/format-tool-response.d.ts +22 -59
  152. package/dist/utils/format-tool-response.js +25 -134
  153. package/package.json +30 -13
  154. package/dist/cli.d.ts.map +0 -1
  155. package/dist/cli.js.map +0 -1
  156. package/dist/core/project-analyzer.d.ts.map +0 -1
  157. package/dist/core/project-analyzer.js.map +0 -1
  158. package/dist/index.d.ts.map +0 -1
  159. package/dist/index.js.map +0 -1
  160. package/dist/mcp-watcher.d.ts.map +0 -1
  161. package/dist/mcp-watcher.js.map +0 -1
  162. package/dist/server/json-rpc-handler.d.ts +0 -57
  163. package/dist/server/json-rpc-handler.d.ts.map +0 -1
  164. package/dist/server/json-rpc-handler.js +0 -222
  165. package/dist/server/json-rpc-handler.js.map +0 -1
  166. package/dist/server/mcp-server.d.ts.map +0 -1
  167. package/dist/server/mcp-server.js.map +0 -1
  168. package/dist/server/tool-registry.d.ts.map +0 -1
  169. package/dist/server/tool-registry.js.map +0 -1
  170. package/dist/streaming/progress-store.d.ts.map +0 -1
  171. package/dist/streaming/progress-store.js.map +0 -1
  172. package/dist/tools/analyze-build-impact.d.ts.map +0 -1
  173. package/dist/tools/analyze-build-impact.js.map +0 -1
  174. package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
  175. package/dist/tools/analyze-core-to-shared.js.map +0 -1
  176. package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
  177. package/dist/tools/analyze-parser-performance.js.map +0 -1
  178. package/dist/tools/analyze-project.d.ts.map +0 -1
  179. package/dist/tools/analyze-project.js.map +0 -1
  180. package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
  181. package/dist/tools/check-incremental-compatibility.js.map +0 -1
  182. package/dist/tools/collect-feedback.d.ts.map +0 -1
  183. package/dist/tools/collect-feedback.js.map +0 -1
  184. package/dist/tools/extract-libraries.d.ts.map +0 -1
  185. package/dist/tools/extract-libraries.js.map +0 -1
  186. package/dist/tools/find-angular-symbol.d.ts.map +0 -1
  187. package/dist/tools/find-angular-symbol.js.map +0 -1
  188. package/dist/tools/find-usages.d.ts.map +0 -1
  189. package/dist/tools/find-usages.js.map +0 -1
  190. package/dist/tools/get-call-graph.d.ts.map +0 -1
  191. package/dist/tools/get-call-graph.js.map +0 -1
  192. package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
  193. package/dist/tools/get-operation-progress-tool.js.map +0 -1
  194. package/dist/tools/get-operation-progress.d.ts.map +0 -1
  195. package/dist/tools/get-operation-progress.js.map +0 -1
  196. package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
  197. package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
  198. package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
  199. package/dist/tools/helpers/find-ts-config.js.map +0 -1
  200. package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
  201. package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
  202. package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
  203. package/dist/tools/helpers/rule-matcher.js.map +0 -1
  204. package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
  205. package/dist/tools/helpers/suggestion-generator.js.map +0 -1
  206. package/dist/tools/learn-patterns.d.ts.map +0 -1
  207. package/dist/tools/learn-patterns.js.map +0 -1
  208. package/dist/tools/list-imports.d.ts.map +0 -1
  209. package/dist/tools/list-imports.js.map +0 -1
  210. package/dist/tools/orchestrate-migration.d.ts.map +0 -1
  211. package/dist/tools/orchestrate-migration.js.map +0 -1
  212. package/dist/tools/parse-stack-trace.d.ts.map +0 -1
  213. package/dist/tools/parse-stack-trace.js.map +0 -1
  214. package/dist/tools/plan-migration.d.ts.map +0 -1
  215. package/dist/tools/plan-migration.js.map +0 -1
  216. package/dist/tools/resolve-type.d.ts.map +0 -1
  217. package/dist/tools/resolve-type.js.map +0 -1
  218. package/dist/tools/review-feedback.d.ts.map +0 -1
  219. package/dist/tools/review-feedback.js.map +0 -1
  220. package/dist/tools/rollback-changes.d.ts.map +0 -1
  221. package/dist/tools/rollback-changes.js.map +0 -1
  222. package/dist/tools/run-angular-cli.d.ts.map +0 -1
  223. package/dist/tools/run-angular-cli.js.map +0 -1
  224. package/dist/tools/run-build.d.ts.map +0 -1
  225. package/dist/tools/run-build.js.map +0 -1
  226. package/dist/tools/run-schematic.d.ts.map +0 -1
  227. package/dist/tools/run-schematic.js.map +0 -1
  228. package/dist/tools/scan-all.d.ts.map +0 -1
  229. package/dist/tools/scan-all.js.map +0 -1
  230. package/dist/tools/scan-angular.d.ts.map +0 -1
  231. package/dist/tools/scan-angular.js.map +0 -1
  232. package/dist/tools/scan-architecture.d.ts.map +0 -1
  233. package/dist/tools/scan-architecture.js.map +0 -1
  234. package/dist/tools/scan-solid.d.ts.map +0 -1
  235. package/dist/tools/scan-solid.js.map +0 -1
  236. package/dist/tools/search-codebase.d.ts.map +0 -1
  237. package/dist/tools/search-codebase.js.map +0 -1
  238. package/dist/tools/shared/scan-types.d.ts.map +0 -1
  239. package/dist/tools/shared/scan-types.js.map +0 -1
  240. package/dist/tools/suggest-improvements.d.ts.map +0 -1
  241. package/dist/tools/suggest-improvements.js.map +0 -1
  242. package/dist/tools/transform-code-batch.d.ts.map +0 -1
  243. package/dist/tools/transform-code-batch.js.map +0 -1
  244. package/dist/tools/transform-code.d.ts.map +0 -1
  245. package/dist/tools/transform-code.js.map +0 -1
  246. package/dist/tools/validate-before-transform.d.ts.map +0 -1
  247. package/dist/tools/validate-before-transform.js.map +0 -1
  248. package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
  249. package/dist/tools/validate-project-compatibility.js.map +0 -1
  250. package/dist/tools/validate-transformation.d.ts.map +0 -1
  251. package/dist/tools/validate-transformation.js.map +0 -1
  252. package/dist/types.d.ts.map +0 -1
  253. package/dist/types.js.map +0 -1
  254. package/dist/utils/format-tool-response.d.ts.map +0 -1
  255. package/dist/utils/format-tool-response.js.map +0 -1
@@ -0,0 +1,320 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Inspect Template Tool
3
+ *
4
+ * MCP tool that returns the structure of an Angular component template:
5
+ * elements with their bindings, the project components/directives and
6
+ * pipes they resolve to, control-flow nesting and i18n keys.
7
+ *
8
+ * @remarks
9
+ * Logic lives in `TemplateInspector` (`@angular-modernizer/api`); this tool
10
+ * only resolves the project, validates arguments and applies the compact
11
+ * output contract. Accepts the `.html` template or the component `.ts` file.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Via MCP:
16
+ * // tool: inspect-template
17
+ * // args: { file: '/project/src/app/list/list.component.html', projectRoot: '/project' }
18
+ * ```
19
+ */
20
+ import { type MCPTool, type ToolAnnotations } from '../types.js';
21
+ import { type ComponentTemplateReport } from '@angular-modernizer/api';
22
+ import { ProjectCache } from './helpers/project-cache.js';
23
+ /** A report shaped by the compact options. */
24
+ type ListField = 'elements' | 'i18nKeys' | 'dynamicI18nPrefixes';
25
+ type TemplateReportOutput = Omit<ComponentTemplateReport, ListField> & Partial<Pick<ComponentTemplateReport, ListField>> & {
26
+ truncated: boolean;
27
+ };
28
+ /**
29
+ * Output of the inspect-template tool.
30
+ */
31
+ interface InspectTemplateOutput {
32
+ templates: TemplateReportOutput[];
33
+ summary: string;
34
+ tsConfigPath: string;
35
+ /** Conditions that can make the result incomplete (unresolved library imports). */
36
+ warnings?: string[];
37
+ }
38
+ /**
39
+ * MCP tool that inspects the structure of component templates.
40
+ */
41
+ export declare class InspectTemplateTool implements MCPTool {
42
+ private readonly projects;
43
+ readonly name = "inspect-template";
44
+ readonly title = "Inspect Template";
45
+ readonly annotations: ToolAnnotations;
46
+ constructor(projects?: ProjectCache);
47
+ readonly description: string;
48
+ readonly inputSchema: {
49
+ type: string;
50
+ additionalProperties: boolean;
51
+ properties: {
52
+ summaryOnly: {
53
+ readonly type: "boolean";
54
+ readonly description: "Return counts and the text summary only, without the result list. Default: false.";
55
+ readonly default: false;
56
+ };
57
+ maxResults: {
58
+ readonly type: "number";
59
+ readonly description: string;
60
+ };
61
+ file: {
62
+ type: string;
63
+ description: string;
64
+ };
65
+ projectRoot: {
66
+ type: string;
67
+ description: string;
68
+ };
69
+ className: {
70
+ type: string;
71
+ description: string;
72
+ };
73
+ includePlainElements: {
74
+ type: string;
75
+ description: string;
76
+ default: boolean;
77
+ };
78
+ i18nNames: {
79
+ type: string;
80
+ items: {
81
+ type: string;
82
+ };
83
+ description: string;
84
+ };
85
+ };
86
+ required: string[];
87
+ };
88
+ readonly outputSchema: {
89
+ type: string;
90
+ properties: {
91
+ warnings: {
92
+ readonly type: "array";
93
+ readonly items: {
94
+ readonly type: "string";
95
+ };
96
+ readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
97
+ };
98
+ templates: {
99
+ type: string;
100
+ items: {
101
+ readonly type: "object";
102
+ readonly properties: {
103
+ readonly component: {
104
+ readonly type: "string";
105
+ };
106
+ readonly componentFile: {
107
+ readonly type: "string";
108
+ };
109
+ readonly templateFile: {
110
+ readonly type: "string";
111
+ };
112
+ readonly inline: {
113
+ readonly type: "boolean";
114
+ };
115
+ readonly directives: {
116
+ readonly type: "array";
117
+ readonly items: {
118
+ readonly type: "object";
119
+ readonly properties: {
120
+ readonly className: {
121
+ readonly type: "string";
122
+ };
123
+ readonly kind: {
124
+ readonly type: "string";
125
+ };
126
+ readonly selector: {
127
+ readonly type: "string";
128
+ };
129
+ readonly file: {
130
+ readonly type: "string";
131
+ };
132
+ readonly count: {
133
+ readonly type: "integer";
134
+ };
135
+ };
136
+ readonly required: readonly ["className", "kind", "selector", "file", "count"];
137
+ };
138
+ };
139
+ readonly pipes: {
140
+ readonly type: "array";
141
+ readonly items: {
142
+ readonly type: "object";
143
+ readonly properties: {
144
+ readonly name: {
145
+ readonly type: "string";
146
+ };
147
+ readonly count: {
148
+ readonly type: "integer";
149
+ };
150
+ readonly className: {
151
+ readonly type: "string";
152
+ };
153
+ readonly file: {
154
+ readonly type: "string";
155
+ };
156
+ };
157
+ readonly required: readonly ["name", "count"];
158
+ };
159
+ };
160
+ readonly unresolvedElements: {
161
+ readonly type: "array";
162
+ readonly items: {
163
+ readonly type: "object";
164
+ readonly properties: {
165
+ readonly tag: {
166
+ readonly type: "string";
167
+ };
168
+ readonly count: {
169
+ readonly type: "integer";
170
+ };
171
+ };
172
+ readonly required: readonly ["tag", "count"];
173
+ };
174
+ };
175
+ readonly controlFlow: {
176
+ readonly type: "object";
177
+ readonly properties: {
178
+ readonly blocks: {
179
+ readonly type: "object";
180
+ readonly additionalProperties: {
181
+ readonly type: "integer";
182
+ };
183
+ };
184
+ readonly structuralDirectives: {
185
+ readonly type: "object";
186
+ readonly additionalProperties: {
187
+ readonly type: "integer";
188
+ };
189
+ };
190
+ readonly maxDepth: {
191
+ readonly type: "integer";
192
+ };
193
+ };
194
+ readonly required: readonly ["blocks", "structuralDirectives", "maxDepth"];
195
+ };
196
+ readonly dynamicI18nCount: {
197
+ readonly type: "integer";
198
+ };
199
+ readonly parseErrors: {
200
+ readonly type: "array";
201
+ readonly items: {
202
+ readonly type: "string";
203
+ };
204
+ };
205
+ readonly counts: {
206
+ readonly type: "object";
207
+ readonly properties: {
208
+ [k: string]: {
209
+ type: string;
210
+ };
211
+ };
212
+ readonly required: readonly ["elements", "bindings", "inputs", "outputs", "directives", "pipes", "i18nKeys"];
213
+ };
214
+ readonly elements: {
215
+ readonly type: "array";
216
+ readonly items: {
217
+ readonly type: "object";
218
+ readonly properties: {
219
+ readonly tag: {
220
+ readonly type: "string";
221
+ };
222
+ readonly line: {
223
+ readonly type: "integer";
224
+ };
225
+ readonly col: {
226
+ readonly type: "integer";
227
+ };
228
+ readonly depth: {
229
+ readonly type: "integer";
230
+ };
231
+ readonly matches: {
232
+ readonly type: "array";
233
+ readonly items: {
234
+ readonly type: "string";
235
+ };
236
+ };
237
+ readonly bindings: {
238
+ readonly type: "array";
239
+ readonly items: {
240
+ readonly type: "object";
241
+ readonly properties: {
242
+ readonly kind: {
243
+ readonly type: "string";
244
+ };
245
+ readonly name: {
246
+ readonly type: "string";
247
+ };
248
+ readonly value: {
249
+ readonly type: "string";
250
+ };
251
+ readonly line: {
252
+ readonly type: "integer";
253
+ };
254
+ };
255
+ readonly required: readonly ["kind", "name"];
256
+ };
257
+ };
258
+ };
259
+ readonly required: readonly ["tag", "line", "col", "depth", "matches", "bindings"];
260
+ };
261
+ };
262
+ readonly i18nKeys: {
263
+ readonly type: "array";
264
+ readonly items: {
265
+ readonly type: "object";
266
+ readonly properties: {
267
+ readonly key: {
268
+ readonly type: "string";
269
+ };
270
+ readonly source: {
271
+ readonly type: "string";
272
+ };
273
+ readonly line: {
274
+ readonly type: "integer";
275
+ };
276
+ };
277
+ readonly required: readonly ["key", "source", "line"];
278
+ };
279
+ };
280
+ readonly dynamicI18nPrefixes: {
281
+ readonly type: "array";
282
+ readonly items: {
283
+ readonly type: "object";
284
+ readonly properties: {
285
+ readonly prefix: {
286
+ readonly type: "string";
287
+ };
288
+ readonly source: {
289
+ readonly type: "string";
290
+ };
291
+ readonly line: {
292
+ readonly type: "integer";
293
+ };
294
+ };
295
+ readonly required: readonly ["prefix", "source", "line"];
296
+ };
297
+ };
298
+ readonly truncated: {
299
+ readonly type: "boolean";
300
+ };
301
+ };
302
+ readonly required: readonly ["component", "componentFile", "templateFile", "inline", "directives", "pipes", "unresolvedElements", "controlFlow", "dynamicI18nCount", "parseErrors", "counts", "truncated"];
303
+ };
304
+ };
305
+ summary: {
306
+ type: string;
307
+ };
308
+ tsConfigPath: {
309
+ type: string;
310
+ };
311
+ };
312
+ required: string[];
313
+ };
314
+ execute(args: Record<string, unknown>): Promise<InspectTemplateOutput>;
315
+ private parseI18nNames;
316
+ private shape;
317
+ private buildSummary;
318
+ }
319
+ export {};
320
+ //# sourceMappingURL=inspect-template.d.ts.map
@@ -0,0 +1,324 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Inspect Template Tool
3
+ *
4
+ * MCP tool that returns the structure of an Angular component template:
5
+ * elements with their bindings, the project components/directives and
6
+ * pipes they resolve to, control-flow nesting and i18n keys.
7
+ *
8
+ * @remarks
9
+ * Logic lives in `TemplateInspector` (`@angular-modernizer/api`); this tool
10
+ * only resolves the project, validates arguments and applies the compact
11
+ * output contract. Accepts the `.html` template or the component `.ts` file.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Via MCP:
16
+ * // tool: inspect-template
17
+ * // args: { file: '/project/src/app/list/list.component.html', projectRoot: '/project' }
18
+ * ```
19
+ */
20
+ import { TemplateInspector, } from '@angular-modernizer/api';
21
+ import { existsSync } from 'node:fs';
22
+ import { isAbsolute, resolve } from 'node:path';
23
+ import { findTsConfig } from './helpers/find-ts-config.js';
24
+ import { ProjectCache } from './helpers/project-cache.js';
25
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
26
+ import { configuredComponentDecorators } from './helpers/project-decorators.js';
27
+ import { WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
28
+ const COUNT_OBJECT = { type: 'object', additionalProperties: { type: 'integer' } };
29
+ const TEMPLATE_COUNT_KEYS = [
30
+ 'elements',
31
+ 'bindings',
32
+ 'inputs',
33
+ 'outputs',
34
+ 'directives',
35
+ 'pipes',
36
+ 'i18nKeys',
37
+ ];
38
+ /** Output schema of one template report. */
39
+ const TEMPLATE_REPORT_SCHEMA = {
40
+ type: 'object',
41
+ properties: {
42
+ component: { type: 'string' },
43
+ componentFile: { type: 'string' },
44
+ templateFile: { type: 'string' },
45
+ inline: { type: 'boolean' },
46
+ directives: {
47
+ type: 'array',
48
+ items: {
49
+ type: 'object',
50
+ properties: {
51
+ className: { type: 'string' },
52
+ kind: { type: 'string' },
53
+ selector: { type: 'string' },
54
+ file: { type: 'string' },
55
+ count: { type: 'integer' },
56
+ },
57
+ required: ['className', 'kind', 'selector', 'file', 'count'],
58
+ },
59
+ },
60
+ pipes: {
61
+ type: 'array',
62
+ items: {
63
+ type: 'object',
64
+ properties: {
65
+ name: { type: 'string' },
66
+ count: { type: 'integer' },
67
+ className: { type: 'string' },
68
+ file: { type: 'string' },
69
+ },
70
+ required: ['name', 'count'],
71
+ },
72
+ },
73
+ unresolvedElements: {
74
+ type: 'array',
75
+ items: {
76
+ type: 'object',
77
+ properties: { tag: { type: 'string' }, count: { type: 'integer' } },
78
+ required: ['tag', 'count'],
79
+ },
80
+ },
81
+ controlFlow: {
82
+ type: 'object',
83
+ properties: {
84
+ blocks: COUNT_OBJECT,
85
+ structuralDirectives: COUNT_OBJECT,
86
+ maxDepth: { type: 'integer' },
87
+ },
88
+ required: ['blocks', 'structuralDirectives', 'maxDepth'],
89
+ },
90
+ dynamicI18nCount: { type: 'integer' },
91
+ parseErrors: { type: 'array', items: { type: 'string' } },
92
+ counts: {
93
+ type: 'object',
94
+ properties: Object.fromEntries(TEMPLATE_COUNT_KEYS.map((k) => [k, { type: 'integer' }])),
95
+ required: [...TEMPLATE_COUNT_KEYS],
96
+ },
97
+ elements: {
98
+ type: 'array',
99
+ items: {
100
+ type: 'object',
101
+ properties: {
102
+ tag: { type: 'string' },
103
+ line: { type: 'integer' },
104
+ col: { type: 'integer' },
105
+ depth: { type: 'integer' },
106
+ matches: { type: 'array', items: { type: 'string' } },
107
+ bindings: {
108
+ type: 'array',
109
+ items: {
110
+ type: 'object',
111
+ properties: {
112
+ kind: { type: 'string' },
113
+ name: { type: 'string' },
114
+ value: { type: 'string' },
115
+ line: { type: 'integer' },
116
+ },
117
+ required: ['kind', 'name'],
118
+ },
119
+ },
120
+ },
121
+ required: ['tag', 'line', 'col', 'depth', 'matches', 'bindings'],
122
+ },
123
+ },
124
+ i18nKeys: {
125
+ type: 'array',
126
+ items: {
127
+ type: 'object',
128
+ properties: {
129
+ key: { type: 'string' },
130
+ source: { type: 'string' },
131
+ line: { type: 'integer' },
132
+ },
133
+ required: ['key', 'source', 'line'],
134
+ },
135
+ },
136
+ dynamicI18nPrefixes: {
137
+ type: 'array',
138
+ items: {
139
+ type: 'object',
140
+ properties: {
141
+ prefix: { type: 'string' },
142
+ source: { type: 'string' },
143
+ line: { type: 'integer' },
144
+ },
145
+ required: ['prefix', 'source', 'line'],
146
+ },
147
+ },
148
+ truncated: { type: 'boolean' },
149
+ },
150
+ required: [
151
+ 'component',
152
+ 'componentFile',
153
+ 'templateFile',
154
+ 'inline',
155
+ 'directives',
156
+ 'pipes',
157
+ 'unresolvedElements',
158
+ 'controlFlow',
159
+ 'dynamicI18nCount',
160
+ 'parseErrors',
161
+ 'counts',
162
+ 'truncated',
163
+ ],
164
+ };
165
+ /**
166
+ * MCP tool that inspects the structure of component templates.
167
+ */
168
+ export class InspectTemplateTool {
169
+ projects;
170
+ name = 'inspect-template';
171
+ title = 'Inspect Template';
172
+ annotations = {
173
+ readOnlyHint: true,
174
+ destructiveHint: false,
175
+ idempotentHint: true,
176
+ openWorldHint: false,
177
+ };
178
+ constructor(projects = new ProjectCache()) {
179
+ this.projects = projects;
180
+ }
181
+ description = 'Inspect an Angular component template (.html file, or the component .ts for inline templates). ' +
182
+ 'Per element: tag, line, control-flow depth, bindings (input, output, two-way, attribute, ' +
183
+ 'structural, reference with their expressions) and the project components/directives whose ' +
184
+ 'selector matches it. Per template: components/directives used (with files), pipes (resolved to ' +
185
+ 'project pipe classes when declared in the project), custom elements without a project match ' +
186
+ '(library components), control-flow blocks, structural directives and max nesting depth, and ' +
187
+ 'static i18n keys (translate pipe/directive, i18n="@@id"), plus the static prefixes of dynamic ' +
188
+ "keys ('A.' + x, `A.${x}`) in dynamicI18nPrefixes (definitions and project-wide usages of a key: " +
189
+ 'inspect-i18n). Plain elements without bindings are ' +
190
+ 'omitted unless includePlainElements; counts always cover all elements. summaryOnly drops the ' +
191
+ 'element, key and prefix lists, maxResults caps them.';
192
+ inputSchema = {
193
+ type: 'object',
194
+ additionalProperties: false,
195
+ properties: {
196
+ file: {
197
+ type: 'string',
198
+ description: 'Template .html file or component .ts file (absolute, or relative to projectRoot).',
199
+ },
200
+ projectRoot: {
201
+ type: 'string',
202
+ description: 'Absolute path to the project root. Must contain a tsconfig.json.',
203
+ },
204
+ className: {
205
+ type: 'string',
206
+ description: 'Only inspect this component class of a .ts file. Optional.',
207
+ },
208
+ includePlainElements: {
209
+ type: 'boolean',
210
+ description: 'Also list elements without bindings, references or directive matches. Default: false.',
211
+ default: false,
212
+ },
213
+ i18nNames: {
214
+ type: 'array',
215
+ items: { type: 'string' },
216
+ description: 'Pipe and directive names that take a translation key. Default: ["translate", "transloco"].',
217
+ },
218
+ ...COMPACT_OUTPUT_SCHEMA,
219
+ },
220
+ required: ['file', 'projectRoot'],
221
+ };
222
+ outputSchema = {
223
+ type: 'object',
224
+ properties: {
225
+ templates: { type: 'array', items: TEMPLATE_REPORT_SCHEMA },
226
+ summary: { type: 'string' },
227
+ tsConfigPath: { type: 'string' },
228
+ ...WARNINGS_OUTPUT_SCHEMA,
229
+ },
230
+ required: ['templates', 'summary', 'tsConfigPath'],
231
+ };
232
+ async execute(args) {
233
+ const params = args;
234
+ if (!params.file || typeof params.file !== 'string') {
235
+ throw new Error('file is required');
236
+ }
237
+ if (!params.projectRoot) {
238
+ throw new Error('projectRoot is required');
239
+ }
240
+ const compact = parseCompactOptions(args);
241
+ const i18nNames = this.parseI18nNames(params.i18nNames);
242
+ if (!existsSync(params.projectRoot)) {
243
+ throw new Error(`projectRoot does not exist: ${params.projectRoot}`);
244
+ }
245
+ const filePath = isAbsolute(params.file)
246
+ ? params.file
247
+ : resolve(params.projectRoot, params.file);
248
+ if (!existsSync(filePath)) {
249
+ throw new Error(`file does not exist: ${filePath}`);
250
+ }
251
+ const tsConfigPath = findTsConfig(params.projectRoot);
252
+ if (!tsConfigPath) {
253
+ throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
254
+ }
255
+ const project = this.projects.get(tsConfigPath);
256
+ if (!filePath.endsWith('.html') && !project.getSourceFile(filePath)) {
257
+ throw new Error(`file is not part of the tsconfig program: ${filePath}`);
258
+ }
259
+ const inspector = new TemplateInspector(project, {
260
+ componentDecorators: configuredComponentDecorators(params.projectRoot),
261
+ includePlainElements: params.includePlainElements === true,
262
+ ...(i18nNames === undefined ? {} : { i18nNames }),
263
+ });
264
+ const reports = inspector.inspectFile(filePath, params.className);
265
+ return withWarnings({
266
+ templates: reports.map((r) => this.shape(r, compact.summaryOnly, compact.maxResults)),
267
+ summary: this.buildSummary(filePath, reports),
268
+ tsConfigPath,
269
+ }, this.projects.warnings(tsConfigPath));
270
+ }
271
+ parseI18nNames(value) {
272
+ if (value === undefined) {
273
+ return undefined;
274
+ }
275
+ const valid = Array.isArray(value) && value.every((v) => typeof v === 'string');
276
+ if (!valid) {
277
+ throw new Error('i18nNames must be an array of strings');
278
+ }
279
+ return value;
280
+ }
281
+ shape(report, summaryOnly, maxResults) {
282
+ const { elements, i18nKeys, dynamicI18nPrefixes, ...rest } = report;
283
+ if (summaryOnly) {
284
+ return { ...rest, truncated: false };
285
+ }
286
+ const shownElements = limitList(elements, maxResults);
287
+ const shownKeys = limitList(i18nKeys, maxResults);
288
+ const shownPrefixes = limitList(dynamicI18nPrefixes, maxResults);
289
+ return {
290
+ ...rest,
291
+ elements: shownElements.items,
292
+ i18nKeys: shownKeys.items,
293
+ dynamicI18nPrefixes: shownPrefixes.items,
294
+ truncated: shownElements.truncated || shownKeys.truncated || shownPrefixes.truncated,
295
+ };
296
+ }
297
+ buildSummary(filePath, reports) {
298
+ if (reports.length === 0) {
299
+ return (`No component template found for ${filePath}. For an .html file no component in the ` +
300
+ 'program declares it as templateUrl; for a .ts file no class has a template or templateUrl.');
301
+ }
302
+ return reports
303
+ .map((r) => {
304
+ const c = r.counts;
305
+ const flow = r.controlFlow;
306
+ const blocks = Object.entries(flow.blocks)
307
+ .concat(Object.entries(flow.structuralDirectives).map(([n, k]) => [`*${n}`, k]))
308
+ .map(([n, k]) => `${n} ${k}`)
309
+ .join(', ');
310
+ const unresolved = r.unresolvedElements.map((u) => u.tag).join(', ');
311
+ return [
312
+ `${r.component} (${r.templateFile}${r.inline ? ', inline' : ''}): ${c.elements} elements, ` +
313
+ `${c.bindings} bindings (${c.inputs} in, ${c.outputs} out), ${c.directives} project ` +
314
+ `components/directives, ${c.pipes} pipes, ${c.i18nKeys} i18n keys` +
315
+ (r.dynamicI18nCount > 0 ? ` (+${r.dynamicI18nCount} dynamic)` : '') +
316
+ `, max depth ${flow.maxDepth}${blocks ? ` (${blocks})` : ''}.`,
317
+ ...(unresolved ? [` Not in project: ${unresolved}.`] : []),
318
+ ...(r.parseErrors.length > 0 ? [` ${r.parseErrors.length} parse error(s).`] : []),
319
+ ].join('\n');
320
+ })
321
+ .join('\n');
322
+ }
323
+ }
324
+ //# sourceMappingURL=inspect-template.js.map