@angular-modernizer/adapter-mcp 0.1.4 → 0.3.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 (152) hide show
  1. package/README.md +125 -35
  2. package/dist/cli.js +65 -13
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.d.ts +8 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +8 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp-watcher.d.ts.map +1 -1
  9. package/dist/mcp-watcher.js +3 -0
  10. package/dist/mcp-watcher.js.map +1 -1
  11. package/dist/server/json-rpc-handler.d.ts +41 -0
  12. package/dist/server/json-rpc-handler.d.ts.map +1 -1
  13. package/dist/server/json-rpc-handler.js +85 -6
  14. package/dist/server/json-rpc-handler.js.map +1 -1
  15. package/dist/server/mcp-server.d.ts +31 -0
  16. package/dist/server/mcp-server.d.ts.map +1 -1
  17. package/dist/server/mcp-server.js +76 -23
  18. package/dist/server/mcp-server.js.map +1 -1
  19. package/dist/server/stdio-guard.d.ts +20 -0
  20. package/dist/server/stdio-guard.d.ts.map +1 -0
  21. package/dist/server/stdio-guard.js +48 -0
  22. package/dist/server/stdio-guard.js.map +1 -0
  23. package/dist/tools/analyze-build-impact.d.ts +169 -12
  24. package/dist/tools/analyze-build-impact.d.ts.map +1 -1
  25. package/dist/tools/analyze-build-impact.js +221 -36
  26. package/dist/tools/analyze-build-impact.js.map +1 -1
  27. package/dist/tools/analyze-parser-performance.d.ts.map +1 -1
  28. package/dist/tools/analyze-parser-performance.js +6 -4
  29. package/dist/tools/analyze-parser-performance.js.map +1 -1
  30. package/dist/tools/collect-feedback.d.ts +112 -1
  31. package/dist/tools/collect-feedback.d.ts.map +1 -1
  32. package/dist/tools/collect-feedback.js +240 -11
  33. package/dist/tools/collect-feedback.js.map +1 -1
  34. package/dist/tools/extract-libraries.d.ts +4 -0
  35. package/dist/tools/extract-libraries.d.ts.map +1 -1
  36. package/dist/tools/extract-libraries.js +40 -8
  37. package/dist/tools/extract-libraries.js.map +1 -1
  38. package/dist/tools/find-angular-symbol.d.ts +29 -6
  39. package/dist/tools/find-angular-symbol.d.ts.map +1 -1
  40. package/dist/tools/find-angular-symbol.js +51 -6
  41. package/dist/tools/find-angular-symbol.js.map +1 -1
  42. package/dist/tools/find-component-hosts.d.ts +114 -0
  43. package/dist/tools/find-component-hosts.d.ts.map +1 -0
  44. package/dist/tools/find-component-hosts.js +240 -0
  45. package/dist/tools/find-component-hosts.js.map +1 -0
  46. package/dist/tools/find-usages.d.ts +33 -4
  47. package/dist/tools/find-usages.d.ts.map +1 -1
  48. package/dist/tools/find-usages.js +102 -11
  49. package/dist/tools/find-usages.js.map +1 -1
  50. package/dist/tools/get-bootstrap-execution.d.ts +108 -0
  51. package/dist/tools/get-bootstrap-execution.d.ts.map +1 -0
  52. package/dist/tools/get-bootstrap-execution.js +243 -0
  53. package/dist/tools/get-bootstrap-execution.js.map +1 -0
  54. package/dist/tools/get-call-graph.d.ts +33 -4
  55. package/dist/tools/get-call-graph.d.ts.map +1 -1
  56. package/dist/tools/get-call-graph.js +76 -13
  57. package/dist/tools/get-call-graph.js.map +1 -1
  58. package/dist/tools/helpers/compact-output.d.ts +61 -0
  59. package/dist/tools/helpers/compact-output.d.ts.map +1 -0
  60. package/dist/tools/helpers/compact-output.js +83 -0
  61. package/dist/tools/helpers/compact-output.js.map +1 -0
  62. package/dist/tools/helpers/find-ts-config.d.ts +24 -1
  63. package/dist/tools/helpers/find-ts-config.d.ts.map +1 -1
  64. package/dist/tools/helpers/find-ts-config.js +213 -7
  65. package/dist/tools/helpers/find-ts-config.js.map +1 -1
  66. package/dist/tools/helpers/project-cache.d.ts +177 -0
  67. package/dist/tools/helpers/project-cache.d.ts.map +1 -0
  68. package/dist/tools/helpers/project-cache.js +313 -0
  69. package/dist/tools/helpers/project-cache.js.map +1 -0
  70. package/dist/tools/helpers/rule-runner.d.ts +67 -0
  71. package/dist/tools/helpers/rule-runner.d.ts.map +1 -0
  72. package/dist/tools/helpers/rule-runner.js +117 -0
  73. package/dist/tools/helpers/rule-runner.js.map +1 -0
  74. package/dist/tools/helpers/scan-plan.d.ts +45 -0
  75. package/dist/tools/helpers/scan-plan.d.ts.map +1 -0
  76. package/dist/tools/helpers/scan-plan.js +151 -0
  77. package/dist/tools/helpers/scan-plan.js.map +1 -0
  78. package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
  79. package/dist/tools/helpers/stack-frame-file-index.d.ts.map +1 -0
  80. package/dist/tools/helpers/stack-frame-file-index.js +71 -0
  81. package/dist/tools/helpers/stack-frame-file-index.js.map +1 -0
  82. package/dist/tools/helpers/suggestion-generator.d.ts +1 -1
  83. package/dist/tools/helpers/suggestion-generator.d.ts.map +1 -1
  84. package/dist/tools/helpers/suggestion-generator.js.map +1 -1
  85. package/dist/tools/inspect-form-group.d.ts +93 -0
  86. package/dist/tools/inspect-form-group.d.ts.map +1 -0
  87. package/dist/tools/inspect-form-group.js +161 -0
  88. package/dist/tools/inspect-form-group.js.map +1 -0
  89. package/dist/tools/inspect-i18n.d.ts +85 -0
  90. package/dist/tools/inspect-i18n.d.ts.map +1 -0
  91. package/dist/tools/inspect-i18n.js +203 -0
  92. package/dist/tools/inspect-i18n.js.map +1 -0
  93. package/dist/tools/inspect-template.d.ts +89 -0
  94. package/dist/tools/inspect-template.d.ts.map +1 -0
  95. package/dist/tools/inspect-template.js +166 -0
  96. package/dist/tools/inspect-template.js.map +1 -0
  97. package/dist/tools/list-imports.d.ts +119 -0
  98. package/dist/tools/list-imports.d.ts.map +1 -0
  99. package/dist/tools/list-imports.js +171 -0
  100. package/dist/tools/list-imports.js.map +1 -0
  101. package/dist/tools/orchestrate-migration.d.ts +1 -0
  102. package/dist/tools/orchestrate-migration.d.ts.map +1 -1
  103. package/dist/tools/orchestrate-migration.js +33 -1
  104. package/dist/tools/orchestrate-migration.js.map +1 -1
  105. package/dist/tools/parse-stack-trace.d.ts +3 -1
  106. package/dist/tools/parse-stack-trace.d.ts.map +1 -1
  107. package/dist/tools/parse-stack-trace.js +18 -4
  108. package/dist/tools/parse-stack-trace.js.map +1 -1
  109. package/dist/tools/plan-migration.d.ts +89 -1
  110. package/dist/tools/plan-migration.d.ts.map +1 -1
  111. package/dist/tools/plan-migration.js +203 -7
  112. package/dist/tools/plan-migration.js.map +1 -1
  113. package/dist/tools/resolve-type.d.ts +3 -0
  114. package/dist/tools/resolve-type.d.ts.map +1 -1
  115. package/dist/tools/resolve-type.js +6 -2
  116. package/dist/tools/resolve-type.js.map +1 -1
  117. package/dist/tools/review-feedback.d.ts +7 -0
  118. package/dist/tools/review-feedback.d.ts.map +1 -1
  119. package/dist/tools/review-feedback.js +68 -16
  120. package/dist/tools/review-feedback.js.map +1 -1
  121. package/dist/tools/scan-all.d.ts +6 -6
  122. package/dist/tools/scan-all.d.ts.map +1 -1
  123. package/dist/tools/scan-all.js +7 -7
  124. package/dist/tools/scan-all.js.map +1 -1
  125. package/dist/tools/scan-angular.d.ts +1 -1
  126. package/dist/tools/scan-angular.js +1 -1
  127. package/dist/tools/scan-architecture.d.ts +25 -4
  128. package/dist/tools/scan-architecture.d.ts.map +1 -1
  129. package/dist/tools/scan-architecture.js +115 -134
  130. package/dist/tools/scan-architecture.js.map +1 -1
  131. package/dist/tools/scan-solid.d.ts +1 -1
  132. package/dist/tools/scan-solid.js +1 -1
  133. package/dist/tools/search-codebase.d.ts +32 -6
  134. package/dist/tools/search-codebase.d.ts.map +1 -1
  135. package/dist/tools/search-codebase.js +60 -14
  136. package/dist/tools/search-codebase.js.map +1 -1
  137. package/dist/tools/server-status.d.ts +96 -0
  138. package/dist/tools/server-status.d.ts.map +1 -0
  139. package/dist/tools/server-status.js +195 -0
  140. package/dist/tools/server-status.js.map +1 -0
  141. package/dist/tools/suggest-improvements.d.ts +3 -1
  142. package/dist/tools/suggest-improvements.d.ts.map +1 -1
  143. package/dist/tools/suggest-improvements.js +47 -10
  144. package/dist/tools/suggest-improvements.js.map +1 -1
  145. package/dist/tools/trace-output-flow.d.ts +111 -0
  146. package/dist/tools/trace-output-flow.d.ts.map +1 -0
  147. package/dist/tools/trace-output-flow.js +308 -0
  148. package/dist/tools/trace-output-flow.js.map +1 -0
  149. package/dist/types.d.ts +7 -0
  150. package/dist/types.d.ts.map +1 -1
  151. package/dist/types.js.map +1 -1
  152. package/package.json +13 -12
