@angular-modernizer/adapter-mcp 0.3.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -282
- package/dist/cli.js +21 -13
- package/dist/core/project-analyzer.d.ts +3 -12
- package/dist/core/project-analyzer.js +3 -12
- package/dist/index.d.ts +122 -6
- package/dist/index.js +49 -5
- package/dist/mcp-watcher.d.ts +32 -7
- package/dist/mcp-watcher.js +16 -15
- package/dist/scan-host/scan-host.d.ts +119 -0
- package/dist/scan-host/scan-host.js +376 -0
- package/dist/scan-host/scan-protocol.d.ts +35 -0
- package/dist/scan-host/scan-protocol.js +6 -0
- package/dist/scan-host/scan-worker.d.ts +14 -0
- package/dist/scan-host/scan-worker.js +48 -0
- package/dist/server/limited-stdio-transport.d.ts +75 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +20 -18
- package/dist/server/mcp-server.js +42 -79
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +71 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/tool-registry.d.ts +6 -9
- package/dist/server/tool-registry.js +6 -12
- package/dist/streaming/progress-store.d.ts +22 -5
- package/dist/streaming/progress-store.js +9 -5
- package/dist/tools/analyze-build-impact.d.ts +276 -35
- package/dist/tools/analyze-build-impact.js +175 -28
- package/dist/tools/analyze-core-to-shared.d.ts +176 -16
- package/dist/tools/analyze-core-to-shared.js +124 -19
- package/dist/tools/analyze-parser-performance.d.ts +209 -15
- package/dist/tools/analyze-parser-performance.js +119 -56
- package/dist/tools/analyze-project.d.ts +349 -17
- package/dist/tools/analyze-project.js +282 -97
- package/dist/tools/check-incremental-compatibility.d.ts +74 -12
- package/dist/tools/check-incremental-compatibility.js +69 -10
- package/dist/tools/collect-feedback.d.ts +225 -21
- package/dist/tools/collect-feedback.js +199 -118
- package/dist/tools/compare-health.d.ts +413 -0
- package/dist/tools/compare-health.js +479 -0
- package/dist/tools/extract-libraries.d.ts +200 -24
- package/dist/tools/extract-libraries.js +131 -27
- package/dist/tools/find-angular-symbol.d.ts +92 -24
- package/dist/tools/find-angular-symbol.js +70 -20
- package/dist/tools/find-component-hosts.d.ts +603 -27
- package/dist/tools/find-component-hosts.js +223 -19
- package/dist/tools/find-usages.d.ts +102 -22
- package/dist/tools/find-usages.js +81 -21
- package/dist/tools/get-bootstrap-execution.d.ts +183 -25
- package/dist/tools/get-bootstrap-execution.js +109 -25
- package/dist/tools/get-call-graph.d.ts +127 -12
- package/dist/tools/get-call-graph.js +84 -19
- package/dist/tools/get-operation-progress-tool.d.ts +126 -8
- package/dist/tools/get-operation-progress-tool.js +124 -12
- package/dist/tools/get-operation-progress.d.ts +27 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +182 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/batch-kernel.d.ts +14 -0
- package/dist/tools/helpers/batch-kernel.js +12 -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/compact-output.d.ts +2 -1
- package/dist/tools/helpers/compact-output.js +2 -1
- 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 +99 -0
- package/dist/tools/helpers/health-delta.js +236 -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 +60 -37
- package/dist/tools/helpers/project-cache.js +54 -37
- 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 +25 -13
- package/dist/tools/helpers/rule-runner.js +45 -24
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-engine.d.ts +107 -0
- package/dist/tools/helpers/scan-engine.js +197 -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/suggestion-generator.d.ts +9 -13
- package/dist/tools/helpers/suggestion-generator.js +0 -12
- package/dist/tools/helpers/tool-cache.d.ts +11 -0
- package/dist/tools/helpers/tool-cache.js +15 -0
- package/dist/tools/helpers/tool-context.d.ts +63 -0
- package/dist/tools/helpers/tool-context.js +79 -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 +262 -24
- package/dist/tools/inspect-form-group.js +134 -13
- package/dist/tools/inspect-i18n.d.ts +410 -23
- package/dist/tools/inspect-i18n.js +213 -13
- package/dist/tools/inspect-template.d.ts +260 -22
- package/dist/tools/inspect-template.js +174 -13
- package/dist/tools/learn-patterns.d.ts +210 -13
- package/dist/tools/learn-patterns.js +113 -12
- package/dist/tools/list-imports.d.ts +152 -34
- package/dist/tools/list-imports.js +124 -18
- package/dist/tools/orchestrate-migration.d.ts +159 -14
- package/dist/tools/orchestrate-migration.js +147 -20
- package/dist/tools/parse-stack-trace.d.ts +78 -21
- package/dist/tools/parse-stack-trace.js +44 -7
- package/dist/tools/plan-migration.d.ts +395 -26
- package/dist/tools/plan-migration.js +173 -22
- package/dist/tools/resolve-type.d.ts +57 -9
- package/dist/tools/resolve-type.js +49 -12
- package/dist/tools/review-feedback.d.ts +214 -16
- package/dist/tools/review-feedback.js +142 -57
- package/dist/tools/rollback-changes.d.ts +88 -7
- package/dist/tools/rollback-changes.js +74 -19
- package/dist/tools/run-angular-cli.d.ts +57 -12
- package/dist/tools/run-angular-cli.js +76 -13
- package/dist/tools/run-build.d.ts +127 -13
- package/dist/tools/run-build.js +128 -16
- package/dist/tools/run-schematic.d.ts +82 -12
- package/dist/tools/run-schematic.js +115 -18
- package/dist/tools/scan-all.d.ts +88 -23
- package/dist/tools/scan-all.js +161 -220
- package/dist/tools/scan-angular.d.ts +60 -19
- package/dist/tools/scan-angular.js +100 -141
- package/dist/tools/scan-architecture.d.ts +92 -24
- package/dist/tools/scan-architecture.js +268 -211
- package/dist/tools/scan-solid.d.ts +59 -19
- package/dist/tools/scan-solid.js +98 -139
- package/dist/tools/search-codebase.d.ts +110 -23
- package/dist/tools/search-codebase.js +67 -11
- package/dist/tools/server-status.d.ts +392 -26
- package/dist/tools/server-status.js +260 -27
- package/dist/tools/suggest-improvements.d.ts +105 -10
- package/dist/tools/suggest-improvements.js +91 -51
- package/dist/tools/trace-output-flow.d.ts +713 -26
- package/dist/tools/trace-output-flow.js +396 -33
- 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 +402 -18
- package/dist/tools/transform-code.js +708 -649
- package/dist/tools/validate-before-transform.d.ts +136 -7
- package/dist/tools/validate-before-transform.js +65 -9
- package/dist/tools/validate-project-compatibility.d.ts +82 -15
- package/dist/tools/validate-project-compatibility.js +84 -15
- package/dist/tools/validate-transformation.d.ts +243 -8
- package/dist/tools/validate-transformation.js +127 -23
- package/dist/tools/verify-citations.d.ts +202 -0
- package/dist/tools/verify-citations.js +221 -0
- package/dist/types.d.ts +78 -11
- package/dist/types.js +0 -5
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +31 -20
- 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 +0 -200
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js +0 -7
- 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,221 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
import { CITATION_ATTENTION_STATUSES, CitationVerifier, } from '@angular-modernizer/api';
|
|
3
|
+
import { createNodeCitationFileSource } from './helpers/citation-file-source.js';
|
|
4
|
+
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, truncationNote, } from './helpers/compact-output.js';
|
|
5
|
+
const STATUSES = [
|
|
6
|
+
'ok',
|
|
7
|
+
'unverified',
|
|
8
|
+
'moved',
|
|
9
|
+
'anchor-missing',
|
|
10
|
+
'out-of-range',
|
|
11
|
+
'missing-file',
|
|
12
|
+
'ambiguous',
|
|
13
|
+
];
|
|
14
|
+
/** Attention entries spelled out in the summary; the rest is in `citations`. */
|
|
15
|
+
const SUMMARY_LINES = 20;
|
|
16
|
+
const CITATION_SCHEMA = {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
plan: { type: 'string' },
|
|
20
|
+
planLine: { type: 'integer' },
|
|
21
|
+
text: { type: 'string' },
|
|
22
|
+
status: { type: 'string', enum: [...STATUSES] },
|
|
23
|
+
file: { type: 'string' },
|
|
24
|
+
matched: { type: 'string' },
|
|
25
|
+
foundAt: { type: 'array', items: { type: 'integer' } },
|
|
26
|
+
current: { type: 'string' },
|
|
27
|
+
fileLength: { type: 'integer' },
|
|
28
|
+
candidates: { type: 'array', items: { type: 'string' } },
|
|
29
|
+
},
|
|
30
|
+
required: ['plan', 'planLine', 'text', 'status'],
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* MCP tool that checks the `path:line` citations of Markdown plans against the
|
|
34
|
+
* current code: does the cited file exist, is the line range still in the
|
|
35
|
+
* file, and does the symbol named next to the citation still sit in the range?
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Run it before executing a bug-fix or feature plan (stale line numbers make
|
|
39
|
+
* edits land in the wrong place) and after writing one. Logic lives in the api
|
|
40
|
+
* `CitationVerifier`; the claude-plugin script `verify-citations.mjs` is the
|
|
41
|
+
* same check for sessions without this server.
|
|
42
|
+
*/
|
|
43
|
+
export class VerifyCitationsTool {
|
|
44
|
+
createSource;
|
|
45
|
+
name = 'verify-citations';
|
|
46
|
+
title = 'Verify Plan Citations';
|
|
47
|
+
description = 'Check the path:line citations of Markdown plans (bug-fix plans, feature plans, investigation reports) ' +
|
|
48
|
+
'against the current code. Per citation: ok (the symbol named next to it is inside the cited range), ' +
|
|
49
|
+
'unverified (range exists, no symbol to check; current line text shown), moved (symbol found at other ' +
|
|
50
|
+
'lines: foundAt), anchor-missing (symbol nowhere in the file), out-of-range (file too short), ' +
|
|
51
|
+
'missing-file (similar files listed as candidates), ambiguous (bare file name matches several files). ' +
|
|
52
|
+
'Citations inside fenced code blocks are skipped. Run before executing a plan and after writing one. ' +
|
|
53
|
+
'needsAttention counts moved, anchor-missing, out-of-range, missing-file and ambiguous; those come first ' +
|
|
54
|
+
'in citations. Read-only.';
|
|
55
|
+
annotations = {
|
|
56
|
+
readOnlyHint: true,
|
|
57
|
+
destructiveHint: false,
|
|
58
|
+
idempotentHint: true,
|
|
59
|
+
openWorldHint: false,
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* JSON Schema of the tool arguments.
|
|
63
|
+
* @hidden
|
|
64
|
+
*/
|
|
65
|
+
inputSchema = {
|
|
66
|
+
type: 'object',
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
properties: {
|
|
69
|
+
planPaths: {
|
|
70
|
+
type: 'array',
|
|
71
|
+
items: { type: 'string' },
|
|
72
|
+
minItems: 1,
|
|
73
|
+
description: 'Markdown files to check, absolute or relative to projectRoot (e.g. plan.md and investigation.md of one plan folder).',
|
|
74
|
+
},
|
|
75
|
+
projectRoot: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
description: 'Absolute path of the repository the plans cite. Cited paths resolve from here, then from the plan folder, then by path suffix.',
|
|
78
|
+
},
|
|
79
|
+
...COMPACT_OUTPUT_SCHEMA,
|
|
80
|
+
},
|
|
81
|
+
required: ['planPaths', 'projectRoot'],
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* JSON Schema of the tool result (`structuredContent`).
|
|
85
|
+
* @hidden
|
|
86
|
+
*/
|
|
87
|
+
outputSchema = {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
projectRoot: { type: 'string' },
|
|
91
|
+
plans: {
|
|
92
|
+
type: 'array',
|
|
93
|
+
items: {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
plan: { type: 'string' },
|
|
97
|
+
citations: { type: 'integer' },
|
|
98
|
+
needsAttention: { type: 'integer' },
|
|
99
|
+
},
|
|
100
|
+
required: ['plan', 'citations', 'needsAttention'],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
total: { type: 'integer' },
|
|
104
|
+
needsAttention: { type: 'integer' },
|
|
105
|
+
counts: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: Object.fromEntries(STATUSES.map((s) => [s, { type: 'integer' }])),
|
|
108
|
+
required: [...STATUSES],
|
|
109
|
+
},
|
|
110
|
+
citations: { type: 'array', items: CITATION_SCHEMA },
|
|
111
|
+
truncated: { type: 'boolean' },
|
|
112
|
+
summary: { type: 'string' },
|
|
113
|
+
},
|
|
114
|
+
required: ['projectRoot', 'plans', 'total', 'needsAttention', 'counts', 'truncated', 'summary'],
|
|
115
|
+
};
|
|
116
|
+
constructor(createSource = createNodeCitationFileSource) {
|
|
117
|
+
this.createSource = createSource;
|
|
118
|
+
}
|
|
119
|
+
async execute(args) {
|
|
120
|
+
const { planPaths, projectRoot } = args;
|
|
121
|
+
if (typeof projectRoot !== 'string' || projectRoot === '') {
|
|
122
|
+
throw new Error('projectRoot is required');
|
|
123
|
+
}
|
|
124
|
+
if (!Array.isArray(planPaths) ||
|
|
125
|
+
planPaths.length === 0 ||
|
|
126
|
+
!planPaths.every((p) => typeof p === 'string' && p !== '')) {
|
|
127
|
+
throw new Error('planPaths must be a non-empty array of file paths');
|
|
128
|
+
}
|
|
129
|
+
const compact = parseCompactOptions(args);
|
|
130
|
+
const root = resolve(projectRoot);
|
|
131
|
+
const plans = planPaths.map((p) => (isAbsolute(p) ? p : resolve(root, p)));
|
|
132
|
+
const source = this.createSource(root);
|
|
133
|
+
const missing = plans.filter((p) => !source.isFile(p));
|
|
134
|
+
if (missing.length > 0) {
|
|
135
|
+
throw new Error(`Plan file not found: ${missing.join(', ')}`);
|
|
136
|
+
}
|
|
137
|
+
const reports = new CitationVerifier(root, source).verifyPlans(plans);
|
|
138
|
+
const label = (plan) => relative(root, plan) || plan;
|
|
139
|
+
const all = reports.flatMap((r) => r.results.map((c) => toVerified(label(r.plan), c)));
|
|
140
|
+
const attention = all.filter((c) => CITATION_ATTENTION_STATUSES.has(c.status));
|
|
141
|
+
const counts = Object.fromEntries(STATUSES.map((s) => [s, all.filter((c) => c.status === s).length]));
|
|
142
|
+
const planSummaries = reports.map((r) => ({
|
|
143
|
+
plan: label(r.plan),
|
|
144
|
+
citations: r.results.length,
|
|
145
|
+
needsAttention: r.results.filter((c) => CITATION_ATTENTION_STATUSES.has(c.status)).length,
|
|
146
|
+
}));
|
|
147
|
+
const ordered = [...attention, ...all.filter((c) => !CITATION_ATTENTION_STATUSES.has(c.status))];
|
|
148
|
+
const shown = limitList(ordered, compact.summaryOnly ? undefined : compact.maxResults);
|
|
149
|
+
const summary = buildSummary(planSummaries, all.length, counts, attention, shown.items.length);
|
|
150
|
+
const base = {
|
|
151
|
+
projectRoot: root,
|
|
152
|
+
plans: planSummaries,
|
|
153
|
+
total: all.length,
|
|
154
|
+
needsAttention: attention.length,
|
|
155
|
+
counts,
|
|
156
|
+
};
|
|
157
|
+
if (compact.summaryOnly) {
|
|
158
|
+
return { ...base, truncated: false, summary };
|
|
159
|
+
}
|
|
160
|
+
return { ...base, citations: shown.items, truncated: shown.truncated, summary };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function toVerified(plan, c) {
|
|
164
|
+
return {
|
|
165
|
+
plan,
|
|
166
|
+
planLine: c.planLine,
|
|
167
|
+
text: c.text,
|
|
168
|
+
status: c.status,
|
|
169
|
+
...(c.file === undefined ? {} : { file: c.file }),
|
|
170
|
+
...(c.matched === undefined ? {} : { matched: c.matched }),
|
|
171
|
+
...(c.foundAt === undefined ? {} : { foundAt: c.foundAt }),
|
|
172
|
+
...(c.current === undefined ? {} : { current: c.current }),
|
|
173
|
+
...(c.fileLength === undefined ? {} : { fileLength: c.fileLength }),
|
|
174
|
+
...(c.candidates === undefined ? {} : { candidates: c.candidates }),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function describeCitation(c) {
|
|
178
|
+
const anchor = c.matched === undefined ? '' : ` [${c.matched}]`;
|
|
179
|
+
const where = `${c.plan}:${c.planLine} ${c.text}${anchor}`;
|
|
180
|
+
switch (c.status) {
|
|
181
|
+
case 'moved':
|
|
182
|
+
return `- moved: ${where} -> now at line ${(c.foundAt ?? []).join(', ')} of ${c.file ?? '?'}`;
|
|
183
|
+
case 'anchor-missing':
|
|
184
|
+
return `- anchor-missing: ${where} -> not found in ${c.file ?? '?'}; the line reads "${c.current ?? ''}"`;
|
|
185
|
+
case 'out-of-range':
|
|
186
|
+
return `- out-of-range: ${where} -> ${c.file ?? '?'} has ${c.fileLength ?? 0} lines`;
|
|
187
|
+
case 'missing-file': {
|
|
188
|
+
const similar = c.candidates ?? [];
|
|
189
|
+
return `- missing-file: ${where}${similar.length > 0 ? ` -> similar: ${similar.join(', ')}` : ''}`;
|
|
190
|
+
}
|
|
191
|
+
case 'ambiguous':
|
|
192
|
+
return `- ambiguous: ${where} -> ${(c.candidates ?? []).slice(0, 5).join(', ')}`;
|
|
193
|
+
case 'ok':
|
|
194
|
+
case 'unverified':
|
|
195
|
+
return `- ${c.status}: ${where}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function buildSummary(plans, total, counts, attention, shown) {
|
|
199
|
+
const byStatus = STATUSES.filter((s) => counts[s] > 0)
|
|
200
|
+
.map((s) => `${counts[s]} ${s}`)
|
|
201
|
+
.join(', ');
|
|
202
|
+
const lines = [
|
|
203
|
+
`${total} citation(s) in ${plans.length} plan(s)${byStatus === '' ? '.' : `: ${byStatus}.`}`,
|
|
204
|
+
];
|
|
205
|
+
if (attention.length === 0) {
|
|
206
|
+
lines.push('No citation needs attention.');
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
lines.push(`${attention.length} need attention:`);
|
|
210
|
+
lines.push(...attention.slice(0, SUMMARY_LINES).map(describeCitation));
|
|
211
|
+
if (attention.length > SUMMARY_LINES) {
|
|
212
|
+
lines.push(`... and ${attention.length - SUMMARY_LINES} more in citations.`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const note = truncationNote(shown, total, 'citations');
|
|
216
|
+
if (note !== undefined && shown > 0) {
|
|
217
|
+
lines.push(note);
|
|
218
|
+
}
|
|
219
|
+
return lines.join('\n');
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=verify-citations.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - MCP Types
|
|
3
|
-
*
|
|
4
|
-
* TypeScript type definitions for MCP protocol and tools.
|
|
5
|
-
*/
|
|
6
1
|
import type { ParallelOptions } from '@angular-modernizer/core';
|
|
7
2
|
/**
|
|
8
|
-
* MCP Tool interface as defined by the Model Context Protocol.
|
|
3
|
+
* MCP Tool interface as defined by the Model Context Protocol. Every tool
|
|
4
|
+
* class of this package implements it.
|
|
9
5
|
*/
|
|
10
6
|
export interface MCPTool {
|
|
11
7
|
/**
|
|
@@ -20,45 +16,110 @@ export interface MCPTool {
|
|
|
20
16
|
* JSON Schema for tool input validation.
|
|
21
17
|
*/
|
|
22
18
|
inputSchema: object;
|
|
19
|
+
/** Display name for clients (MCP 2025-06-18). */
|
|
20
|
+
title?: string;
|
|
21
|
+
/** Behavior hints for clients (MCP 2025-03-26); hints, not guarantees. */
|
|
22
|
+
annotations?: ToolAnnotations;
|
|
23
|
+
/**
|
|
24
|
+
* JSON Schema of the result object (MCP 2025-06-18). Every tool answers
|
|
25
|
+
* with `structuredContent` plus a text block with its `summary`; with a
|
|
26
|
+
* schema the SDK validates `structuredContent` against it. All tools of
|
|
27
|
+
* this package set one.
|
|
28
|
+
*/
|
|
29
|
+
outputSchema?: object;
|
|
23
30
|
/**
|
|
24
31
|
* Execute the tool with given arguments.
|
|
25
32
|
* @param args - Tool arguments validated against inputSchema
|
|
33
|
+
* @param ctx - Cancellation and progress of the MCP request (absent in direct calls)
|
|
26
34
|
* @returns Tool execution result
|
|
27
35
|
*/
|
|
28
|
-
execute(args: Record<string, unknown
|
|
36
|
+
execute(args: Record<string, unknown>, ctx?: ToolContext): Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reports progress of a running tool call. `progress` grows with every call;
|
|
40
|
+
* `total` is the expected end value when known.
|
|
41
|
+
*/
|
|
42
|
+
export type ProgressFn = (progress: number, total?: number, message?: string) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Per-call context of an MCP request. `signal` aborts when the client sends
|
|
45
|
+
* `notifications/cancelled` (the SDK then sends no response); `progress` is
|
|
46
|
+
* set only when the client asked for progress with a `progressToken`.
|
|
47
|
+
*/
|
|
48
|
+
export interface ToolContext {
|
|
49
|
+
/** Aborted when the client cancels the request. */
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
/** Sends progress notifications; set only with a `progressToken`. */
|
|
52
|
+
progress?: ProgressFn;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* MCP tool annotations. `readOnlyHint` means the tool does not change its
|
|
56
|
+
* environment (writing the analyzer's own cache does not count);
|
|
57
|
+
* `destructiveHint` and `idempotentHint` only matter when it is not read-only.
|
|
58
|
+
*/
|
|
59
|
+
export interface ToolAnnotations {
|
|
60
|
+
/** The tool does not change its environment. */
|
|
61
|
+
readOnlyHint?: boolean;
|
|
62
|
+
/** The tool can overwrite or delete project files. */
|
|
63
|
+
destructiveHint?: boolean;
|
|
64
|
+
/** Repeating a call with the same arguments has no further effect. */
|
|
65
|
+
idempotentHint?: boolean;
|
|
66
|
+
/** The tool reaches outside the project (arbitrary commands or packages). */
|
|
67
|
+
openWorldHint?: boolean;
|
|
29
68
|
}
|
|
30
69
|
/**
|
|
31
70
|
* JSON-RPC 2.0 request message.
|
|
71
|
+
*
|
|
72
|
+
* @deprecated Not used since the server runs on the MCP TypeScript SDK; will be removed in 2.0.
|
|
32
73
|
*/
|
|
33
74
|
export interface JsonRpcRequest {
|
|
75
|
+
/** Protocol version, always `'2.0'`. */
|
|
34
76
|
jsonrpc: '2.0';
|
|
77
|
+
/** Request id, echoed in the response. */
|
|
35
78
|
id: number | string;
|
|
79
|
+
/** Method name. */
|
|
36
80
|
method: string;
|
|
81
|
+
/** Method parameters. */
|
|
37
82
|
params?: Record<string, unknown>;
|
|
38
83
|
}
|
|
39
84
|
/**
|
|
40
85
|
* JSON-RPC 2.0 response message.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Not used since the server runs on the MCP TypeScript SDK; will be removed in 2.0.
|
|
41
88
|
*/
|
|
42
89
|
export interface JsonRpcResponse {
|
|
90
|
+
/** Protocol version, always `'2.0'`. */
|
|
43
91
|
jsonrpc: '2.0';
|
|
92
|
+
/** Id of the request; `null` when it could not be read. */
|
|
44
93
|
id: number | string | null;
|
|
94
|
+
/** Result on success. */
|
|
45
95
|
result?: unknown;
|
|
96
|
+
/** Error on failure. */
|
|
46
97
|
error?: JsonRpcError;
|
|
47
98
|
}
|
|
48
99
|
/**
|
|
49
100
|
* JSON-RPC 2.0 error object.
|
|
101
|
+
*
|
|
102
|
+
* @deprecated Not used since the server runs on the MCP TypeScript SDK; will be removed in 2.0.
|
|
50
103
|
*/
|
|
51
104
|
export interface JsonRpcError {
|
|
105
|
+
/** JSON-RPC error code, e.g. `-32602` for invalid params. */
|
|
52
106
|
code: number;
|
|
107
|
+
/** Error message. */
|
|
53
108
|
message: string;
|
|
109
|
+
/** Additional error details. */
|
|
54
110
|
data?: unknown;
|
|
55
111
|
}
|
|
56
112
|
/**
|
|
57
113
|
* JSON-RPC 2.0 notification message (no response expected).
|
|
114
|
+
*
|
|
115
|
+
* @deprecated Not used since the server runs on the MCP TypeScript SDK; will be removed in 2.0.
|
|
58
116
|
*/
|
|
59
117
|
export interface JsonRpcNotification {
|
|
118
|
+
/** Protocol version, always `'2.0'`. */
|
|
60
119
|
jsonrpc: '2.0';
|
|
120
|
+
/** Method name. */
|
|
61
121
|
method: string;
|
|
122
|
+
/** Method parameters. */
|
|
62
123
|
params?: Record<string, unknown>;
|
|
63
124
|
}
|
|
64
125
|
/**
|
|
@@ -66,15 +127,18 @@ export interface JsonRpcNotification {
|
|
|
66
127
|
*/
|
|
67
128
|
export interface MCPServerConfig {
|
|
68
129
|
/**
|
|
69
|
-
* Port for HTTP transport
|
|
130
|
+
* Port for HTTP transport. Never read: the server speaks stdio only.
|
|
131
|
+
* @deprecated Will be removed in 2.0.
|
|
70
132
|
*/
|
|
71
133
|
port?: number;
|
|
72
134
|
/**
|
|
73
|
-
* Tool execution timeout in milliseconds.
|
|
135
|
+
* Tool execution timeout in milliseconds. Not enforced by the server.
|
|
136
|
+
* @deprecated Will be removed in 2.0.
|
|
74
137
|
*/
|
|
75
138
|
timeout?: number;
|
|
76
139
|
/**
|
|
77
|
-
* Maximum number of concurrent tool executions.
|
|
140
|
+
* Maximum number of concurrent tool executions. Not enforced by the server.
|
|
141
|
+
* @deprecated Will be removed in 2.0.
|
|
78
142
|
*/
|
|
79
143
|
maxConcurrentTools?: number;
|
|
80
144
|
/**
|
|
@@ -82,7 +146,8 @@ export interface MCPServerConfig {
|
|
|
82
146
|
*/
|
|
83
147
|
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
84
148
|
/**
|
|
85
|
-
* Enable performance metrics collection.
|
|
149
|
+
* Enable performance metrics collection. Not read by the server.
|
|
150
|
+
* @deprecated Will be removed in 2.0.
|
|
86
151
|
*/
|
|
87
152
|
enableMetrics?: boolean;
|
|
88
153
|
/**
|
|
@@ -95,6 +160,8 @@ export interface MCPServerConfig {
|
|
|
95
160
|
}
|
|
96
161
|
/**
|
|
97
162
|
* Tool execution context for tracking and metrics.
|
|
163
|
+
*
|
|
164
|
+
* @deprecated Not used since the server runs on the MCP TypeScript SDK; will be removed in 2.0.
|
|
98
165
|
*/
|
|
99
166
|
export interface ToolExecutionContext {
|
|
100
167
|
/**
|
package/dist/types.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - MCP Types
|
|
3
|
-
*
|
|
4
|
-
* TypeScript type definitions for MCP protocol and tools.
|
|
5
|
-
*/
|
|
6
1
|
/**
|
|
7
2
|
* Helper to convert MCP OrchestrationOptions to Core ParallelOptions.
|
|
8
3
|
* Note: parallel/incremental/baseBranch are control flow params, not ParallelOptions.
|
|
@@ -1,72 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @angular-modernizer/adapter-mcp - Tool Response Formatter
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Every tool answers with its result object as `structuredContent` and the
|
|
5
|
+
* result's `summary` as the text block.
|
|
6
6
|
*/
|
|
7
|
-
interface AnalyzeProjectResult {
|
|
8
|
-
framework?: {
|
|
9
|
-
type?: string;
|
|
10
|
-
version?: string;
|
|
11
|
-
};
|
|
12
|
-
architecture?: {
|
|
13
|
-
type?: string;
|
|
14
|
-
layers?: string[];
|
|
15
|
-
};
|
|
16
|
-
summary?: {
|
|
17
|
-
totalFiles?: number;
|
|
18
|
-
analyzedFiles?: number;
|
|
19
|
-
duration?: number;
|
|
20
|
-
};
|
|
21
|
-
pagination?: {
|
|
22
|
-
totalResults: number;
|
|
23
|
-
returnedResults: number;
|
|
24
|
-
offset: number;
|
|
25
|
-
hasMore: boolean;
|
|
26
|
-
};
|
|
27
|
-
results?: unknown[];
|
|
28
|
-
technologyStack?: {
|
|
29
|
-
libraries?: {
|
|
30
|
-
name: string;
|
|
31
|
-
version?: string;
|
|
32
|
-
}[];
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
interface ScanArchitectureResult {
|
|
36
|
-
summary?: {
|
|
37
|
-
totalViolations?: number;
|
|
38
|
-
analyzedFiles?: number;
|
|
39
|
-
bySeverity?: Record<string, number>;
|
|
40
|
-
byCategory?: Record<string, number>;
|
|
41
|
-
};
|
|
42
|
-
pagination?: {
|
|
43
|
-
totalResults: number;
|
|
44
|
-
returnedResults: number;
|
|
45
|
-
offset: number;
|
|
46
|
-
hasMore: boolean;
|
|
47
|
-
};
|
|
48
|
-
violations?: {
|
|
49
|
-
ruleId: string;
|
|
50
|
-
severity: string;
|
|
51
|
-
filePath: string;
|
|
52
|
-
line?: number;
|
|
53
|
-
message: string;
|
|
54
|
-
}[];
|
|
55
|
-
metadata?: {
|
|
56
|
-
duration?: number;
|
|
57
|
-
rulesExecuted?: string[];
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
7
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
8
|
+
* A result that reports its own failure: top-level `success: false` or
|
|
9
|
+
* `status: 'failed'` (transform-code, run-angular-cli, run-build,
|
|
10
|
+
* run-schematic, rollback-changes, orchestrate-migration). It goes out with
|
|
11
|
+
* `isError: true` with the same content. `status: 'partial'` is a success.
|
|
12
|
+
*/
|
|
13
|
+
export declare function reportsFailure(result: object): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Tool result as MCP content: the object itself as `structuredContent`, and a
|
|
16
|
+
* text block with the tool's `summary`. Without a summary the text block
|
|
17
|
+
* holds the compact JSON.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* The text used to repeat the whole result as compact JSON after the summary
|
|
21
|
+
* (the spec's SHOULD for clients that only read `content`). Measured on a
|
|
22
|
+
* 3900-file app that made the 13 investigation answers 1.62x the size of the
|
|
23
|
+
* Markdown format, a large get-call-graph 917 instead of 426 KB, because the
|
|
24
|
+
* summary then appeared three times. Claude Code shows the model only
|
|
25
|
+
* `structuredContent`; the summary alone keeps the text readable at 0.84x.
|
|
63
26
|
*/
|
|
64
|
-
export declare function
|
|
27
|
+
export declare function formatStructuredToolResponse(result: Record<string, unknown>): {
|
|
65
28
|
content: {
|
|
66
29
|
type: string;
|
|
67
30
|
text: string;
|
|
68
31
|
}[];
|
|
32
|
+
structuredContent: Record<string, unknown>;
|
|
69
33
|
isError: boolean;
|
|
70
34
|
};
|
|
71
|
-
export {};
|
|
72
35
|
//# sourceMappingURL=format-tool-response.d.ts.map
|
|
@@ -1,149 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @angular-modernizer/adapter-mcp - Tool Response Formatter
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Every tool answers with its result object as `structuredContent` and the
|
|
5
|
+
* result's `summary` as the text block.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* A result that reports its own failure: top-level `success: false` or
|
|
9
|
+
* `status: 'failed'` (transform-code, run-angular-cli, run-build,
|
|
10
|
+
* run-schematic, rollback-changes, orchestrate-migration). It goes out with
|
|
11
|
+
* `isError: true` with the same content. `status: 'partial'` is a success.
|
|
9
12
|
*/
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
lines.push('');
|
|
14
|
-
}
|
|
13
|
+
export function reportsFailure(result) {
|
|
14
|
+
return (('success' in result && result.success === false) ||
|
|
15
|
+
('status' in result && result.status === 'failed'));
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// Architecture
|
|
29
|
-
addSection(lines, !!result.architecture, () => {
|
|
30
|
-
lines.push('## Architecture', `- **Type:** ${result.architecture.type ?? 'Unknown'}`);
|
|
31
|
-
if (result.architecture.layers) {
|
|
32
|
-
lines.push(`- **Layers:** ${result.architecture.layers.join(', ')}`);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
// Summary stats
|
|
36
|
-
addSection(lines, !!result.summary, () => {
|
|
37
|
-
const { totalFiles = 0, analyzedFiles = 0, duration = 0 } = result.summary;
|
|
38
|
-
lines.push('## Summary', `- **Total Files:** ${totalFiles}`, `- **Analyzed Files:** ${analyzedFiles}`, `- **Duration:** ${duration}ms`);
|
|
39
|
-
});
|
|
40
|
-
// Pagination info
|
|
41
|
-
addSection(lines, !!(result.pagination && result.results?.length), () => {
|
|
42
|
-
const { totalResults, returnedResults, offset, hasMore } = result.pagination;
|
|
43
|
-
lines.push('## File Analysis Details', `- **Total Files Analyzed:** ${totalResults}`, `- **Details Returned:** ${returnedResults} (offset: ${offset})`);
|
|
44
|
-
if (hasMore) {
|
|
45
|
-
lines.push('- **More available:** Use resultOffset parameter to get additional file details');
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
// Technology stack
|
|
49
|
-
addSection(lines, !!result.technologyStack?.libraries?.length, () => {
|
|
50
|
-
const libs = result.technologyStack.libraries;
|
|
51
|
-
lines.push('## Key Technologies');
|
|
52
|
-
libs.slice(0, 10).forEach((lib) => {
|
|
53
|
-
lines.push(`- ${lib.name}${lib.version ? ` (${lib.version})` : ''}`);
|
|
54
|
-
});
|
|
55
|
-
if (libs.length > 10) {
|
|
56
|
-
lines.push(`- ... and ${libs.length - 10} more`);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return lines.join('\n');
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Format scan-architecture result into human-readable summary
|
|
63
|
-
*/
|
|
64
|
-
function formatScanArchitectureSummary(result) {
|
|
65
|
-
const lines = ['# Architecture Scan Results', ''];
|
|
66
|
-
// Summary stats
|
|
67
|
-
addSection(lines, !!result.summary, () => {
|
|
68
|
-
const { totalViolations = 0, analyzedFiles = 0, bySeverity, byCategory, } = result.summary;
|
|
69
|
-
lines.push('## Summary', `- **Total Violations:** ${totalViolations}`, `- **Files Analyzed:** ${analyzedFiles}`);
|
|
70
|
-
if (bySeverity) {
|
|
71
|
-
lines.push('', '### By Severity');
|
|
72
|
-
Object.entries(bySeverity).forEach(([severity, count]) => {
|
|
73
|
-
lines.push(`- **${severity}:** ${String(count)}`);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (byCategory) {
|
|
77
|
-
lines.push('', '### By Category');
|
|
78
|
-
Object.entries(byCategory).forEach(([category, count]) => {
|
|
79
|
-
lines.push(`- **${category}:** ${String(count)}`);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
// Pagination info
|
|
84
|
-
addSection(lines, !!result.pagination, () => {
|
|
85
|
-
const { returnedResults, totalResults, offset, hasMore } = result.pagination;
|
|
86
|
-
lines.push('## Violations Returned', `- **Showing:** ${returnedResults} of ${totalResults} violations`, `- **Offset:** ${offset}`);
|
|
87
|
-
if (hasMore) {
|
|
88
|
-
lines.push('- **More available:** Use resultOffset parameter to get next page');
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// Show first few violations
|
|
92
|
-
addSection(lines, !!result.violations?.length, () => {
|
|
93
|
-
const violations = result.violations;
|
|
94
|
-
lines.push('## Sample Violations');
|
|
95
|
-
violations.slice(0, 5).forEach((v, i) => {
|
|
96
|
-
lines.push(`\n### ${i + 1}. ${v.ruleId}`, `- **Severity:** ${v.severity}`, `- **File:** ${v.filePath}`);
|
|
97
|
-
if (v.line) {
|
|
98
|
-
lines.push(`- **Line:** ${v.line}`);
|
|
99
|
-
}
|
|
100
|
-
lines.push(`- **Message:** ${v.message}`);
|
|
101
|
-
});
|
|
102
|
-
if (violations.length > 5) {
|
|
103
|
-
lines.push(`\n... and ${violations.length - 5} more violations (see structured data below)`);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
// Metadata
|
|
107
|
-
addSection(lines, !!result.metadata, () => {
|
|
108
|
-
const { duration = 0, rulesExecuted } = result.metadata;
|
|
109
|
-
lines.push('## Metadata', `- **Duration:** ${duration}ms`, `- **Rules Executed:** ${rulesExecuted?.length ?? 0}`);
|
|
110
|
-
});
|
|
111
|
-
return lines.join('\n');
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Format tool result with human-readable summary + structured data
|
|
115
|
-
* according to MCP specification.
|
|
18
|
+
* Tool result as MCP content: the object itself as `structuredContent`, and a
|
|
19
|
+
* text block with the tool's `summary`. Without a summary the text block
|
|
20
|
+
* holds the compact JSON.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The text used to repeat the whole result as compact JSON after the summary
|
|
24
|
+
* (the spec's SHOULD for clients that only read `content`). Measured on a
|
|
25
|
+
* 3900-file app that made the 13 investigation answers 1.62x the size of the
|
|
26
|
+
* Markdown format, a large get-call-graph 917 instead of 426 KB, because the
|
|
27
|
+
* summary then appeared three times. Claude Code shows the model only
|
|
28
|
+
* `structuredContent`; the summary alone keeps the text readable at 0.84x.
|
|
116
29
|
*/
|
|
117
|
-
export function
|
|
118
|
-
|
|
119
|
-
// Generate human-readable summary based on tool type
|
|
120
|
-
switch (toolName) {
|
|
121
|
-
case 'analyze-project':
|
|
122
|
-
summary = formatAnalyzeProjectSummary(result);
|
|
123
|
-
break;
|
|
124
|
-
case 'scan-architecture':
|
|
125
|
-
case 'scan-solid':
|
|
126
|
-
case 'scan-angular':
|
|
127
|
-
case 'scan-all':
|
|
128
|
-
summary = formatScanArchitectureSummary(result);
|
|
129
|
-
break;
|
|
130
|
-
default:
|
|
131
|
-
// For other tools, just use a simple summary
|
|
132
|
-
summary = `# ${toolName} Result\n\nTool executed successfully. See structured data below.\n`;
|
|
133
|
-
}
|
|
134
|
-
// Add structured data section
|
|
135
|
-
summary += '\n---\n\n## Structured Data (JSON)\n\n';
|
|
136
|
-
summary += '```json\n';
|
|
137
|
-
summary += JSON.stringify(result, null, 2);
|
|
138
|
-
summary += '\n```\n';
|
|
30
|
+
export function formatStructuredToolResponse(result) {
|
|
31
|
+
const summary = typeof result['summary'] === 'string' ? result['summary'] : '';
|
|
139
32
|
return {
|
|
140
33
|
content: [
|
|
141
|
-
{
|
|
142
|
-
type: 'text',
|
|
143
|
-
text: summary,
|
|
144
|
-
},
|
|
34
|
+
{ type: 'text', text: summary === '' ? JSON.stringify(result) : summary },
|
|
145
35
|
],
|
|
146
|
-
|
|
36
|
+
structuredContent: result,
|
|
37
|
+
isError: reportsFailure(result),
|
|
147
38
|
};
|
|
148
39
|
}
|
|
149
40
|
//# sourceMappingURL=format-tool-response.js.map
|