@angular-modernizer/adapter-mcp 1.2.0 → 2.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.
- package/CHANGELOG.md +662 -0
- package/README.md +84 -445
- package/dist/cli.js +9 -1
- package/dist/core/project-analyzer.js +2 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -0
- package/dist/scan-host/scan-host.d.ts +7 -0
- package/dist/scan-host/scan-host.js +73 -10
- package/dist/scan-host/scan-protocol.d.ts +2 -0
- package/dist/scan-host/scan-worker.js +14 -8
- package/dist/server/limited-stdio-transport.d.ts +6 -3
- package/dist/server/limited-stdio-transport.js +26 -9
- package/dist/server/mcp-server.js +1 -1
- package/dist/server/sdk-server.d.ts +14 -3
- package/dist/server/sdk-server.js +54 -6
- package/dist/server/tool-registry.d.ts +3 -1
- package/dist/server/tool-registry.js +8 -3
- package/dist/streaming/progress-store.d.ts +19 -7
- package/dist/streaming/progress-store.js +19 -8
- package/dist/tools/analyze-build-impact.d.ts +7 -4
- package/dist/tools/analyze-build-impact.js +8 -3
- package/dist/tools/analyze-core-to-shared.d.ts +10 -6
- package/dist/tools/analyze-core-to-shared.js +63 -60
- package/dist/tools/analyze-parser-performance.d.ts +57 -13
- package/dist/tools/analyze-parser-performance.js +67 -6
- package/dist/tools/analyze-project.d.ts +30 -4
- package/dist/tools/analyze-project.js +99 -15
- package/dist/tools/check-incremental-compatibility.d.ts +30 -41
- package/dist/tools/check-incremental-compatibility.js +32 -264
- package/dist/tools/collect-feedback.js +15 -2
- package/dist/tools/extract-libraries.js +42 -27
- package/dist/tools/find-angular-symbol.js +3 -2
- package/dist/tools/find-component-hosts.js +3 -2
- package/dist/tools/find-usages.js +21 -12
- package/dist/tools/get-call-graph.js +15 -2
- package/dist/tools/get-operation-progress-tool.d.ts +1 -1
- package/dist/tools/get-operation-progress-tool.js +2 -2
- package/dist/tools/get-operation-progress.d.ts +4 -1
- package/dist/tools/get-operation-progress.js +6 -2
- package/dist/tools/helpers/analysis-output.d.ts +32 -1
- package/dist/tools/helpers/analysis-output.js +22 -1
- package/dist/tools/helpers/build-cache.d.ts +27 -0
- package/dist/tools/helpers/build-cache.js +86 -0
- package/dist/tools/helpers/class-filter.d.ts +18 -0
- package/dist/tools/helpers/class-filter.js +30 -0
- package/dist/tools/helpers/cli-arguments.d.ts +23 -0
- package/dist/tools/helpers/cli-arguments.js +35 -0
- package/dist/tools/helpers/feedback-catalog.d.ts +38 -0
- package/dist/tools/helpers/feedback-catalog.js +196 -0
- package/dist/tools/helpers/feedback-sidecar.d.ts +201 -0
- package/dist/tools/helpers/feedback-sidecar.js +381 -0
- package/dist/tools/helpers/file-type-check.d.ts +34 -0
- package/dist/tools/helpers/file-type-check.js +56 -0
- package/dist/tools/helpers/output-contract.d.ts +42 -0
- package/dist/tools/helpers/output-contract.js +54 -0
- package/dist/tools/helpers/pattern-anonymizer.d.ts +27 -0
- package/dist/tools/helpers/pattern-anonymizer.js +159 -0
- package/dist/tools/helpers/project-cache.d.ts +5 -4
- package/dist/tools/helpers/project-cache.js +21 -16
- package/dist/tools/helpers/project-decorators.d.ts +11 -4
- package/dist/tools/helpers/project-decorators.js +13 -6
- package/dist/tools/helpers/refresh-apply.d.ts +94 -0
- package/dist/tools/helpers/refresh-apply.js +460 -0
- package/dist/tools/helpers/refresh-inventory.d.ts +106 -0
- package/dist/tools/helpers/refresh-inventory.js +610 -0
- package/dist/tools/helpers/rule-runner.js +3 -1
- package/dist/tools/helpers/scan-cache.d.ts +74 -5
- package/dist/tools/helpers/scan-cache.js +134 -6
- package/dist/tools/helpers/scan-engine.d.ts +30 -6
- package/dist/tools/helpers/scan-engine.js +131 -22
- package/dist/tools/helpers/scan-plan.js +16 -2
- package/dist/tools/helpers/source-map-loader.d.ts +55 -0
- package/dist/tools/helpers/source-map-loader.js +226 -0
- package/dist/tools/helpers/template-check.d.ts +76 -0
- package/dist/tools/helpers/template-check.js +158 -0
- package/dist/tools/helpers/tool-cache.d.ts +7 -2
- package/dist/tools/helpers/tool-cache.js +9 -3
- package/dist/tools/helpers/tool-context.d.ts +18 -0
- package/dist/tools/helpers/tool-context.js +29 -0
- package/dist/tools/helpers/transform-safety.d.ts +151 -1
- package/dist/tools/helpers/transform-safety.js +357 -4
- package/dist/tools/inspect-form-group.js +5 -0
- package/dist/tools/inspect-i18n.d.ts +1 -1
- package/dist/tools/inspect-template.js +8 -2
- package/dist/tools/learn-patterns.d.ts +43 -28
- package/dist/tools/learn-patterns.js +83 -161
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/orchestrate-migration.d.ts +19 -1
- package/dist/tools/orchestrate-migration.js +52 -10
- package/dist/tools/parse-stack-trace.d.ts +48 -1
- package/dist/tools/parse-stack-trace.js +108 -9
- package/dist/tools/plan-migration.js +22 -10
- package/dist/tools/refresh-state.d.ts +378 -0
- package/dist/tools/refresh-state.js +370 -0
- package/dist/tools/resolve-type.js +10 -3
- package/dist/tools/review-feedback.d.ts +42 -7
- package/dist/tools/review-feedback.js +24 -17
- package/dist/tools/rollback-changes.d.ts +5 -0
- package/dist/tools/rollback-changes.js +7 -2
- package/dist/tools/run-angular-cli.js +36 -22
- package/dist/tools/run-build.d.ts +33 -28
- package/dist/tools/run-build.js +136 -438
- package/dist/tools/run-schematic.d.ts +8 -2
- package/dist/tools/run-schematic.js +80 -50
- package/dist/tools/scan-all.d.ts +31 -15
- package/dist/tools/scan-all.js +75 -109
- package/dist/tools/scan-angular.d.ts +27 -14
- package/dist/tools/scan-angular.js +70 -92
- package/dist/tools/scan-architecture.d.ts +29 -12
- package/dist/tools/scan-architecture.js +205 -135
- package/dist/tools/scan-solid.d.ts +27 -14
- package/dist/tools/scan-solid.js +73 -89
- package/dist/tools/search-codebase.d.ts +6 -1
- package/dist/tools/search-codebase.js +13 -7
- package/dist/tools/suggest-improvements.d.ts +34 -3
- package/dist/tools/suggest-improvements.js +34 -9
- package/dist/tools/trace-output-flow.js +3 -2
- package/dist/tools/transform-code-batch.d.ts +9 -9
- package/dist/tools/transform-code.d.ts +161 -12
- package/dist/tools/transform-code.js +715 -206
- package/dist/tools/validate-before-transform.js +2 -1
- package/dist/tools/validate-project-compatibility.d.ts +28 -55
- package/dist/tools/validate-project-compatibility.js +33 -225
- package/dist/tools/validate-transformation.d.ts +40 -26
- package/dist/tools/validate-transformation.js +115 -294
- package/dist/tools/verify-citations.js +8 -2
- package/dist/types.d.ts +9 -9
- package/dist/utils/format-tool-response.d.ts +3 -1
- package/dist/utils/format-tool-response.js +8 -3
- package/package.json +14 -13
package/dist/cli.js
CHANGED
|
@@ -10,13 +10,15 @@ import { fileURLToPath } from 'node:url';
|
|
|
10
10
|
import { MCPServer } from './server/mcp-server.js';
|
|
11
11
|
import { isDebugEnabled } from './mcp-watcher.js';
|
|
12
12
|
import { routeConsoleToStderr } from './server/stdio-guard.js';
|
|
13
|
-
import { configureScanHost, parseScanWorkerSetting } from './scan-host/scan-host.js';
|
|
13
|
+
import { MIN_WORKER_HEAP_MB, configureScanHost, parseScanWorkerSetting } from './scan-host/scan-host.js';
|
|
14
14
|
import { AnalyzeProjectTool } from './tools/analyze-project.js';
|
|
15
15
|
import { ScanArchitectureTool } from './tools/scan-architecture.js';
|
|
16
16
|
import { ScanSolidTool } from './tools/scan-solid.js';
|
|
17
17
|
import { ScanAngularTool } from './tools/scan-angular.js';
|
|
18
18
|
import { ScanAllTool } from './tools/scan-all.js';
|
|
19
19
|
import { CompareHealthTool } from './tools/compare-health.js';
|
|
20
|
+
import { RefreshStateTool } from './tools/refresh-state.js';
|
|
21
|
+
import { catalogTool } from './tools/helpers/feedback-catalog.js';
|
|
20
22
|
import { PlanMigrationTool } from './tools/plan-migration.js';
|
|
21
23
|
import { TransformCodeTool } from './tools/transform-code.js';
|
|
22
24
|
import { RunAngularCliTool } from './tools/run-angular-cli.js';
|
|
@@ -124,6 +126,10 @@ function main() {
|
|
|
124
126
|
const scanWorker = parseScanWorkerSetting(process.argv.slice(2), process.env);
|
|
125
127
|
scanWorker.warnings.forEach((w) => console.error(`Scan worker: ${w}`));
|
|
126
128
|
configureScanHost({ enabled: scanWorker.enabled, maxHeapMb: projects.limits.maxHeapMb });
|
|
129
|
+
const heapMb = projects.limits.maxHeapMb;
|
|
130
|
+
if (scanWorker.enabled && heapMb > 0 && heapMb < MIN_WORKER_HEAP_MB) {
|
|
131
|
+
console.error(`Scan worker: --max-heap-mb ${heapMb} is below the minimum of ${MIN_WORKER_HEAP_MB} MB; scans will fail`);
|
|
132
|
+
}
|
|
127
133
|
debugLog(`CLI Scan worker: ${scanWorker.enabled ? 'on' : 'off'}`);
|
|
128
134
|
server.registerTool(new AnalyzeProjectTool());
|
|
129
135
|
server.registerTool(new ScanArchitectureTool());
|
|
@@ -131,6 +137,8 @@ function main() {
|
|
|
131
137
|
server.registerTool(new ScanAngularTool());
|
|
132
138
|
server.registerTool(new ScanAllTool());
|
|
133
139
|
server.registerTool(new CompareHealthTool());
|
|
140
|
+
// The tool list is read per call: tools registered after refresh-state count too
|
|
141
|
+
server.registerTool(new RefreshStateTool({}, () => [...server.getToolsMap().values()].map(catalogTool)));
|
|
134
142
|
server.registerTool(new PlanMigrationTool(projects));
|
|
135
143
|
server.registerTool(new TransformCodeTool());
|
|
136
144
|
server.registerTool(new RunAngularCliTool());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Kernel } from '@angular-modernizer/core';
|
|
1
|
+
import { Kernel, applySuppressionComments } from '@angular-modernizer/core';
|
|
2
2
|
import { AnalyzerPlugin } from '@angular-modernizer/plugin-analyzer';
|
|
3
3
|
import { createPublicApi } from '@angular-modernizer/api';
|
|
4
4
|
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
@@ -80,7 +80,7 @@ export async function analyzeProject(options) {
|
|
|
80
80
|
// Execute the rule and return its results
|
|
81
81
|
try {
|
|
82
82
|
const results = await rule.analyze(context);
|
|
83
|
-
return results;
|
|
83
|
+
return applySuppressionComments(results, rule.id, config, project);
|
|
84
84
|
}
|
|
85
85
|
catch (error) {
|
|
86
86
|
console.error(`✗ Rule "${rule.name}" failed:`, error);
|
package/dist/index.d.ts
CHANGED
|
@@ -59,12 +59,14 @@ export { ScanAllTool } from './tools/scan-all.js';
|
|
|
59
59
|
export { CompareHealthTool } from './tools/compare-health.js';
|
|
60
60
|
export { PlanMigrationTool } from './tools/plan-migration.js';
|
|
61
61
|
export { TransformCodeTool } from './tools/transform-code.js';
|
|
62
|
+
export type { TemplateChecker, TemplateCheckRequest, TemplateCheckOutcome, TemplateDiagnostic, } from './tools/helpers/template-check.js';
|
|
62
63
|
export { RunAngularCliTool } from './tools/run-angular-cli.js';
|
|
63
64
|
export { RunBuildTool } from './tools/run-build.js';
|
|
64
65
|
export { AnalyzeCoreToSharedTool } from './tools/analyze-core-to-shared.js';
|
|
65
66
|
export { RunSchematicTool } from './tools/run-schematic.js';
|
|
66
67
|
export { ValidateTransformationTool } from './tools/validate-transformation.js';
|
|
67
68
|
export { RollbackChangesTool } from './tools/rollback-changes.js';
|
|
69
|
+
export { RefreshStateTool } from './tools/refresh-state.js';
|
|
68
70
|
export { OrchestrateMigrationTool } from './tools/orchestrate-migration.js';
|
|
69
71
|
export { ValidateBeforeTransformTool } from './tools/validate-before-transform.js';
|
|
70
72
|
export { LearnPatternsTool } from './tools/learn-patterns.js';
|
|
@@ -78,6 +80,7 @@ export { SuggestImprovementsTool } from './tools/suggest-improvements.js';
|
|
|
78
80
|
export { AnalyzeParserPerformanceTool } from './tools/analyze-parser-performance.js';
|
|
79
81
|
export { ExtractLibrariesTool } from './tools/extract-libraries.js';
|
|
80
82
|
export { ParseStackTraceTool } from './tools/parse-stack-trace.js';
|
|
83
|
+
export type { SourceMapFetcher, SourceMapOrigin, } from './tools/helpers/source-map-loader.js';
|
|
81
84
|
export { FindUsagesTool } from './tools/find-usages.js';
|
|
82
85
|
export { GetCallGraphTool } from './tools/get-call-graph.js';
|
|
83
86
|
export { ResolveTypeTool } from './tools/resolve-type.js';
|
|
@@ -124,10 +127,16 @@ export type { ParseStackTraceOutput } from './tools/parse-stack-trace.js';
|
|
|
124
127
|
export type { PlanMigrationResult } from './tools/plan-migration.js';
|
|
125
128
|
export type { ReviewFeedbackOutput } from './tools/review-feedback.js';
|
|
126
129
|
export type { RollbackResult } from './tools/rollback-changes.js';
|
|
130
|
+
export type { RefreshApplyOutput, RefreshCounts, RefreshStateOutput, } from './tools/refresh-state.js';
|
|
131
|
+
export type { MarkedItem, RefreshPart, RemovedItem, SkipCause, SkippedItem, } from './tools/helpers/refresh-apply.js';
|
|
132
|
+
export type { CatalogTool, ToolCatalogProvider, } from './tools/helpers/feedback-catalog.js';
|
|
133
|
+
export type { SkippedRecords } from './tools/helpers/feedback-sidecar.js';
|
|
134
|
+
export type { GitRunner, InventoryOptions, RefreshAction, RefreshItem, RefreshReason, RefreshRetention, RefreshStore, StoreReport, } from './tools/helpers/refresh-inventory.js';
|
|
127
135
|
export type { AngularCliResult } from './tools/run-angular-cli.js';
|
|
128
136
|
export type { BuildResult } from './tools/run-build.js';
|
|
129
137
|
export type { SchematicResult } from './tools/run-schematic.js';
|
|
130
138
|
export type { ScanAllResult } from './tools/scan-all.js';
|
|
139
|
+
export type { ScanCacheMode } from './tools/helpers/scan-cache.js';
|
|
131
140
|
export type { ScanAngularResult } from './tools/scan-angular.js';
|
|
132
141
|
export type { ScanArchitectureResult } from './tools/scan-architecture.js';
|
|
133
142
|
export type { ScanSolidResult } from './tools/scan-solid.js';
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,7 @@ export { AnalyzeCoreToSharedTool } from './tools/analyze-core-to-shared.js';
|
|
|
67
67
|
export { RunSchematicTool } from './tools/run-schematic.js';
|
|
68
68
|
export { ValidateTransformationTool } from './tools/validate-transformation.js';
|
|
69
69
|
export { RollbackChangesTool } from './tools/rollback-changes.js';
|
|
70
|
+
export { RefreshStateTool } from './tools/refresh-state.js';
|
|
70
71
|
export { OrchestrateMigrationTool } from './tools/orchestrate-migration.js';
|
|
71
72
|
// Add missing tool exports
|
|
72
73
|
export { ValidateBeforeTransformTool } from './tools/validate-before-transform.js';
|
|
@@ -66,6 +66,13 @@ export declare const SCAN_WORKER_FLAG: {
|
|
|
66
66
|
readonly flag: "--scan-worker";
|
|
67
67
|
readonly env: "ANGULAR_MODERNIZER_SCAN_WORKER";
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Smallest heap limit a scan worker gets. Below about 3 MB V8 cannot even
|
|
71
|
+
* create the worker's isolate and ends the whole process (Node 22 and 24:
|
|
72
|
+
* "Fatal JavaScript out of memory: GC during deserialization"), which no
|
|
73
|
+
* listener can catch; a scan needs far more anyway.
|
|
74
|
+
*/
|
|
75
|
+
export declare const MIN_WORKER_HEAP_MB = 16;
|
|
69
76
|
/**
|
|
70
77
|
* Sets how scans run. The CLI turns the worker on, which also starts the
|
|
71
78
|
* waiting worker; without this call (Jest, library use) scans run in the
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* project cache checks.
|
|
21
21
|
*/
|
|
22
22
|
import { Worker } from 'node:worker_threads';
|
|
23
|
+
import { reportConfigWarning } from '@angular-modernizer/core';
|
|
23
24
|
import { runScanEngine, } from '../tools/helpers/scan-engine.js';
|
|
24
25
|
/** Command-line flag and environment variable of the scan worker switch. */
|
|
25
26
|
export const SCAN_WORKER_FLAG = {
|
|
@@ -27,6 +28,13 @@ export const SCAN_WORKER_FLAG = {
|
|
|
27
28
|
env: 'ANGULAR_MODERNIZER_SCAN_WORKER',
|
|
28
29
|
};
|
|
29
30
|
const MAX_RUNNING = 1;
|
|
31
|
+
/**
|
|
32
|
+
* Smallest heap limit a scan worker gets. Below about 3 MB V8 cannot even
|
|
33
|
+
* create the worker's isolate and ends the whole process (Node 22 and 24:
|
|
34
|
+
* "Fatal JavaScript out of memory: GC during deserialization"), which no
|
|
35
|
+
* listener can catch; a scan needs far more anyway.
|
|
36
|
+
*/
|
|
37
|
+
export const MIN_WORKER_HEAP_MB = 16;
|
|
30
38
|
let settings = { enabled: false, maxHeapMb: 0 };
|
|
31
39
|
let standby;
|
|
32
40
|
const running = new Map();
|
|
@@ -132,20 +140,44 @@ export async function runScan(spec, sink, options = {}) {
|
|
|
132
140
|
*/
|
|
133
141
|
export async function runScanInWorker(spec, sink, options = {}) {
|
|
134
142
|
const { signal } = options;
|
|
135
|
-
|
|
143
|
+
const heapLimit = options.maxHeapMb ?? 0;
|
|
144
|
+
if (belowWorkerMinimum(heapLimit)) {
|
|
145
|
+
throw new Error(`--max-heap-mb ${heapLimit} is below the minimum of ${MIN_WORKER_HEAP_MB} MB a scan worker can start with. ` +
|
|
146
|
+
'Use 0 (no limit) or a larger value.');
|
|
147
|
+
}
|
|
148
|
+
if (!(await acquire(signal, spec.tool))) {
|
|
136
149
|
return { cancelled: true, ruleIds: [] };
|
|
137
150
|
}
|
|
138
151
|
let released = Promise.resolve();
|
|
139
152
|
try {
|
|
140
153
|
const run = startScan(spec, sink, options);
|
|
141
154
|
released = run.released;
|
|
142
|
-
|
|
155
|
+
// Back in the caller's async context: the worker's config warnings join its scope
|
|
156
|
+
try {
|
|
157
|
+
const result = await run.result;
|
|
158
|
+
result.configWarnings?.forEach(reportConfigWarning);
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (error instanceof ScanWorkerError) {
|
|
163
|
+
error.configWarnings.forEach(reportConfigWarning);
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
143
167
|
}
|
|
144
168
|
finally {
|
|
145
169
|
await released;
|
|
146
170
|
release();
|
|
147
171
|
}
|
|
148
172
|
}
|
|
173
|
+
/** An engine error a scan worker reported, with the config warnings of its run. */
|
|
174
|
+
class ScanWorkerError extends Error {
|
|
175
|
+
configWarnings;
|
|
176
|
+
constructor(message, configWarnings) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.configWarnings = configWarnings;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
149
181
|
function startScan(spec, sink, options) {
|
|
150
182
|
const { signal } = options;
|
|
151
183
|
const heapLimit = options.maxHeapMb ?? 0;
|
|
@@ -164,8 +196,10 @@ function startScan(spec, sink, options) {
|
|
|
164
196
|
const released = new Promise((resolve) => {
|
|
165
197
|
markReleased = resolve;
|
|
166
198
|
});
|
|
199
|
+
let onExited = () => undefined;
|
|
167
200
|
const exited = new Promise((resolve) => {
|
|
168
|
-
|
|
201
|
+
onExited = resolve;
|
|
202
|
+
worker.once('exit', onExited);
|
|
169
203
|
});
|
|
170
204
|
const result = new Promise((resolve, reject) => {
|
|
171
205
|
let ruleIds = [];
|
|
@@ -185,6 +219,9 @@ function startScan(spec, sink, options) {
|
|
|
185
219
|
worker.off('exit', onExit);
|
|
186
220
|
running.delete(info.threadId);
|
|
187
221
|
if (keepWorker) {
|
|
222
|
+
// A kept worker serves the next scan; one listener per scan would
|
|
223
|
+
// pile up (MaxListenersExceededWarning after a few scans)
|
|
224
|
+
worker.off('exit', onExited);
|
|
188
225
|
keepForNextScan(worker, script, heapLimit);
|
|
189
226
|
markReleased();
|
|
190
227
|
}
|
|
@@ -203,6 +240,7 @@ function startScan(spec, sink, options) {
|
|
|
203
240
|
const onAbort = () => {
|
|
204
241
|
if (!settled) {
|
|
205
242
|
cancelled++;
|
|
243
|
+
process.stderr.write(`[scan-host] ${spec.tool} cancelled: terminating worker thread ${info.threadId}\n`);
|
|
206
244
|
}
|
|
207
245
|
finish(() => resolve({ cancelled: true, ruleIds }));
|
|
208
246
|
};
|
|
@@ -231,7 +269,7 @@ function startScan(spec, sink, options) {
|
|
|
231
269
|
finish(() => resolve(message.result), true);
|
|
232
270
|
return;
|
|
233
271
|
case 'error': {
|
|
234
|
-
const error = new
|
|
272
|
+
const error = new ScanWorkerError(message.message, message.configWarnings ?? []);
|
|
235
273
|
if (message.stack !== undefined) {
|
|
236
274
|
error.stack = message.stack;
|
|
237
275
|
}
|
|
@@ -274,14 +312,25 @@ function takeWorker(script, maxHeapMb) {
|
|
|
274
312
|
candidate.script === scriptKey(script) &&
|
|
275
313
|
candidate.maxHeapMb === maxHeapMb) {
|
|
276
314
|
standby = undefined;
|
|
315
|
+
candidate.worker.off('error', candidate.onError);
|
|
316
|
+
candidate.worker.off('exit', candidate.onExit);
|
|
277
317
|
candidate.worker.ref();
|
|
278
318
|
return candidate.worker;
|
|
279
319
|
}
|
|
280
320
|
return spawnWorker(script, maxHeapMb);
|
|
281
321
|
}
|
|
282
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Starts a waiting worker for the default script unless one waits already,
|
|
324
|
+
* a scan runs or waits (it parks its worker when it ends), or the host is
|
|
325
|
+
* off. Before, a queued scan that was cancelled started a second worker next
|
|
326
|
+
* to the running one.
|
|
327
|
+
*/
|
|
283
328
|
function prepareStandby() {
|
|
284
|
-
if (!settings.enabled ||
|
|
329
|
+
if (!settings.enabled ||
|
|
330
|
+
belowWorkerMinimum(settings.maxHeapMb) ||
|
|
331
|
+
(standby !== undefined && !standby.exited) ||
|
|
332
|
+
active > 0 ||
|
|
333
|
+
waiting.length > 0) {
|
|
285
334
|
return;
|
|
286
335
|
}
|
|
287
336
|
const script = workerScript(undefined);
|
|
@@ -292,13 +341,23 @@ function keepForNextScan(worker, script, maxHeapMb) {
|
|
|
292
341
|
if (standby !== undefined && standby.worker !== worker) {
|
|
293
342
|
void standby.worker.terminate();
|
|
294
343
|
}
|
|
295
|
-
|
|
296
|
-
|
|
344
|
+
// Without an 'error' listener a waiting worker that fails (out of memory
|
|
345
|
+
// under a small --max-heap-mb) ends the server; the next scan starts its own
|
|
346
|
+
// worker and reports the failure
|
|
347
|
+
const onError = (error) => {
|
|
348
|
+
process.stderr.write(`[scan-host] waiting scan worker failed: ${error.code ?? error.message}` +
|
|
349
|
+
(error.code === 'ERR_WORKER_OUT_OF_MEMORY' ? ` (heap limit ${maxHeapMb} MB, --max-heap-mb)` : '') +
|
|
350
|
+
'\n');
|
|
351
|
+
};
|
|
352
|
+
const onExit = () => {
|
|
297
353
|
entry.exited = true;
|
|
298
354
|
if (standby === entry) {
|
|
299
355
|
standby = undefined;
|
|
300
356
|
}
|
|
301
|
-
}
|
|
357
|
+
};
|
|
358
|
+
const entry = { worker, script: scriptKey(script), maxHeapMb, exited: false, onError, onExit };
|
|
359
|
+
worker.on('error', onError);
|
|
360
|
+
worker.once('exit', onExit);
|
|
302
361
|
// A waiting worker must not keep the process alive
|
|
303
362
|
worker.unref();
|
|
304
363
|
standby = entry;
|
|
@@ -315,7 +374,7 @@ function spawnWorker(script, maxHeapMb) {
|
|
|
315
374
|
return worker;
|
|
316
375
|
}
|
|
317
376
|
/** Waits for a free slot; `false` when the signal aborts first. */
|
|
318
|
-
function acquire(signal) {
|
|
377
|
+
function acquire(signal, tool) {
|
|
319
378
|
if (signal?.aborted === true) {
|
|
320
379
|
return Promise.resolve(false);
|
|
321
380
|
}
|
|
@@ -336,6 +395,7 @@ function acquire(signal) {
|
|
|
336
395
|
if (index >= 0) {
|
|
337
396
|
waiting.splice(index, 1);
|
|
338
397
|
}
|
|
398
|
+
process.stderr.write(`[scan-host] ${tool} cancelled while queued\n`);
|
|
339
399
|
resolve(false);
|
|
340
400
|
};
|
|
341
401
|
waiting.push(entry);
|
|
@@ -370,6 +430,9 @@ function defaultWorkerScript() {
|
|
|
370
430
|
eval: true,
|
|
371
431
|
};
|
|
372
432
|
}
|
|
433
|
+
function belowWorkerMinimum(maxHeapMb) {
|
|
434
|
+
return maxHeapMb > 0 && maxHeapMb < MIN_WORKER_HEAP_MB;
|
|
435
|
+
}
|
|
373
436
|
function toMB(bytes) {
|
|
374
437
|
return Math.round(bytes / (1024 * 1024));
|
|
375
438
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @angular-modernizer/adapter-mcp - Messages between scan host and scan worker
|
|
3
3
|
*/
|
|
4
|
+
import type { ConfigWarning } from '@angular-modernizer/core';
|
|
4
5
|
import type { ScanEngineResult, ScanFileEvent, ScanSpec } from '../tools/helpers/scan-engine.js';
|
|
5
6
|
/**
|
|
6
7
|
* Message from the host to a scan worker. A worker starts without its scan
|
|
@@ -29,6 +30,7 @@ export type ScanWorkerMessage = {
|
|
|
29
30
|
type: 'error';
|
|
30
31
|
message: string;
|
|
31
32
|
stack?: string;
|
|
33
|
+
configWarnings?: ConfigWarning[];
|
|
32
34
|
};
|
|
33
35
|
/** A worker reports its heap with every n-th file. */
|
|
34
36
|
export declare const HEAP_REPORT_EVERY = 20;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { parentPort } from 'node:worker_threads';
|
|
14
14
|
import { routeConsoleToStderr } from '../server/stdio-guard.js';
|
|
15
|
+
import { collectConfigWarnings, configWarningsOf } from '@angular-modernizer/core';
|
|
15
16
|
import { runScanEngine } from '../tools/helpers/scan-engine.js';
|
|
16
17
|
import { HEAP_REPORT_EVERY, } from './scan-protocol.js';
|
|
17
18
|
// The host pipes the worker's stdout to stderr as well; this keeps console
|
|
@@ -24,7 +25,8 @@ if (port === null) {
|
|
|
24
25
|
const post = (message) => port.postMessage(message);
|
|
25
26
|
port.on('message', (message) => {
|
|
26
27
|
let files = 0;
|
|
27
|
-
|
|
28
|
+
// Own scope: config warnings of this run (plugin initialization) go back in the result
|
|
29
|
+
collectConfigWarnings(() => runScanEngine(message.spec, {
|
|
28
30
|
ready: (ruleIds) => post({ type: 'ready', ruleIds, heapUsed: process.memoryUsage().heapUsed }),
|
|
29
31
|
file: (event) => {
|
|
30
32
|
files++;
|
|
@@ -35,14 +37,18 @@ port.on('message', (message) => {
|
|
|
35
37
|
});
|
|
36
38
|
},
|
|
37
39
|
batchDone: (count) => post({ type: 'batch', files: count }),
|
|
38
|
-
}).then((result) => {
|
|
39
|
-
post({ type: 'done', result });
|
|
40
|
+
})).then(({ result, warnings }) => {
|
|
41
|
+
post({ type: 'done', result: warnings.length === 0 ? result : { ...result, configWarnings: warnings } });
|
|
40
42
|
// The scan's project is garbage now; with --expose-gc free it before the next scan
|
|
41
43
|
globalThis.gc?.();
|
|
42
|
-
}, (error) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
}, (error) => {
|
|
45
|
+
const configWarnings = configWarningsOf(error);
|
|
46
|
+
post({
|
|
47
|
+
type: 'error',
|
|
48
|
+
message: error instanceof Error ? error.message : String(error),
|
|
49
|
+
...(error instanceof Error && error.stack !== undefined ? { stack: error.stack } : {}),
|
|
50
|
+
...(configWarnings.length === 0 ? {} : { configWarnings }),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
47
53
|
});
|
|
48
54
|
//# sourceMappingURL=scan-worker.js.map
|
|
@@ -55,12 +55,15 @@ export interface LimitedStdioTransportOptions {
|
|
|
55
55
|
*/
|
|
56
56
|
export declare class LimitedStdioTransport extends StdioServerTransport {
|
|
57
57
|
private readonly maxResponseBytes;
|
|
58
|
-
/** Tool name per pending tools/call request id. */
|
|
58
|
+
/** Tool name and narrowing options per pending tools/call request id. */
|
|
59
59
|
private readonly toolCalls;
|
|
60
60
|
private readonly responseStats;
|
|
61
61
|
constructor(stdin?: Readable, stdout?: Writable, options?: LimitedStdioTransportOptions);
|
|
62
|
-
/**
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Names the tool that answers request `id` and the options of its input
|
|
64
|
+
* schema that narrow the answer; the oversize message names only those.
|
|
65
|
+
*/
|
|
66
|
+
trackToolCall(id: RequestId, tool: string, narrowing?: readonly string[]): void;
|
|
64
67
|
/** Sizes of the responses sent so far (copies, safe to hand out). */
|
|
65
68
|
getResponseStats(): ResponseStats;
|
|
66
69
|
send(message: JSONRPCMessage): Promise<void>;
|
|
@@ -19,6 +19,21 @@ export const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
|
19
19
|
function isResponse(message) {
|
|
20
20
|
return 'id' in message && ('result' in message || 'error' in message);
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* How to get a smaller answer: the narrowing options the tool has (a lower
|
|
24
|
+
* value or `summaryOnly: true`), never options of other tools.
|
|
25
|
+
*/
|
|
26
|
+
function narrowingHint(tool, narrowing) {
|
|
27
|
+
if (narrowing.length === 0) {
|
|
28
|
+
return tool === undefined
|
|
29
|
+
? 'Narrow the request.'
|
|
30
|
+
: `${tool} has no option that narrows its answer; call it on a smaller input.`;
|
|
31
|
+
}
|
|
32
|
+
const names = narrowing.length === 1
|
|
33
|
+
? narrowing[0]
|
|
34
|
+
: `${narrowing.slice(0, -1).join(', ')} or ${narrowing[narrowing.length - 1]}`;
|
|
35
|
+
return `Narrow the request with ${names}.`;
|
|
36
|
+
}
|
|
22
37
|
/**
|
|
23
38
|
* `StdioServerTransport` that measures each response in `send()`. The tool
|
|
24
39
|
* behind a request id is reported by the `tools/call` handler through
|
|
@@ -26,16 +41,19 @@ function isResponse(message) {
|
|
|
26
41
|
*/
|
|
27
42
|
export class LimitedStdioTransport extends StdioServerTransport {
|
|
28
43
|
maxResponseBytes;
|
|
29
|
-
/** Tool name per pending tools/call request id. */
|
|
44
|
+
/** Tool name and narrowing options per pending tools/call request id. */
|
|
30
45
|
toolCalls = new Map();
|
|
31
46
|
responseStats = { count: 0, totalBytes: 0, oversized: 0 };
|
|
32
47
|
constructor(stdin, stdout, options = {}) {
|
|
33
48
|
super(stdin, stdout);
|
|
34
49
|
this.maxResponseBytes = options.maxResponseBytes ?? MAX_RESPONSE_BYTES;
|
|
35
50
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Names the tool that answers request `id` and the options of its input
|
|
53
|
+
* schema that narrow the answer; the oversize message names only those.
|
|
54
|
+
*/
|
|
55
|
+
trackToolCall(id, tool, narrowing = []) {
|
|
56
|
+
this.toolCalls.set(id, { tool, narrowing });
|
|
39
57
|
}
|
|
40
58
|
/** Sizes of the responses sent so far (copies, safe to hand out). */
|
|
41
59
|
getResponseStats() {
|
|
@@ -45,16 +63,16 @@ export class LimitedStdioTransport extends StdioServerTransport {
|
|
|
45
63
|
if (!isResponse(message)) {
|
|
46
64
|
return super.send(message);
|
|
47
65
|
}
|
|
48
|
-
const
|
|
66
|
+
const call = this.toolCalls.get(message.id);
|
|
49
67
|
this.toolCalls.delete(message.id);
|
|
50
|
-
return super.send(this.withinLimit(message, tool));
|
|
68
|
+
return super.send(this.withinLimit(message, call?.tool, call?.narrowing ?? []));
|
|
51
69
|
}
|
|
52
70
|
/**
|
|
53
71
|
* Returns `message` when it serializes within the limit, otherwise a small
|
|
54
72
|
* replacement with the same id: an `isError` result for a tool call, a
|
|
55
73
|
* JSON-RPC error for anything else.
|
|
56
74
|
*/
|
|
57
|
-
withinLimit(message, tool) {
|
|
75
|
+
withinLimit(message, tool, narrowing) {
|
|
58
76
|
let bytes;
|
|
59
77
|
try {
|
|
60
78
|
bytes = Buffer.byteLength(JSON.stringify(message) + '\n', 'utf8');
|
|
@@ -75,8 +93,7 @@ export class LimitedStdioTransport extends StdioServerTransport {
|
|
|
75
93
|
: 'too large to serialize';
|
|
76
94
|
const limit = `${this.maxResponseBytes / (1024 * 1024)} MB`;
|
|
77
95
|
const text = `Response of tool '${tool ?? 'unknown'}' is ${size}, over the ${limit} limit, and was dropped ` +
|
|
78
|
-
|
|
79
|
-
'where the tool supports it, or a smaller scope, depth or maxResults.';
|
|
96
|
+
`to keep the MCP connection alive. ${narrowingHint(tool, narrowing)}`;
|
|
80
97
|
if (tool === undefined) {
|
|
81
98
|
return { jsonrpc: '2.0', id: message.id, error: { code: -32603, message: text } };
|
|
82
99
|
}
|
|
@@ -71,7 +71,7 @@ export class MCPServer {
|
|
|
71
71
|
const transport = new LimitedStdioTransport();
|
|
72
72
|
this.transport = transport;
|
|
73
73
|
this.handle = serveStdio(createServerFactory(this.registry, {
|
|
74
|
-
onToolCall: (id, tool) => transport.trackToolCall(id, tool),
|
|
74
|
+
onToolCall: (id, tool, narrowing) => transport.trackToolCall(id, tool, narrowing),
|
|
75
75
|
protocol: this.protocol,
|
|
76
76
|
}), {
|
|
77
77
|
transport,
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* `ToolRegistry.executeTool`.
|
|
14
14
|
*
|
|
15
15
|
* Every call gets the request's abort signal (`notifications/cancelled`; the
|
|
16
|
-
* SDK sends no response for an aborted request
|
|
16
|
+
* SDK sends no response for an aborted request, also when the cancel arrived
|
|
17
|
+
* while the tool blocked the thread) and, when the client sent a
|
|
17
18
|
* `progressToken`, a throttled `progress` that sends `notifications/progress`.
|
|
18
19
|
*/
|
|
19
20
|
import { type McpServerFactory, type RequestId, type jsonSchemaValidator } from '@modelcontextprotocol/server';
|
|
@@ -28,9 +29,19 @@ export interface ProtocolInfo {
|
|
|
28
29
|
/** Protocol revision the last request was served with. */
|
|
29
30
|
version?: string;
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Input options that make a tool answer smaller, in the order the size limit
|
|
34
|
+
* message names them.
|
|
35
|
+
*/
|
|
36
|
+
export declare const NARROWING_OPTIONS: readonly ["summaryOnly", "maxResults", "maxNodes", "depth", "maxFiles", "includePatterns", "scope", "rules"];
|
|
37
|
+
/** The narrowing options a tool's input schema has. */
|
|
38
|
+
export declare function narrowingOptions(inputSchema: unknown): string[];
|
|
31
39
|
export interface SdkServerHooks {
|
|
32
|
-
/**
|
|
33
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Called with the request id when a tool call starts, with the options of
|
|
42
|
+
* the tool's input schema that narrow its answer (`NARROWING_OPTIONS`).
|
|
43
|
+
*/
|
|
44
|
+
onToolCall?: (id: RequestId, tool: string, narrowing: readonly string[]) => void;
|
|
34
45
|
/** Updated on `initialize` and on every tool call. */
|
|
35
46
|
protocol?: ProtocolInfo;
|
|
36
47
|
}
|
|
@@ -13,13 +13,40 @@
|
|
|
13
13
|
* `ToolRegistry.executeTool`.
|
|
14
14
|
*
|
|
15
15
|
* Every call gets the request's abort signal (`notifications/cancelled`; the
|
|
16
|
-
* SDK sends no response for an aborted request
|
|
16
|
+
* SDK sends no response for an aborted request, also when the cancel arrived
|
|
17
|
+
* while the tool blocked the thread) and, when the client sent a
|
|
17
18
|
* `progressToken`, a throttled `progress` that sends `notifications/progress`.
|
|
18
19
|
*/
|
|
19
20
|
import { McpServer, fromJsonSchema, } from '@modelcontextprotocol/server';
|
|
20
21
|
import { AjvJsonSchemaValidator } from '@modelcontextprotocol/server/validators/ajv';
|
|
21
22
|
import { PACKAGE_VERSION } from './package-version.js';
|
|
22
23
|
import { throttleProgress } from '../tools/helpers/tool-context.js';
|
|
24
|
+
import { configWarningsLine, withConfigWarningsSchema } from '../tools/helpers/output-contract.js';
|
|
25
|
+
import { configWarningsOf } from '@angular-modernizer/core';
|
|
26
|
+
/**
|
|
27
|
+
* Input options that make a tool answer smaller, in the order the size limit
|
|
28
|
+
* message names them.
|
|
29
|
+
*/
|
|
30
|
+
export const NARROWING_OPTIONS = [
|
|
31
|
+
'summaryOnly',
|
|
32
|
+
'maxResults',
|
|
33
|
+
'maxNodes',
|
|
34
|
+
'depth',
|
|
35
|
+
'maxFiles',
|
|
36
|
+
'includePatterns',
|
|
37
|
+
'scope',
|
|
38
|
+
'rules',
|
|
39
|
+
];
|
|
40
|
+
/** The narrowing options a tool's input schema has. */
|
|
41
|
+
export function narrowingOptions(inputSchema) {
|
|
42
|
+
const properties = typeof inputSchema === 'object' && inputSchema !== null
|
|
43
|
+
? inputSchema.properties
|
|
44
|
+
: undefined;
|
|
45
|
+
if (typeof properties !== 'object' || properties === null) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
return NARROWING_OPTIONS.filter((option) => option in properties);
|
|
49
|
+
}
|
|
23
50
|
/**
|
|
24
51
|
* Validates tool arguments. One instance for all connections: Ajv caches the
|
|
25
52
|
* compiled schema per schema object, so every input schema compiles once.
|
|
@@ -50,6 +77,7 @@ export function createServerFactory(registry, hooks = {}) {
|
|
|
50
77
|
console.error('[MCP] Server initialized and ready');
|
|
51
78
|
};
|
|
52
79
|
for (const tool of registry.getAllTools()) {
|
|
80
|
+
const narrowing = narrowingOptions(tool.inputSchema);
|
|
53
81
|
mcp.registerTool(tool.name, {
|
|
54
82
|
...(tool.title === undefined ? {} : { title: tool.title }),
|
|
55
83
|
description: tool.description,
|
|
@@ -57,27 +85,47 @@ export function createServerFactory(registry, hooks = {}) {
|
|
|
57
85
|
...(tool.outputSchema === undefined
|
|
58
86
|
? {}
|
|
59
87
|
: {
|
|
60
|
-
outputSchema: fromJsonSchema(tool.outputSchema, OUTPUT_VALIDATOR),
|
|
88
|
+
outputSchema: fromJsonSchema(withConfigWarningsSchema(tool.outputSchema), OUTPUT_VALIDATOR),
|
|
61
89
|
}),
|
|
62
90
|
...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),
|
|
63
91
|
}, async (args, ctx) => {
|
|
64
|
-
hooks.onToolCall?.(ctx.mcpReq.id, tool.name);
|
|
92
|
+
hooks.onToolCall?.(ctx.mcpReq.id, tool.name, narrowing);
|
|
65
93
|
noteProtocol();
|
|
94
|
+
let result;
|
|
66
95
|
try {
|
|
67
|
-
|
|
96
|
+
result = (await registry.executeTool(tool.name, (args ?? {}), toolContext(ctx.mcpReq)));
|
|
68
97
|
}
|
|
69
98
|
catch (error) {
|
|
70
99
|
const message = error instanceof Error ? error.message : 'Tool execution failed';
|
|
71
|
-
|
|
72
|
-
|
|
100
|
+
// Config warnings reported before the throw (no structuredContent here)
|
|
101
|
+
const warnings = configWarningsOf(error);
|
|
102
|
+
const configLine = warnings.length === 0 ? '' : `\n${configWarningsLine(warnings, false)}`;
|
|
103
|
+
result = {
|
|
104
|
+
content: [{ type: 'text', text: `Tool execution error: ${message}${configLine}` }],
|
|
73
105
|
isError: true,
|
|
74
106
|
};
|
|
75
107
|
}
|
|
108
|
+
await readPendingInput();
|
|
109
|
+
return result;
|
|
76
110
|
});
|
|
77
111
|
}
|
|
78
112
|
return mcp;
|
|
79
113
|
};
|
|
80
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Lets the event loop read stdin once before a tool result goes out. A tool
|
|
117
|
+
* whose last phase is synchronous (an investigation query on a loaded
|
|
118
|
+
* project) blocks the thread; a `notifications/cancelled` that arrived
|
|
119
|
+
* meanwhile is read only on the next poll phase. Without this the SDK saw the
|
|
120
|
+
* request as not aborted and sent the response of a cancelled request. The
|
|
121
|
+
* first `setImmediate` can run in the current loop turn before any poll, the
|
|
122
|
+
* nested one runs after the next poll phase.
|
|
123
|
+
*/
|
|
124
|
+
function readPendingInput() {
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
setImmediate(() => setImmediate(resolve));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
81
129
|
/**
|
|
82
130
|
* Tool context of one request: its abort signal and, only with a
|
|
83
131
|
* `progressToken`, a throttled sender of `notifications/progress`.
|
|
@@ -38,7 +38,9 @@ export declare class ToolRegistry {
|
|
|
38
38
|
*/
|
|
39
39
|
getToolNames(): string[];
|
|
40
40
|
/**
|
|
41
|
-
* Execute a tool by name with given arguments.
|
|
41
|
+
* Execute a tool by name with given arguments. Config warnings the tool
|
|
42
|
+
* reports while it runs (core `reportConfigWarning`) come back as
|
|
43
|
+
* `configWarnings` plus one summary line.
|
|
42
44
|
* @param name - Tool name
|
|
43
45
|
* @param args - Tool arguments
|
|
44
46
|
* @param ctx - Cancellation and progress of the request
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { collectConfigWarnings } from '@angular-modernizer/core';
|
|
2
|
+
import { withConfigWarnings } from '../tools/helpers/output-contract.js';
|
|
1
3
|
import { formatStructuredToolResponse } from '../utils/format-tool-response.js';
|
|
2
4
|
/**
|
|
3
5
|
* Central registry for MCP tools: registration, discovery and execution.
|
|
@@ -53,7 +55,9 @@ export class ToolRegistry {
|
|
|
53
55
|
return Array.from(this.tools.keys());
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
|
-
* Execute a tool by name with given arguments.
|
|
58
|
+
* Execute a tool by name with given arguments. Config warnings the tool
|
|
59
|
+
* reports while it runs (core `reportConfigWarning`) come back as
|
|
60
|
+
* `configWarnings` plus one summary line.
|
|
57
61
|
* @param name - Tool name
|
|
58
62
|
* @param args - Tool arguments
|
|
59
63
|
* @param ctx - Cancellation and progress of the request
|
|
@@ -65,8 +69,9 @@ export class ToolRegistry {
|
|
|
65
69
|
if (!tool) {
|
|
66
70
|
throw new Error(`Unknown tool: ${name}`);
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
// Config warnings the call reported (any depth, after awaits) go into the answer
|
|
73
|
+
const { result, warnings } = await collectConfigWarnings(() => tool.execute(args, ctx));
|
|
74
|
+
return formatStructuredToolResponse(withConfigWarnings(result, warnings));
|
|
70
75
|
}
|
|
71
76
|
/**
|
|
72
77
|
* Unregister a tool.
|