@@ -0,0 +1,243 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Get Bootstrap Execution Tool
3
+ *
4
+ * MCP tool that lists what an Angular app runs at startup (initializers,
5
+ * bootstrap component/module), on the first HTTP request (interceptors) and
6
+ * on first injection (provider factories), including everything reached
7
+ * through calls and dependency injection, and where a watched expression
8
+ * such as `AppConfig.settings` is read or written on the way.
9
+ *
10
+ * @remarks
11
+ * Logic lives in `BootstrapExecutionAnalyzer` (`@angular-modernizer/api`);
12
+ * this tool resolves the project, validates arguments and applies the
13
+ * compact output contract.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Via MCP:
18
+ * // tool: get-bootstrap-execution
19
+ * // args: { projectRoot: '/project', watch: ['AppConfig.settings'], summaryOnly: true }
20
+ * ```
21
+ */
22
+ import { BootstrapExecutionAnalyzer, normalizeWatchExpression, } from '@angular-modernizer/api';
23
+ import { existsSync } from 'node:fs';
24
+ import { isAbsolute, relative, resolve } from 'node:path';
25
+ import { findTsConfig } from './helpers/find-ts-config.js';
26
+ import { ProjectCache } from './helpers/project-cache.js';
27
+ import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
28
+ const TIMINGS = [
29
+ 'initializer',
30
+ 'bootstrap',
31
+ 'first-http-request',
32
+ 'first-injection',
33
+ 'custom',
34
+ ];
35
+ /** Watched access sites listed in the text summary. */
36
+ const SUMMARY_MAX_SITES = 10;
37
+ /**
38
+ * Summary order: accesses that can run before the app is fully initialized
39
+ * first (initializers, and interceptors an initializer may construct).
40
+ */
41
+ const TIMING_RANK = {
42
+ initializer: 0,
43
+ 'first-http-request': 1,
44
+ custom: 2,
45
+ 'first-injection': 3,
46
+ bootstrap: 4,
47
+ };
48
+ function earliestFirst(a, b) {
49
+ return TIMING_RANK[a.timing] - TIMING_RANK[b.timing] || a.path.length - b.path.length;
50
+ }
51
+ function positiveInteger(value, name) {
52
+ if (value === undefined) {
53
+ return undefined;
54
+ }
55
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
56
+ throw new Error(`${name} must be a positive integer`);
57
+ }
58
+ return value;
59
+ }
60
+ function stringList(value, name) {
61
+ if (value === undefined) {
62
+ return undefined;
63
+ }
64
+ const valid = Array.isArray(value) && value.every((v) => typeof v === 'string');
65
+ if (!valid) {
66
+ throw new Error(`${name} must be an array of strings`);
67
+ }
68
+ return value;
69
+ }
70
+ /**
71
+ * MCP tool that reports what runs at application startup.
72
+ */
73
+ export class GetBootstrapExecutionTool {
74
+ projects;
75
+ name = 'get-bootstrap-execution';
76
+ constructor(projects = new ProjectCache()) {
77
+ this.projects = projects;
78
+ }
79
+ description = 'List what an Angular app executes at startup and whether it touches a given expression. Roots: ' +
80
+ 'provideAppInitializer/provideEnvironmentInitializer/providePlatformInitializer and APP_INITIALIZER-style ' +
81
+ 'provider literals (timing "initializer", finish before "bootstrap"), bootstrapApplication/bootstrapModule ' +
82
+ '("bootstrap"), HTTP_INTERCEPTORS classes and withInterceptors functions ("first-http-request", can happen ' +
83
+ 'inside an initializer that uses HttpClient), other useFactory providers ("first-injection"). From each root ' +
84
+ 'it walks calls (incl. constructors, field initializers, getters) and DI: inject(X), constructor parameters, ' +
85
+ '@Inject(TOKEN) and factory deps, with tokens resolved to the providers registered in the project. watch ' +
86
+ '(e.g. ["AppConfig.settings"]) reports every reachable read/write with the call path from the root, which ' +
87
+ 'catches reads hidden behind constructors and getters that search-codebase cannot see. method + file start ' +
88
+ 'from one callable instead (e.g. "AuthInterceptor.constructor"). Roots are found by scanning source files, ' +
89
+ 'not by evaluating which providers are registered; spec files are skipped. Start with summaryOnly; ' +
90
+ 'maxResults caps the reached list per root and the watch hits.';
91
+ inputSchema = {
92
+ type: 'object',
93
+ properties: {
94
+ projectRoot: {
95
+ type: 'string',
96
+ description: 'Absolute path to the project root. Must contain a tsconfig.json.',
97
+ },
98
+ watch: {
99
+ type: 'array',
100
+ items: { type: 'string' },
101
+ description: 'Expressions whose reads and writes to report, matched by text (optional chaining ignored), e.g. ["AppConfig.settings"].',
102
+ },
103
+ timings: {
104
+ type: 'array',
105
+ items: { type: 'string', enum: [...TIMINGS] },
106
+ description: 'Only roots with these timings. Default: all.',
107
+ },
108
+ file: {
109
+ type: 'string',
110
+ description: 'Only roots registered in this file; with method, the file declaring it (absolute, or relative to projectRoot).',
111
+ },
112
+ method: {
113
+ type: 'string',
114
+ description: 'Start from this callable instead of the discovered roots: "Class.constructor", "Class.member" or a function name. Needs file.',
115
+ },
116
+ depth: {
117
+ type: 'number',
118
+ description: 'Maximum call/injection distance from a root. Default: 8.',
119
+ },
120
+ maxNodes: {
121
+ type: 'number',
122
+ description: 'Maximum callables walked per root; a capped root is marked truncated. Default: 300.',
123
+ },
124
+ includeReached: {
125
+ type: 'boolean',
126
+ description: 'Include the reached callables per root. Default: true.',
127
+ default: true,
128
+ },
129
+ ...COMPACT_OUTPUT_SCHEMA,
130
+ },
131
+ required: ['projectRoot'],
132
+ };
133
+ async execute(args) {
134
+ const params = args;
135
+ if (!params.projectRoot) {
136
+ throw new Error('projectRoot is required');
137
+ }
138
+ const compact = parseCompactOptions(args);
139
+ const watch = stringList(params.watch, 'watch');
140
+ const timings = stringList(params.timings, 'timings');
141
+ const unknownTiming = timings?.find((t) => !TIMINGS.includes(t));
142
+ if (unknownTiming !== undefined) {
143
+ throw new Error(`unknown timing: ${unknownTiming}`);
144
+ }
145
+ const depth = positiveInteger(params.depth, 'depth');
146
+ const maxNodes = positiveInteger(params.maxNodes, 'maxNodes');
147
+ if (params.method !== undefined && params.file === undefined) {
148
+ throw new Error('method needs file');
149
+ }
150
+ if (!existsSync(params.projectRoot)) {
151
+ throw new Error(`projectRoot does not exist: ${params.projectRoot}`);
152
+ }
153
+ const tsConfigPath = findTsConfig(params.projectRoot);
154
+ if (!tsConfigPath) {
155
+ throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
156
+ }
157
+ const file = params.file === undefined || isAbsolute(params.file)
158
+ ? params.file
159
+ : resolve(params.projectRoot, params.file);
160
+ const result = new BootstrapExecutionAnalyzer(this.projects.get(tsConfigPath)).analyze({
161
+ ...(watch === undefined ? {} : { watch }),
162
+ ...(timings === undefined ? {} : { timings: timings }),
163
+ ...(file === undefined ? {} : { file }),
164
+ ...(params.method === undefined ? {} : { method: params.method }),
165
+ ...(depth === undefined ? {} : { depth }),
166
+ ...(maxNodes === undefined ? {} : { maxNodes }),
167
+ });
168
+ const summary = this.buildSummary(result, params.projectRoot, watch ?? [], params.method);
169
+ if (compact.summaryOnly) {
170
+ return { counts: result.counts, truncated: false, summary, tsConfigPath };
171
+ }
172
+ const includeReached = params.includeReached !== false;
173
+ let truncated = false;
174
+ const roots = result.roots.map((root) => {
175
+ const { reached, ...rest } = root;
176
+ if (!includeReached) {
177
+ return { ...rest, reachedCount: reached.length };
178
+ }
179
+ const shown = limitList(reached, compact.maxResults);
180
+ truncated ||= shown.truncated;
181
+ return { ...rest, reached: shown.items, reachedCount: reached.length };
182
+ });
183
+ const hits = limitList(result.watchHits, compact.maxResults);
184
+ truncated ||= hits.truncated;
185
+ return {
186
+ roots,
187
+ watchHits: hits.items,
188
+ counts: result.counts,
189
+ truncated,
190
+ summary,
191
+ tsConfigPath,
192
+ };
193
+ }
194
+ buildSummary(result, projectRoot, watch, method) {
195
+ if (result.roots.length === 0) {
196
+ return method !== undefined
197
+ ? `Callable '${method}' not found in the given file.`
198
+ : 'No bootstrap roots found (no initializers, bootstrapApplication/bootstrapModule, interceptors or factory providers in the tsconfig program).';
199
+ }
200
+ const rel = (f) => relative(projectRoot, f);
201
+ const timings = Object.entries(result.counts.rootsByTiming)
202
+ .map(([t, n]) => `${t} ${n}`)
203
+ .join(', ');
204
+ const lines = [
205
+ `${result.counts.roots} root(s) (${timings}), ${result.counts.reached} callables reached` +
206
+ (result.counts.truncatedRoots > 0 ? `, ${result.counts.truncatedRoots} root(s) truncated by maxNodes` : '') +
207
+ '.',
208
+ ];
209
+ for (const expression of watch) {
210
+ const hits = result.watchHits.filter((h) => h.watch === normalizeWatchExpression(expression));
211
+ if (hits.length === 0) {
212
+ lines.push(`${expression}: not accessed from any root.`);
213
+ continue;
214
+ }
215
+ const sites = new Map();
216
+ for (const h of [...hits].sort(earliestFirst)) {
217
+ const key = `${rel(h.file)}:${h.line}`;
218
+ sites.set(key, [...(sites.get(key) ?? []), h]);
219
+ }
220
+ const early = hits.filter((h) => h.timing === 'initializer' || h.timing === 'first-http-request');
221
+ lines.push(`${expression}: ${sites.size} access site(s) reachable, ${early.length} path(s) from initializer or interceptor roots.`);
222
+ const ordered = [...sites].sort(([, a], [, b]) => {
223
+ const [firstA] = a;
224
+ const [firstB] = b;
225
+ return firstA === undefined || firstB === undefined ? 0 : earliestFirst(firstA, firstB);
226
+ });
227
+ for (const [site, siteHits] of ordered.slice(0, SUMMARY_MAX_SITES)) {
228
+ const first = siteHits[0];
229
+ if (first === undefined) {
230
+ continue;
231
+ }
232
+ const roots = [...new Set(siteHits.map((h) => h.timing))].join('/');
233
+ // siteHits is sorted earliest first, so this is the path that runs soonest.
234
+ lines.push(` ${first.access} ${site} [${roots}] via ${first.path.join(' > ')}`);
235
+ }
236
+ if (sites.size > SUMMARY_MAX_SITES) {
237
+ lines.push(` ... ${sites.size - SUMMARY_MAX_SITES} more site(s) in watchHits`);
238
+ }
239
+ }
240
+ return lines.join('\n');
241
+ }
242
+ }
243
+ //# sourceMappingURL=get-bootstrap-execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-bootstrap-execution.js","sourceRoot":"","sources":["../../src/tools/get-bootstrap-execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC1F,CAAC,CAAC,CAAC;YACH,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,EAAE,CAAC;gBACnE,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACxB,SAAS;gBACX,CAAC;gBACD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACpE,4EAA4E;gBAC5E,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,KAAK,KAAK,SAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACnF,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,GAAG,iBAAiB,EAAE,CAAC;gBACnC,KAAK,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,IAAI,GAAG,iBAAiB,4BAA4B,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @angular-modernizer/adapter-mcp - Get Call Graph Tool
3
3
  *
4
- * MCP tool for building a caller/callee graph for a named method or function.
4
+ * MCP tool for building a caller/callee graph for a named method, function,
5
+ * constructor, get/set accessor or arrow-function property.
5
6
  * Supports configurable traversal direction and depth.
6
7
  *
7
8
  * @remarks
@@ -9,20 +10,34 @@
9
10
  * propagates through the call hierarchy. Useful for determining blast radius
10
11
  * before proposing a bug fix.
11
12
  *
13
+ * The graph is capped at `maxNodes` (default 200); a capped result carries
14
+ * `truncated: true` and a hint in the summary. Callers are not expanded
15
+ * through lifecycle hooks or interface members of foreign classes unless
16
+ * `includeLifecycleHooks` is set. Projects are cached per tsconfig.
17
+ *
12
18
  * @example
13
19
  * ```typescript
