@angular-modernizer/adapter-mcp 0.3.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.
- package/README.md +103 -218
- package/dist/cli.js +13 -13
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/mcp-watcher.d.ts +6 -1
- package/dist/mcp-watcher.js +11 -10
- package/dist/server/limited-stdio-transport.d.ts +68 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +12 -14
- package/dist/server/mcp-server.js +41 -75
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +70 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/tool-registry.d.ts +3 -2
- package/dist/server/tool-registry.js +5 -5
- package/dist/tools/analyze-build-impact.d.ts +220 -1
- package/dist/tools/analyze-build-impact.js +145 -3
- package/dist/tools/analyze-core-to-shared.d.ts +134 -4
- package/dist/tools/analyze-core-to-shared.js +113 -9
- package/dist/tools/analyze-parser-performance.d.ts +200 -7
- package/dist/tools/analyze-parser-performance.js +108 -47
- package/dist/tools/analyze-project.d.ts +267 -5
- package/dist/tools/analyze-project.js +196 -8
- package/dist/tools/check-incremental-compatibility.d.ts +61 -1
- package/dist/tools/check-incremental-compatibility.js +58 -2
- package/dist/tools/collect-feedback.d.ts +199 -10
- package/dist/tools/collect-feedback.js +171 -99
- package/dist/tools/compare-health.d.ts +356 -0
- package/dist/tools/compare-health.js +472 -0
- package/dist/tools/extract-libraries.d.ts +156 -4
- package/dist/tools/extract-libraries.js +115 -10
- package/dist/tools/find-angular-symbol.d.ts +69 -3
- package/dist/tools/find-angular-symbol.js +55 -8
- package/dist/tools/find-component-hosts.d.ts +572 -2
- package/dist/tools/find-component-hosts.js +207 -6
- package/dist/tools/find-usages.d.ts +79 -1
- package/dist/tools/find-usages.js +64 -7
- package/dist/tools/get-bootstrap-execution.d.ts +151 -1
- package/dist/tools/get-bootstrap-execution.js +84 -3
- package/dist/tools/get-call-graph.d.ts +111 -1
- package/dist/tools/get-call-graph.js +72 -10
- package/dist/tools/get-operation-progress-tool.d.ts +114 -2
- package/dist/tools/get-operation-progress-tool.js +114 -7
- package/dist/tools/get-operation-progress.d.ts +1 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +177 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/build-schemas.d.ts +36 -0
- package/dist/tools/helpers/build-schemas.js +23 -0
- package/dist/tools/helpers/citation-file-source.d.ts +10 -0
- package/dist/tools/helpers/citation-file-source.js +82 -0
- package/dist/tools/helpers/finding-window.d.ts +43 -0
- package/dist/tools/helpers/finding-window.js +64 -0
- package/dist/tools/helpers/health-delta.d.ts +86 -0
- package/dist/tools/helpers/health-delta.js +239 -0
- package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
- package/dist/tools/helpers/investigation-schemas.js +48 -0
- package/dist/tools/helpers/library-imports.d.ts +57 -0
- package/dist/tools/helpers/library-imports.js +151 -0
- package/dist/tools/helpers/load-source-files.d.ts +30 -0
- package/dist/tools/helpers/load-source-files.js +34 -0
- package/dist/tools/helpers/output-contract.d.ts +32 -0
- package/dist/tools/helpers/output-contract.js +32 -0
- package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
- package/dist/tools/helpers/platform-root-resolver.js +75 -48
- package/dist/tools/helpers/process-output.d.ts +19 -0
- package/dist/tools/helpers/process-output.js +31 -0
- package/dist/tools/helpers/project-cache.d.ts +11 -4
- package/dist/tools/helpers/project-cache.js +22 -4
- package/dist/tools/helpers/project-decorators.d.ts +14 -0
- package/dist/tools/helpers/project-decorators.js +22 -0
- package/dist/tools/helpers/rule-matcher.js +5 -0
- package/dist/tools/helpers/rule-runner.d.ts +9 -4
- package/dist/tools/helpers/rule-runner.js +28 -14
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-plan.d.ts +5 -2
- package/dist/tools/helpers/scan-plan.js +18 -3
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/tool-context.d.ts +60 -0
- package/dist/tools/helpers/tool-context.js +82 -0
- package/dist/tools/helpers/transform-safety.d.ts +40 -0
- package/dist/tools/helpers/transform-safety.js +87 -0
- package/dist/tools/helpers/validation-output.d.ts +53 -0
- package/dist/tools/helpers/validation-output.js +48 -0
- package/dist/tools/inspect-form-group.d.ts +232 -1
- package/dist/tools/inspect-form-group.js +120 -2
- package/dist/tools/inspect-i18n.d.ts +382 -1
- package/dist/tools/inspect-i18n.js +199 -2
- package/dist/tools/inspect-template.d.ts +232 -1
- package/dist/tools/inspect-template.js +160 -2
- package/dist/tools/learn-patterns.d.ts +122 -1
- package/dist/tools/learn-patterns.js +97 -2
- package/dist/tools/list-imports.d.ts +111 -10
- package/dist/tools/list-imports.js +110 -7
- package/dist/tools/orchestrate-migration.d.ts +128 -5
- package/dist/tools/orchestrate-migration.js +135 -13
- package/dist/tools/parse-stack-trace.d.ts +56 -1
- package/dist/tools/parse-stack-trace.js +34 -0
- package/dist/tools/plan-migration.d.ts +330 -1
- package/dist/tools/plan-migration.js +154 -3
- package/dist/tools/resolve-type.d.ts +39 -1
- package/dist/tools/resolve-type.js +31 -2
- package/dist/tools/review-feedback.d.ts +206 -11
- package/dist/tools/review-feedback.js +132 -51
- package/dist/tools/rollback-changes.d.ts +79 -2
- package/dist/tools/rollback-changes.js +66 -14
- package/dist/tools/run-angular-cli.d.ts +45 -2
- package/dist/tools/run-angular-cli.js +67 -7
- package/dist/tools/run-build.d.ts +114 -2
- package/dist/tools/run-build.js +117 -8
- package/dist/tools/run-schematic.d.ts +70 -2
- package/dist/tools/run-schematic.js +104 -10
- package/dist/tools/scan-all.d.ts +19 -11
- package/dist/tools/scan-all.js +139 -131
- package/dist/tools/scan-angular.d.ts +19 -10
- package/dist/tools/scan-angular.js +51 -23
- package/dist/tools/scan-architecture.d.ts +17 -10
- package/dist/tools/scan-architecture.js +93 -31
- package/dist/tools/scan-solid.d.ts +19 -10
- package/dist/tools/scan-solid.js +51 -23
- package/dist/tools/search-codebase.d.ts +82 -1
- package/dist/tools/search-codebase.js +55 -2
- package/dist/tools/server-status.d.ts +279 -5
- package/dist/tools/server-status.js +179 -5
- package/dist/tools/suggest-improvements.d.ts +97 -5
- package/dist/tools/suggest-improvements.js +80 -44
- package/dist/tools/trace-output-flow.d.ts +682 -2
- package/dist/tools/trace-output-flow.js +375 -15
- package/dist/tools/transform-code-batch.d.ts +3 -0
- package/dist/tools/transform-code-batch.js +10 -5
- package/dist/tools/transform-code.d.ts +335 -12
- package/dist/tools/transform-code.js +649 -608
- package/dist/tools/validate-before-transform.d.ts +116 -2
- package/dist/tools/validate-before-transform.js +55 -2
- package/dist/tools/validate-project-compatibility.d.ts +64 -2
- package/dist/tools/validate-project-compatibility.js +67 -4
- package/dist/tools/validate-transformation.d.ts +220 -2
- package/dist/tools/validate-transformation.js +113 -15
- package/dist/tools/verify-citations.d.ts +181 -0
- package/dist/tools/verify-citations.js +218 -0
- package/dist/types.d.ts +38 -1
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +30 -13
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/project-analyzer.d.ts.map +0 -1
- package/dist/core/project-analyzer.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-watcher.d.ts.map +0 -1
- package/dist/mcp-watcher.js.map +0 -1
- package/dist/server/json-rpc-handler.d.ts +0 -98
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -301
- package/dist/server/json-rpc-handler.js.map +0 -1
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/server/mcp-server.js.map +0 -1
- package/dist/server/stdio-guard.d.ts.map +0 -1
- package/dist/server/stdio-guard.js.map +0 -1
- package/dist/server/tool-registry.d.ts.map +0 -1
- package/dist/server/tool-registry.js.map +0 -1
- package/dist/streaming/progress-store.d.ts.map +0 -1
- package/dist/streaming/progress-store.js.map +0 -1
- package/dist/tools/analyze-build-impact.d.ts.map +0 -1
- package/dist/tools/analyze-build-impact.js.map +0 -1
- package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
- package/dist/tools/analyze-core-to-shared.js.map +0 -1
- package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
- package/dist/tools/analyze-parser-performance.js.map +0 -1
- package/dist/tools/analyze-project.d.ts.map +0 -1
- package/dist/tools/analyze-project.js.map +0 -1
- package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
- package/dist/tools/check-incremental-compatibility.js.map +0 -1
- package/dist/tools/collect-feedback.d.ts.map +0 -1
- package/dist/tools/collect-feedback.js.map +0 -1
- package/dist/tools/extract-libraries.d.ts.map +0 -1
- package/dist/tools/extract-libraries.js.map +0 -1
- package/dist/tools/find-angular-symbol.d.ts.map +0 -1
- package/dist/tools/find-angular-symbol.js.map +0 -1
- package/dist/tools/find-component-hosts.d.ts.map +0 -1
- package/dist/tools/find-component-hosts.js.map +0 -1
- package/dist/tools/find-usages.d.ts.map +0 -1
- package/dist/tools/find-usages.js.map +0 -1
- package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
- package/dist/tools/get-bootstrap-execution.js.map +0 -1
- package/dist/tools/get-call-graph.d.ts.map +0 -1
- package/dist/tools/get-call-graph.js.map +0 -1
- package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
- package/dist/tools/get-operation-progress-tool.js.map +0 -1
- package/dist/tools/get-operation-progress.d.ts.map +0 -1
- package/dist/tools/get-operation-progress.js.map +0 -1
- package/dist/tools/helpers/compact-output.d.ts.map +0 -1
- package/dist/tools/helpers/compact-output.js.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
- package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
- package/dist/tools/helpers/find-ts-config.js.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
- package/dist/tools/helpers/project-cache.d.ts.map +0 -1
- package/dist/tools/helpers/project-cache.js.map +0 -1
- package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
- package/dist/tools/helpers/rule-matcher.js.map +0 -1
- package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
- package/dist/tools/helpers/rule-runner.js.map +0 -1
- package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
- package/dist/tools/helpers/scan-plan.js.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
- package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
- package/dist/tools/helpers/suggestion-generator.js.map +0 -1
- package/dist/tools/inspect-form-group.d.ts.map +0 -1
- package/dist/tools/inspect-form-group.js.map +0 -1
- package/dist/tools/inspect-i18n.d.ts.map +0 -1
- package/dist/tools/inspect-i18n.js.map +0 -1
- package/dist/tools/inspect-template.d.ts.map +0 -1
- package/dist/tools/inspect-template.js.map +0 -1
- package/dist/tools/learn-patterns.d.ts.map +0 -1
- package/dist/tools/learn-patterns.js.map +0 -1
- package/dist/tools/list-imports.d.ts.map +0 -1
- package/dist/tools/list-imports.js.map +0 -1
- package/dist/tools/orchestrate-migration.d.ts.map +0 -1
- package/dist/tools/orchestrate-migration.js.map +0 -1
- package/dist/tools/parse-stack-trace.d.ts.map +0 -1
- package/dist/tools/parse-stack-trace.js.map +0 -1
- package/dist/tools/plan-migration.d.ts.map +0 -1
- package/dist/tools/plan-migration.js.map +0 -1
- package/dist/tools/resolve-type.d.ts.map +0 -1
- package/dist/tools/resolve-type.js.map +0 -1
- package/dist/tools/review-feedback.d.ts.map +0 -1
- package/dist/tools/review-feedback.js.map +0 -1
- package/dist/tools/rollback-changes.d.ts.map +0 -1
- package/dist/tools/rollback-changes.js.map +0 -1
- package/dist/tools/run-angular-cli.d.ts.map +0 -1
- package/dist/tools/run-angular-cli.js.map +0 -1
- package/dist/tools/run-build.d.ts.map +0 -1
- package/dist/tools/run-build.js.map +0 -1
- package/dist/tools/run-schematic.d.ts.map +0 -1
- package/dist/tools/run-schematic.js.map +0 -1
- package/dist/tools/scan-all.d.ts.map +0 -1
- package/dist/tools/scan-all.js.map +0 -1
- package/dist/tools/scan-angular.d.ts.map +0 -1
- package/dist/tools/scan-angular.js.map +0 -1
- package/dist/tools/scan-architecture.d.ts.map +0 -1
- package/dist/tools/scan-architecture.js.map +0 -1
- package/dist/tools/scan-solid.d.ts.map +0 -1
- package/dist/tools/scan-solid.js.map +0 -1
- package/dist/tools/search-codebase.d.ts.map +0 -1
- package/dist/tools/search-codebase.js.map +0 -1
- package/dist/tools/server-status.d.ts.map +0 -1
- package/dist/tools/server-status.js.map +0 -1
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js.map +0 -1
- package/dist/tools/suggest-improvements.d.ts.map +0 -1
- package/dist/tools/suggest-improvements.js.map +0 -1
- package/dist/tools/trace-output-flow.d.ts.map +0 -1
- package/dist/tools/trace-output-flow.js.map +0 -1
- package/dist/tools/transform-code-batch.d.ts.map +0 -1
- package/dist/tools/transform-code-batch.js.map +0 -1
- package/dist/tools/transform-code.d.ts.map +0 -1
- package/dist/tools/transform-code.js.map +0 -1
- package/dist/tools/validate-before-transform.d.ts.map +0 -1
- package/dist/tools/validate-before-transform.js.map +0 -1
- package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
- package/dist/tools/validate-project-compatibility.js.map +0 -1
- package/dist/tools/validate-transformation.d.ts.map +0 -1
- package/dist/tools/validate-transformation.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/format-tool-response.d.ts.map +0 -1
- package/dist/utils/format-tool-response.js.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - SDK server factory
|
|
3
|
+
*
|
|
4
|
+
* Builds the `McpServer` instances `serveStdio` asks for: one per connection
|
|
5
|
+
* (plus a discarded probe for `server/discover`). Every registered `MCPTool`
|
|
6
|
+
* is exposed through `registerTool` with its JSON Schemas as they are; the
|
|
7
|
+
* arguments are validated against the input schema (Ajv, JSON Schema 2020-12)
|
|
8
|
+
* before the tool runs, so invalid arguments come back as an `isError` result
|
|
9
|
+
* without reaching the tool. A tool with an `outputSchema` has its
|
|
10
|
+
* `structuredContent` validated the same way; the SDK replaces a result that
|
|
11
|
+
* does not match with an `isError` result (results that already report
|
|
12
|
+
* `isError` are not checked). The response format is the one of
|
|
13
|
+
* `ToolRegistry.executeTool`.
|
|
14
|
+
*
|
|
15
|
+
* Every call gets the request's abort signal (`notifications/cancelled`; the
|
|
16
|
+
* SDK sends no response for an aborted request) and, when the client sent a
|
|
17
|
+
* `progressToken`, a throttled `progress` that sends `notifications/progress`.
|
|
18
|
+
*/
|
|
19
|
+
import { McpServer, fromJsonSchema, } from '@modelcontextprotocol/server';
|
|
20
|
+
import { AjvJsonSchemaValidator } from '@modelcontextprotocol/server/validators/ajv';
|
|
21
|
+
import { PACKAGE_VERSION } from './package-version.js';
|
|
22
|
+
import { throttleProgress } from '../tools/helpers/tool-context.js';
|
|
23
|
+
/**
|
|
24
|
+
* Validates tool arguments. One instance for all connections: Ajv caches the
|
|
25
|
+
* compiled schema per schema object, so every input schema compiles once.
|
|
26
|
+
* Defaults of the SDK: `strict: false`, `allErrors: true`, formats registered.
|
|
27
|
+
*/
|
|
28
|
+
export const INPUT_VALIDATOR = new AjvJsonSchemaValidator();
|
|
29
|
+
/**
|
|
30
|
+
* Validates `structuredContent` against the output schema, same settings as
|
|
31
|
+
* the input validator. Output schemas leave objects open, so a new result
|
|
32
|
+
* field never fails; a missing required field or a wrong type does.
|
|
33
|
+
*/
|
|
34
|
+
export const OUTPUT_VALIDATOR = new AjvJsonSchemaValidator();
|
|
35
|
+
/**
|
|
36
|
+
* Factory for `serveStdio`: registers every tool of `registry` on a fresh
|
|
37
|
+
* `McpServer` for the era the SDK asks for.
|
|
38
|
+
*/
|
|
39
|
+
export function createServerFactory(registry, hooks = {}) {
|
|
40
|
+
return ({ era }) => {
|
|
41
|
+
const mcp = new McpServer({ name: 'angular-modernizer', version: PACKAGE_VERSION });
|
|
42
|
+
const noteProtocol = () => {
|
|
43
|
+
if (hooks.protocol !== undefined) {
|
|
44
|
+
hooks.protocol.era = era;
|
|
45
|
+
hooks.protocol.version = mcp.server.getNegotiatedProtocolVersion();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
mcp.server.oninitialized = () => {
|
|
49
|
+
noteProtocol();
|
|
50
|
+
console.error('[MCP] Server initialized and ready');
|
|
51
|
+
};
|
|
52
|
+
for (const tool of registry.getAllTools()) {
|
|
53
|
+
mcp.registerTool(tool.name, {
|
|
54
|
+
...(tool.title === undefined ? {} : { title: tool.title }),
|
|
55
|
+
description: tool.description,
|
|
56
|
+
inputSchema: fromJsonSchema(tool.inputSchema, INPUT_VALIDATOR),
|
|
57
|
+
...(tool.outputSchema === undefined
|
|
58
|
+
? {}
|
|
59
|
+
: {
|
|
60
|
+
outputSchema: fromJsonSchema(tool.outputSchema, OUTPUT_VALIDATOR),
|
|
61
|
+
}),
|
|
62
|
+
...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),
|
|
63
|
+
}, async (args, ctx) => {
|
|
64
|
+
hooks.onToolCall?.(ctx.mcpReq.id, tool.name);
|
|
65
|
+
noteProtocol();
|
|
66
|
+
try {
|
|
67
|
+
return (await registry.executeTool(tool.name, (args ?? {}), toolContext(ctx.mcpReq)));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const message = error instanceof Error ? error.message : 'Tool execution failed';
|
|
71
|
+
return {
|
|
72
|
+
content: [{ type: 'text', text: `Tool execution error: ${message}` }],
|
|
73
|
+
isError: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return mcp;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Tool context of one request: its abort signal and, only with a
|
|
83
|
+
* `progressToken`, a throttled sender of `notifications/progress`.
|
|
84
|
+
*/
|
|
85
|
+
export function toolContext(req) {
|
|
86
|
+
const token = req._meta?.progressToken;
|
|
87
|
+
if (token === undefined) {
|
|
88
|
+
return { signal: req.signal };
|
|
89
|
+
}
|
|
90
|
+
let lastProgress = -1;
|
|
91
|
+
const progress = throttleProgress((value, total, message) => {
|
|
92
|
+
// The spec requires a growing value; a tool that restarts a phase must not go back.
|
|
93
|
+
if (value <= lastProgress || req.signal.aborted) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
lastProgress = value;
|
|
97
|
+
req
|
|
98
|
+
.notify({
|
|
99
|
+
method: 'notifications/progress',
|
|
100
|
+
params: {
|
|
101
|
+
progressToken: token,
|
|
102
|
+
progress: value,
|
|
103
|
+
...(total === undefined ? {} : { total }),
|
|
104
|
+
...(message === undefined ? {} : { message }),
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
.catch((error) => {
|
|
108
|
+
console.error('[MCP] Progress notification failed:', error);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return { signal: req.signal, progress };
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=sdk-server.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Central registry for MCP tools. Manages tool registration,
|
|
5
5
|
* discovery, and execution coordination.
|
|
6
6
|
*/
|
|
7
|
-
import { type MCPTool } from '../types.js';
|
|
7
|
+
import { type MCPTool, type ToolContext } from '../types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Registry for MCP tools with registration and discovery capabilities.
|
|
10
10
|
*/
|
|
@@ -47,10 +47,11 @@ export declare class ToolRegistry {
|
|
|
47
47
|
* Execute a tool by name with given arguments.
|
|
48
48
|
* @param name - Tool name
|
|
49
49
|
* @param args - Tool arguments
|
|
50
|
+
* @param ctx - Cancellation and progress of the request
|
|
50
51
|
* @returns Tool execution result in MCP format
|
|
51
52
|
* @throws Error if tool not found
|
|
52
53
|
*/
|
|
53
|
-
executeTool(name: string, args: Record<string, unknown
|
|
54
|
+
executeTool(name: string, args: Record<string, unknown>, ctx?: ToolContext): Promise<unknown>;
|
|
54
55
|
/**
|
|
55
56
|
* Unregister a tool.
|
|
56
57
|
* @param name - Tool name
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Central registry for MCP tools. Manages tool registration,
|
|
5
5
|
* discovery, and execution coordination.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { formatStructuredToolResponse } from '../utils/format-tool-response.js';
|
|
8
8
|
/**
|
|
9
9
|
* Registry for MCP tools with registration and discovery capabilities.
|
|
10
10
|
*/
|
|
@@ -62,17 +62,17 @@ export class ToolRegistry {
|
|
|
62
62
|
* Execute a tool by name with given arguments.
|
|
63
63
|
* @param name - Tool name
|
|
64
64
|
* @param args - Tool arguments
|
|
65
|
+
* @param ctx - Cancellation and progress of the request
|
|
65
66
|
* @returns Tool execution result in MCP format
|
|
66
67
|
* @throws Error if tool not found
|
|
67
68
|
*/
|
|
68
|
-
async executeTool(name, args) {
|
|
69
|
+
async executeTool(name, args, ctx) {
|
|
69
70
|
const tool = this.getTool(name);
|
|
70
71
|
if (!tool) {
|
|
71
72
|
throw new Error(`Unknown tool: ${name}`);
|
|
72
73
|
}
|
|
73
|
-
const result = await tool.execute(args);
|
|
74
|
-
|
|
75
|
-
return formatToolResponse(name, result);
|
|
74
|
+
const result = (await tool.execute(args, ctx));
|
|
75
|
+
return formatStructuredToolResponse(result);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Unregister a tool.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* They are recompiled and template type-checked; their own dependents are not
|
|
24
24
|
* counted.
|
|
25
25
|
*/
|
|
26
|
-
import { type MCPTool } from '../types.js';
|
|
26
|
+
import { type MCPTool, type ToolAnnotations } from '../types.js';
|
|
27
27
|
import { type BuildScopeSymbolImpact } from '@angular-modernizer/core';
|
|
28
28
|
import { type TemplateEdge } from '@angular-modernizer/api';
|
|
29
29
|
import { type ProjectCache } from './helpers/project-cache.js';
|
|
@@ -204,6 +204,14 @@ interface AnalyzeBuildImpactOutput {
|
|
|
204
204
|
* capped by `maxResults`)
|
|
205
205
|
*/
|
|
206
206
|
templateHosts?: TemplateHost[];
|
|
207
|
+
/**
|
|
208
|
+
* Human-readable summary for LLM consumption: the recommendation and the counts
|
|
209
|
+
*/
|
|
210
|
+
summary: string;
|
|
211
|
+
/**
|
|
212
|
+
* Conditions that can make the result incomplete (unresolved library imports)
|
|
213
|
+
*/
|
|
214
|
+
warnings?: string[];
|
|
207
215
|
}
|
|
208
216
|
/**
|
|
209
217
|
* MCP tool for analyzing build impact before transformations.
|
|
@@ -216,9 +224,12 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
|
|
|
216
224
|
*/
|
|
217
225
|
constructor(projects?: ProjectCache | undefined);
|
|
218
226
|
name: string;
|
|
227
|
+
title: string;
|
|
228
|
+
annotations: ToolAnnotations;
|
|
219
229
|
description: string;
|
|
220
230
|
inputSchema: {
|
|
221
231
|
type: string;
|
|
232
|
+
additionalProperties: boolean;
|
|
222
233
|
properties: {
|
|
223
234
|
summaryOnly: {
|
|
224
235
|
readonly type: "boolean";
|
|
@@ -250,6 +261,214 @@ export declare class AnalyzeBuildImpactTool implements MCPTool {
|
|
|
250
261
|
};
|
|
251
262
|
required: string[];
|
|
252
263
|
};
|
|
264
|
+
outputSchema: {
|
|
265
|
+
type: string;
|
|
266
|
+
properties: {
|
|
267
|
+
warnings: {
|
|
268
|
+
readonly type: "array";
|
|
269
|
+
readonly items: {
|
|
270
|
+
readonly type: "string";
|
|
271
|
+
};
|
|
272
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
273
|
+
};
|
|
274
|
+
recommendation: {
|
|
275
|
+
type: string;
|
|
276
|
+
};
|
|
277
|
+
counts: {
|
|
278
|
+
type: string;
|
|
279
|
+
properties: {
|
|
280
|
+
[k: string]: {
|
|
281
|
+
type: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
required: ("changedFiles" | "dependentFiles" | "valueDependentFiles" | "typeOnlyDependentFiles" | "templateDependentFiles" | "reExportFiles" | "affectedFiles" | "affectedModules")[];
|
|
285
|
+
};
|
|
286
|
+
truncated: {
|
|
287
|
+
type: string;
|
|
288
|
+
};
|
|
289
|
+
estimatedBuildScope: {
|
|
290
|
+
type: string;
|
|
291
|
+
properties: {
|
|
292
|
+
strategy: {
|
|
293
|
+
type: string;
|
|
294
|
+
};
|
|
295
|
+
changedFiles: {
|
|
296
|
+
readonly type: "array";
|
|
297
|
+
readonly items: {
|
|
298
|
+
readonly type: "string";
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
dependentFiles: {
|
|
302
|
+
readonly type: "array";
|
|
303
|
+
readonly items: {
|
|
304
|
+
readonly type: "string";
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
affectedModules: {
|
|
308
|
+
readonly type: "array";
|
|
309
|
+
readonly items: {
|
|
310
|
+
readonly type: "string";
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
estimatedBuildTime: {
|
|
314
|
+
type: string;
|
|
315
|
+
};
|
|
316
|
+
valueDependentFiles: {
|
|
317
|
+
readonly type: "array";
|
|
318
|
+
readonly items: {
|
|
319
|
+
readonly type: "string";
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
typeOnlyDependentFiles: {
|
|
323
|
+
readonly type: "array";
|
|
324
|
+
readonly items: {
|
|
325
|
+
readonly type: "string";
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
reExportFiles: {
|
|
329
|
+
readonly type: "array";
|
|
330
|
+
readonly items: {
|
|
331
|
+
readonly type: "string";
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
templateDependentFiles: {
|
|
335
|
+
readonly type: "array";
|
|
336
|
+
readonly items: {
|
|
337
|
+
readonly type: "string";
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
changeSource: {
|
|
341
|
+
type: string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
required: string[];
|
|
345
|
+
};
|
|
346
|
+
affectedFiles: {
|
|
347
|
+
readonly type: "array";
|
|
348
|
+
readonly items: {
|
|
349
|
+
readonly type: "string";
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
affectedModules: {
|
|
353
|
+
readonly type: "array";
|
|
354
|
+
readonly items: {
|
|
355
|
+
readonly type: "string";
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
estimatedBuildTime: {
|
|
359
|
+
type: string;
|
|
360
|
+
};
|
|
361
|
+
mappedFiles: {
|
|
362
|
+
type: string;
|
|
363
|
+
items: {
|
|
364
|
+
type: string;
|
|
365
|
+
properties: {
|
|
366
|
+
file: {
|
|
367
|
+
type: string;
|
|
368
|
+
};
|
|
369
|
+
mappedTo: {
|
|
370
|
+
readonly type: "array";
|
|
371
|
+
readonly items: {
|
|
372
|
+
readonly type: "string";
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
required: string[];
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
unresolvedFiles: {
|
|
380
|
+
type: string;
|
|
381
|
+
items: {
|
|
382
|
+
type: string;
|
|
383
|
+
properties: {
|
|
384
|
+
file: {
|
|
385
|
+
type: string;
|
|
386
|
+
};
|
|
387
|
+
reason: {
|
|
388
|
+
type: string;
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
required: string[];
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
dependencies: {
|
|
395
|
+
type: string;
|
|
396
|
+
items: {
|
|
397
|
+
type: string;
|
|
398
|
+
properties: {
|
|
399
|
+
file: {
|
|
400
|
+
type: string;
|
|
401
|
+
};
|
|
402
|
+
dependents: {
|
|
403
|
+
type: string;
|
|
404
|
+
};
|
|
405
|
+
valueDependents: {
|
|
406
|
+
type: string;
|
|
407
|
+
};
|
|
408
|
+
typeOnlyDependents: {
|
|
409
|
+
type: string;
|
|
410
|
+
};
|
|
411
|
+
templateDependents: {
|
|
412
|
+
type: string;
|
|
413
|
+
};
|
|
414
|
+
isPublicApi: {
|
|
415
|
+
type: string;
|
|
416
|
+
};
|
|
417
|
+
affectedModule: {
|
|
418
|
+
type: string;
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
required: string[];
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
symbolImpacts: {
|
|
425
|
+
type: string;
|
|
426
|
+
items: {
|
|
427
|
+
type: string;
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
templateHosts: {
|
|
431
|
+
type: string;
|
|
432
|
+
items: {
|
|
433
|
+
type: string;
|
|
434
|
+
properties: {
|
|
435
|
+
file: {
|
|
436
|
+
type: string;
|
|
437
|
+
};
|
|
438
|
+
component: {
|
|
439
|
+
type: string;
|
|
440
|
+
};
|
|
441
|
+
uses: {
|
|
442
|
+
type: string;
|
|
443
|
+
items: {
|
|
444
|
+
type: string;
|
|
445
|
+
properties: {
|
|
446
|
+
className: {
|
|
447
|
+
type: string;
|
|
448
|
+
};
|
|
449
|
+
via: {
|
|
450
|
+
type: string;
|
|
451
|
+
};
|
|
452
|
+
file: {
|
|
453
|
+
type: string;
|
|
454
|
+
};
|
|
455
|
+
templateFile: {
|
|
456
|
+
type: string;
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
required: string[];
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
required: string[];
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
summary: {
|
|
467
|
+
type: string;
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
required: string[];
|
|
471
|
+
};
|
|
253
472
|
execute(args: Record<string, unknown>): Promise<AnalyzeBuildImpactOutput>;
|
|
254
473
|
/**
|
|
255
474
|
* Splits the requested files into files of the TypeScript program, `.html`
|
|
@@ -29,7 +29,39 @@ import { findTemplateOwnerFiles, } from '@angular-modernizer/api';
|
|
|
29
29
|
import { existsSync } from 'node:fs';
|
|
30
30
|
import { join } from 'node:path';
|
|
31
31
|
import { findTsConfig } from './helpers/find-ts-config.js';
|
|
32
|
+
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
33
|
+
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
32
34
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
35
|
+
const BUILD_IMPACT_COUNT_KEYS = [
|
|
36
|
+
'changedFiles',
|
|
37
|
+
'dependentFiles',
|
|
38
|
+
'valueDependentFiles',
|
|
39
|
+
'typeOnlyDependentFiles',
|
|
40
|
+
'templateDependentFiles',
|
|
41
|
+
'reExportFiles',
|
|
42
|
+
'affectedFiles',
|
|
43
|
+
'affectedModules',
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Text summary: the recommendation, then the counts and what the lists hold.
|
|
47
|
+
*/
|
|
48
|
+
function describeBuildImpact(result, strategy, summaryOnly) {
|
|
49
|
+
const c = result.counts;
|
|
50
|
+
const lines = [
|
|
51
|
+
result.recommendation,
|
|
52
|
+
`${c.changedFiles} changed, ${c.dependentFiles} dependent file(s) (${c.valueDependentFiles} value, ` +
|
|
53
|
+
`${c.typeOnlyDependentFiles} type-only, ${c.templateDependentFiles} template host(s)), ` +
|
|
54
|
+
`${c.reExportFiles} re-export(s), ${c.affectedModules} module(s); strategy ${strategy}, ` +
|
|
55
|
+
`about ${result.estimatedBuildTime} s build.`,
|
|
56
|
+
];
|
|
57
|
+
if (summaryOnly) {
|
|
58
|
+
lines.push('File lists omitted (summaryOnly).');
|
|
59
|
+
}
|
|
60
|
+
else if (result.truncated) {
|
|
61
|
+
lines.push('File lists capped at maxResults; counts cover everything.');
|
|
62
|
+
}
|
|
63
|
+
return lines.join('\n');
|
|
64
|
+
}
|
|
33
65
|
/** Groups template edges by host component file. */
|
|
34
66
|
function toTemplateHosts(edges) {
|
|
35
67
|
const hosts = new Map();
|
|
@@ -54,13 +86,21 @@ export class AnalyzeBuildImpactTool {
|
|
|
54
86
|
this.projects = projects;
|
|
55
87
|
}
|
|
56
88
|
name = 'analyze-build-impact';
|
|
89
|
+
title = 'Analyze Build Impact';
|
|
90
|
+
annotations = {
|
|
91
|
+
readOnlyHint: true,
|
|
92
|
+
destructiveHint: false,
|
|
93
|
+
idempotentHint: true,
|
|
94
|
+
openWorldHint: false,
|
|
95
|
+
};
|
|
57
96
|
description = 'Analyze build impact before transformations. Estimates affected files, transitive dependents, Angular modules, build time, and provides clear recommendations for AI usage. Helps determine if a transformation is safe to proceed. ' +
|
|
58
97
|
'External .html templates are mapped to their component files. Host components that use a changed component, ' +
|
|
59
98
|
'directive or pipe only in their template (NgModule declarations) are listed as templateHosts. ' +
|
|
60
|
-
'The recommendation and counts come first; ' +
|
|
99
|
+
'The recommendation and counts come first, summary repeats them as text; ' +
|
|
61
100
|
'use summaryOnly to skip the file lists or maxResults to cap them.';
|
|
62
101
|
inputSchema = {
|
|
63
102
|
type: 'object',
|
|
103
|
+
additionalProperties: false,
|
|
64
104
|
properties: {
|
|
65
105
|
projectPath: {
|
|
66
106
|
type: 'string',
|
|
@@ -84,6 +124,105 @@ export class AnalyzeBuildImpactTool {
|
|
|
84
124
|
},
|
|
85
125
|
required: ['projectPath', 'filesToChange'],
|
|
86
126
|
};
|
|
127
|
+
outputSchema = {
|
|
128
|
+
type: 'object',
|
|
129
|
+
properties: {
|
|
130
|
+
recommendation: { type: 'string' },
|
|
131
|
+
counts: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
properties: Object.fromEntries(BUILD_IMPACT_COUNT_KEYS.map((k) => [k, { type: 'integer' }])),
|
|
134
|
+
required: [...BUILD_IMPACT_COUNT_KEYS],
|
|
135
|
+
},
|
|
136
|
+
truncated: { type: 'boolean' },
|
|
137
|
+
estimatedBuildScope: {
|
|
138
|
+
type: 'object',
|
|
139
|
+
properties: {
|
|
140
|
+
strategy: { type: 'string' },
|
|
141
|
+
changedFiles: STRING_ARRAY,
|
|
142
|
+
dependentFiles: STRING_ARRAY,
|
|
143
|
+
affectedModules: STRING_ARRAY,
|
|
144
|
+
estimatedBuildTime: { type: 'number' },
|
|
145
|
+
valueDependentFiles: STRING_ARRAY,
|
|
146
|
+
typeOnlyDependentFiles: STRING_ARRAY,
|
|
147
|
+
reExportFiles: STRING_ARRAY,
|
|
148
|
+
templateDependentFiles: STRING_ARRAY,
|
|
149
|
+
changeSource: { type: 'string' },
|
|
150
|
+
},
|
|
151
|
+
required: ['strategy', 'changedFiles', 'estimatedBuildTime', 'changeSource'],
|
|
152
|
+
},
|
|
153
|
+
affectedFiles: STRING_ARRAY,
|
|
154
|
+
affectedModules: STRING_ARRAY,
|
|
155
|
+
estimatedBuildTime: { type: 'number' },
|
|
156
|
+
mappedFiles: {
|
|
157
|
+
type: 'array',
|
|
158
|
+
items: {
|
|
159
|
+
type: 'object',
|
|
160
|
+
properties: { file: { type: 'string' }, mappedTo: STRING_ARRAY },
|
|
161
|
+
required: ['file', 'mappedTo'],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
unresolvedFiles: {
|
|
165
|
+
type: 'array',
|
|
166
|
+
items: {
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: { file: { type: 'string' }, reason: { type: 'string' } },
|
|
169
|
+
required: ['file', 'reason'],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
dependencies: {
|
|
173
|
+
type: 'array',
|
|
174
|
+
items: {
|
|
175
|
+
type: 'object',
|
|
176
|
+
properties: {
|
|
177
|
+
file: { type: 'string' },
|
|
178
|
+
dependents: { type: 'integer' },
|
|
179
|
+
valueDependents: { type: 'integer' },
|
|
180
|
+
typeOnlyDependents: { type: 'integer' },
|
|
181
|
+
templateDependents: { type: 'integer' },
|
|
182
|
+
isPublicApi: { type: 'boolean' },
|
|
183
|
+
affectedModule: { type: 'string' },
|
|
184
|
+
},
|
|
185
|
+
required: ['file', 'dependents', 'isPublicApi'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
symbolImpacts: { type: 'array', items: { type: 'object' } },
|
|
189
|
+
templateHosts: {
|
|
190
|
+
type: 'array',
|
|
191
|
+
items: {
|
|
192
|
+
type: 'object',
|
|
193
|
+
properties: {
|
|
194
|
+
file: { type: 'string' },
|
|
195
|
+
component: { type: 'string' },
|
|
196
|
+
uses: {
|
|
197
|
+
type: 'array',
|
|
198
|
+
items: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
properties: {
|
|
201
|
+
className: { type: 'string' },
|
|
202
|
+
via: { type: 'string' },
|
|
203
|
+
file: { type: 'string' },
|
|
204
|
+
templateFile: { type: 'string' },
|
|
205
|
+
},
|
|
206
|
+
required: ['className', 'via', 'file', 'templateFile'],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
required: ['file', 'component', 'uses'],
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
summary: { type: 'string' },
|
|
214
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
215
|
+
},
|
|
216
|
+
required: [
|
|
217
|
+
'recommendation',
|
|
218
|
+
'counts',
|
|
219
|
+
'truncated',
|
|
220
|
+
'estimatedBuildScope',
|
|
221
|
+
'estimatedBuildTime',
|
|
222
|
+
'dependencies',
|
|
223
|
+
'summary',
|
|
224
|
+
],
|
|
225
|
+
};
|
|
87
226
|
async execute(args) {
|
|
88
227
|
const params = args;
|
|
89
228
|
if (!params.projectPath) {
|
|
@@ -216,10 +355,11 @@ export class AnalyzeBuildImpactTool {
|
|
|
216
355
|
: {}),
|
|
217
356
|
changeSource: buildScope.changeSource ?? 'forced',
|
|
218
357
|
};
|
|
219
|
-
|
|
358
|
+
const truncated = lists.truncated || (templateHosts?.truncated ?? false);
|
|
359
|
+
const result = {
|
|
220
360
|
recommendation,
|
|
221
361
|
counts,
|
|
222
|
-
truncated
|
|
362
|
+
truncated,
|
|
223
363
|
estimatedBuildScope,
|
|
224
364
|
...(lists.affectedFiles ? { affectedFiles: lists.affectedFiles } : {}),
|
|
225
365
|
...(lists.affectedModules ? { affectedModules: lists.affectedModules } : {}),
|
|
@@ -234,6 +374,8 @@ export class AnalyzeBuildImpactTool {
|
|
|
234
374
|
? { templateHosts: templateHosts.items }
|
|
235
375
|
: {}),
|
|
236
376
|
};
|
|
377
|
+
const warnings = this.projects?.warnings(tsConfigPath) ?? [];
|
|
378
|
+
return withWarnings({ ...result, summary: describeBuildImpact(result, strategy, compact.summaryOnly) }, warnings);
|
|
237
379
|
}
|
|
238
380
|
/**
|
|
239
381
|
* Splits the requested files into files of the TypeScript program, `.html`
|