14
20
  * // Via MCP:
15
21
  * // tool: get-call-graph
16
22
  * // args: { method: 'getUser', file: '/project/src/app/user.service.ts', projectRoot: '/project' }
23
+ * // args: { method: 'AuthInterceptor.constructor', file: '/project/src/app/auth.interceptor.ts',
24
+ * // projectRoot: '/project', direction: 'down', depth: 4 }
17
25
  * ```
18
26
  */
19
27
  import { type MCPTool } from '../types.js';
20
28
  import { type CallGraphResult } from '@angular-modernizer/api';
29
+ import { ProjectCache } from './helpers/project-cache.js';
30
+ /** Tool output: the call graph (trees omitted with `summaryOnly`) plus a text summary. */
31
+ export type GetCallGraphOutput = Omit<CallGraphResult, 'callers' | 'callees'> & Partial<Pick<CallGraphResult, 'callers' | 'callees'>> & {
32
+ summary: string;
33
+ };
21
34
  /**
22
35
  * MCP tool that builds a call graph for a named method or function.
23
36
  */
24
37
  export declare class GetCallGraphTool implements MCPTool {
38
+ private readonly projects;
25
39
  readonly name = "get-call-graph";
40
+ constructor(projects?: ProjectCache);
26
41
  readonly description: string;
27
42
  readonly inputSchema: {
28
43
  type: string;
@@ -50,12 +65,26 @@ export declare class GetCallGraphTool implements MCPTool {
50
65
  description: string;
51
66
  default: number;
52
67
  };
68
+ maxNodes: {
69
+ type: string;
70
+ description: string;
71
+ default: number;
72
+ };
73
+ includeLifecycleHooks: {
74
+ type: string;
75
+ description: string;
76
+ default: boolean;
77
+ };
78
+ summaryOnly: {
79
+ type: string;
80
+ description: string;
81
+ default: boolean;
82
+ };
53
83
  };
54
84
  required: string[];
55
85
  };
56
- execute(args: Record<string, unknown>): Promise<CallGraphResult & {
57
- summary: string;
58
- }>;
86
+ execute(args: Record<string, unknown>): Promise<GetCallGraphOutput>;
59
87
  private buildSummary;
88
+ private label;
60
89
  }
61
90
  //# sourceMappingURL=get-call-graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-call-graph.d.ts","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AA8BjC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,QAAQ,CAAC,IAAI,oBAAoB;IAEjC,QAAQ,CAAC,WAAW,SAImE;IAEvF,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA6BlB;IAEI,OAAO,CACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,eAAe,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IA4CjD,OAAO,CAAC,YAAY;CA6BrB"}
1
+ {"version":3,"file":"get-call-graph.d.ts","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAmD1D,0FAA0F;AAC1F,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,GAC3E,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E;;GAEG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAGlC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,QAAQ,CAAC,IAAI,oBAAoB;gBAEJ,QAAQ,GAAE,YAAiC;IAExE,QAAQ,CAAC,WAAW,SAcmE;IAEvF,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAmDlB;IAEI,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAsDzE,OAAO,CAAC,YAAY;IAuCpB,OAAO,CAAC,KAAK;CAUd"}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @angular-modernizer/adapter-mcp - Get Call Graph Tool
3
3
  *
4
- * MCP tool for building a caller/callee graph for a named method or function.
4
+ * MCP tool for building a caller/callee graph for a named method, function,
5
+ * constructor, get/set accessor or arrow-function property.
5
6
  * Supports configurable traversal direction and depth.
6
7
  *
7
8
  * @remarks
@@ -9,32 +10,54 @@
9
10
  * propagates through the call hierarchy. Useful for determining blast radius
10
11
  * before proposing a bug fix.
11
12
  *
13
+ * The graph is capped at `maxNodes` (default 200); a capped result carries
14
+ * `truncated: true` and a hint in the summary. Callers are not expanded
15
+ * through lifecycle hooks or interface members of foreign classes unless
16
+ * `includeLifecycleHooks` is set. Projects are cached per tsconfig.
17
+ *
12
18
  * @example
13
19
  * ```typescript
14
20
  * // Via MCP:
15
21
  * // tool: get-call-graph
16
22
  * // args: { method: 'getUser', file: '/project/src/app/user.service.ts', projectRoot: '/project' }
23
+ * // args: { method: 'AuthInterceptor.constructor', file: '/project/src/app/auth.interceptor.ts',
24
+ * // projectRoot: '/project', direction: 'down', depth: 4 }
17
25
  * ```
18
26
  */
19
- import { Project } from 'ts-morph';
20
27
  import { CallGraphBuilder, } from '@angular-modernizer/api';
21
28
  import { existsSync } from 'node:fs';
22
29
  import { findTsConfig } from './helpers/find-ts-config.js';
30
+ import { ProjectCache } from './helpers/project-cache.js';
23
31
  /**
24
32
  * MCP tool that builds a call graph for a named method or function.
25
33
  */
26
34
  export class GetCallGraphTool {
35
+ projects;
27
36
  name = 'get-call-graph';
28
- description = 'Build a caller/callee graph for a named method or function. ' +
29
- 'Direction "up" shows who calls the method, "down" shows what it calls, ' +
37
+ constructor(projects = new ProjectCache()) {
38
+ this.projects = projects;
39
+ }
40
+ description = 'Build a caller/callee graph for a named method, function, constructor, ' +
41
+ 'get/set accessor or arrow-function property. ' +
42
+ 'Direction "up" shows who calls it, "down" shows what it calls, ' +
30
43
  '"both" returns the full call tree. Configurable depth (default: 2). ' +
44
+ 'Prefer "ClassName.method" and the narrowest direction you need. ' +
45
+ 'The graph is capped at maxNodes (default 200); a capped result has truncated: true. ' +
46
+ 'Callers are not expanded through Angular lifecycle hooks or interface members of foreign classes ' +
47
+ '(set includeLifecycleHooks to override). summaryOnly returns counts and direct neighbours only. ' +
48
+ 'Callees are resolved via the type checker and include new X() (constructor incl. field initializers), ' +
49
+ 'super(), and property reads that resolve to getters. ' +
50
+ 'Callers of component members include calls from the component template as leaf nodes ' +
51
+ '(kind "template", template file and line, snippet). ' +
52
+ 'Use method "ClassName.constructor" to see what runs transitively during construction. ' +
31
53
  'Use after parse-stack-trace to trace error propagation through the call hierarchy.';
32
54
  inputSchema = {
33
55
  type: 'object',
34
56
  properties: {
35
57
  method: {
36
58
  type: 'string',
37
- description: 'Name of the method or function to analyse.',
59
+ description: 'Name of the callable to analyse: method, function, get/set accessor, arrow-function property, ' +
60
+ '"constructor", or class-qualified ("ClassName.member", "ClassName.constructor").',
38
61
  },
39
62
  file: {
40
63
  type: 'string',
@@ -55,6 +78,23 @@ export class GetCallGraphTool {
55
78
  description: 'How many levels deep to traverse. Default: 2.',
56
79
  default: 2,
57
80
  },
81
+ maxNodes: {
82
+ type: 'number',
83
+ description: 'Maximum number of nodes across callers and callees. Traversal stops at the cap and the ' +
84
+ 'result is marked truncated. Default: 200.',
85
+ default: 200,
86
+ },
87
+ includeLifecycleHooks: {
88
+ type: 'boolean',
89
+ description: 'Expand callers through Angular lifecycle hooks and implements-interface members of other ' +
90
+ 'classes (e.g. every ngOnInit in the program). Default: false.',
91
+ default: false,
92
+ },
93
+ summaryOnly: {
94
+ type: 'boolean',
95
+ description: 'Return target, counts and the text summary without the callers/callees trees. Default: false.',
96
+ default: false,
97
+ },
58
98
  },
59
99
  required: ['method', 'file', 'projectRoot'],
60
100
  };
@@ -76,17 +116,24 @@ export class GetCallGraphTool {
76
116
  if (!tsConfigPath) {
77
117
  throw new Error(`tsconfig.json not found in projectRoot: ${params.projectRoot}`);
78
118
  }
79
- const project = new Project({ tsConfigFilePath: tsConfigPath });
80
- const graphBuilder = new CallGraphBuilder(project);
119
+ if (params.maxNodes !== undefined &&
120
+ (!Number.isInteger(params.maxNodes) || params.maxNodes < 1)) {
121
+ throw new Error('maxNodes must be a positive integer');
122
+ }
123
+ const graphBuilder = new CallGraphBuilder(this.projects.get(tsConfigPath));
81
124
  const options = {
82
125
  direction: params.direction ?? 'both',
83
126
  depth: params.depth ?? 2,
127
+ maxNodes: params.maxNodes ?? 200,
128
+ includeLifecycleHooks: params.includeLifecycleHooks ?? false,
84
129
  };
85
130
  const result = graphBuilder.buildCallGraph(params.method, params.file, options);
86
- return {
87
- ...result,
88
- summary: this.buildSummary(params.method, result),
89
- };
131
+ const summary = this.buildSummary(params.method, result);
132
+ if (params.summaryOnly) {
133
+ const { callers: _callers, callees: _callees, ...rest } = result;
134
+ return { ...rest, summary };
135
+ }
136
+ return { ...result, summary };
90
137
  }
91
138
  buildSummary(method, result) {
92
139
  if (!result.target) {
@@ -94,11 +141,17 @@ export class GetCallGraphTool {
94
141
  }
95
142
  const lines = [
96
143
  `Call graph for '${method}' at ${result.target.file}:${result.target.line}`,
144
+ `Nodes: ${result.nodeCount}`,
97
145
  ];
146
+ if (result.truncated) {
147
+ lines.push(`\nTRUNCATED at ${result.truncatedAt ?? result.nodeCount} nodes (maxNodes). The trees are a valid ` +
148
+ 'but incomplete prefix. Narrow the query: class-qualified method, direction "up" or "down", ' +
149
+ 'lower depth, or raise maxNodes.');
150
+ }
98
151
  if (result.callers.length > 0) {
99
152
  lines.push(`\nCallers (${result.callers.length}):`);
100
153
  for (const c of result.callers) {
101
- lines.push(` ← ${c.name} (${c.file}:${c.line})`);
154
+ lines.push(` ← ${this.label(c)} (${c.file}:${c.line})`);
102
155
  }
103
156
  }
104
157
  else {
@@ -107,7 +160,7 @@ export class GetCallGraphTool {
107
160
  if (result.callees.length > 0) {
108
161
  lines.push(`\nCallees (${result.callees.length}):`);
109
162
  for (const c of result.callees) {
110
- lines.push(` → ${c.name} (${c.file}:${c.line})`);
163
+ lines.push(` → ${this.label(c)} (${c.file}:${c.line})`);
111
164
  }
112
165
  }
113
166
  else {
@@ -115,5 +168,15 @@ export class GetCallGraphTool {
115
168
  }
116
169
  return lines.join('\n');
117
170
  }
171
+ label(node) {
172
+ if (node.kind === 'template') {
173
+ return `template of ${node.className ?? 'component'}: ${node.snippet ?? ''}`;
174
+ }
175
+ const qualified = node.className
176
+ ? `${node.className}.${node.name}`
177
+ : node.name;
178
+ const kind = node.kind && node.kind !== 'method' ? ` [${node.kind}]` : '';
179
+ return `${qualified}${kind}`;
180
+ }
118
181
  }
119
182
  //# sourceMappingURL=get-call-graph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-call-graph.js","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EACL,gBAAgB,GAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AA4B3D;;GAEG;AACH,MAAM,OAAO,g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I,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @angular-modernizer/adapter-mcp - Compact output
3
+ *
4
+ * Shared `summaryOnly` / `maxResults` handling for tools that return long
5
+ * lists (find-usages, find-angular-symbol, list-imports, analyze-build-impact).
6
+ *
7
+ * @remarks
8
+ * Contract for every tool that uses it:
9
+ * - `summaryOnly: true` omits the list fields and keeps counts and the text
10
+ * summary, so an agent can decide whether the full list is worth loading.
11
+ * - `maxResults: n` keeps the first `n` entries of each list and sets
12
+ * `truncated: true` when anything was cut. Counts always describe the full
13
+ * result, never the shortened list.
14
+ * Both are opt-in; without them the tools return everything, as before. The
15
+ * JSON-RPC handler's 4 MB limit stays the last line of defence.
16
+ */
17
+ /** JSON schema entries for the two shared parameters. */
18
+ export declare const COMPACT_OUTPUT_SCHEMA: {
19
+ readonly summaryOnly: {
20
+ readonly type: "boolean";
21
+ readonly description: "Return counts and the text summary only, without the result list. Default: false.";
22
+ readonly default: false;
23
+ };
24
+ readonly maxResults: {
25
+ readonly type: "number";
26
+ readonly description: string;
27
+ };
28
+ };
29
+ /** Parsed compact-output options. */
30
+ export interface CompactOptions {
31
+ summaryOnly: boolean;
32
+ maxResults: number | undefined;
33
+ }
34
+ /** A list shortened to `maxResults`. */
35
+ export interface LimitedList<T> {
36
+ items: T[];
37
+ truncated: boolean;
38
+ }
39
+ /**
40
+ * Validates and reads `summaryOnly` and `maxResults` from raw tool arguments.
41
+ *
42
+ * @throws Error when `summaryOnly` is not a boolean or `maxResults` is not a
43
+ * positive integer.
44
+ */
45
+ export declare function parseCompactOptions(args: Record<string, unknown>): CompactOptions;
46
+ /** Keeps the first `maxResults` entries of `items`. */
47
+ export declare function limitList<T>(items: readonly T[], maxResults: number | undefined): LimitedList<T>;
48
+ /** Summary line for a list cut by `maxResults`, or `undefined` if nothing was cut. */
49
+ export declare function truncationNote(shown: number, total: number, noun: string): string | undefined;
50
+ /**
51
+ * Counts files per directory prefix of at most `depth` segments, relative to
52
+ * `root`, sorted by count (descending) and then by name.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * countByDirectory(['/p/src/app/a/x.ts', '/p/src/app/a/y.ts'], '/p', 3);
57
+ * // { 'src/app/a': 2 }
58
+ * ```
59
+ */
60
+ export declare function countByDirectory(files: readonly string[], root: string, depth: number): Record<string, number>;
61
+ //# sourceMappingURL=compact-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact-output.d.ts","sourceRoot":"","sources":["../../../src/tools/helpers/compact-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,yDAAyD;AACzD,eAAO,MAAM,qBAAqB;;;;;;;;;;CAaxB,CAAC;AAEX,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,wCAAwC;AACxC,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,cAAc,CAchB;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,WAAW,CAAC,CAAC,CAAC,CAKhB;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAIpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYxB"}