@angular-modernizer/adapter-mcp 2.0.0 → 2.1.1
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 +45 -0
- package/README.md +3 -1
- package/dist/cli.js +6 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/server/build-staleness.d.ts +92 -0
- package/dist/server/build-staleness.js +159 -0
- package/dist/server/limited-stdio-transport.js +28 -1
- package/dist/server/sdk-server.d.ts +6 -0
- package/dist/server/sdk-server.js +21 -2
- package/dist/server/tool-registry.d.ts +2 -1
- package/dist/server/tool-registry.js +8 -2
- package/dist/tools/analyze-project.d.ts +26 -1
- package/dist/tools/analyze-project.js +8 -3
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/helpers/analysis-output.js +3 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +24 -2
- package/dist/tools/helpers/output-contract.js +15 -2
- package/dist/tools/helpers/refresh-apply.js +1 -1
- package/dist/tools/helpers/refresh-inventory.d.ts +1 -1
- package/dist/tools/helpers/refresh-inventory.js +24 -3
- package/dist/tools/helpers/scan-cache.d.ts +45 -2
- package/dist/tools/helpers/scan-cache.js +47 -2
- package/dist/tools/helpers/scan-engine.d.ts +13 -0
- package/dist/tools/helpers/scan-engine.js +10 -0
- package/dist/tools/learn-patterns.js +6 -6
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/refresh-state.js +1 -1
- package/dist/tools/scan-all.d.ts +7 -1
- package/dist/tools/scan-all.js +8 -13
- package/dist/tools/scan-angular.d.ts +7 -1
- package/dist/tools/scan-angular.js +7 -2
- package/dist/tools/scan-architecture.d.ts +8 -0
- package/dist/tools/scan-architecture.js +25 -14
- package/dist/tools/scan-solid.d.ts +7 -1
- package/dist/tools/scan-solid.js +7 -2
- package/dist/tools/server-status.d.ts +6 -24
- package/dist/tools/server-status.js +9 -57
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @angular-modernizer/adapter-mcp
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 938445c: learn-patterns recognises patterns of knowledge bases written before 2.0: old `learned-<type>-<timestamp>` ids are migrated to `learned-<category>-<type>` on load and duplicate entries merged.
|
|
8
|
+
- ede9912: Every tool answer now warns with `configWarnings` code `stale-build` when a package dist/ was rebuilt after the MCP server started.
|
|
9
|
+
- Updated dependencies [028078f]
|
|
10
|
+
- Updated dependencies [938445c]
|
|
11
|
+
- @angular-modernizer/api@2.1.1
|
|
12
|
+
- @angular-modernizer/core@2.1.1
|
|
13
|
+
- @angular-modernizer/orchestration@2.1.1
|
|
14
|
+
- @angular-modernizer/plugin-analyzer@2.1.1
|
|
15
|
+
- @angular-modernizer/plugin-angular@2.1.1
|
|
16
|
+
- @angular-modernizer/plugin-architecture@2.1.1
|
|
17
|
+
- @angular-modernizer/plugin-solid@2.1.1
|
|
18
|
+
- @angular-modernizer/plugin-standalone@2.1.1
|
|
19
|
+
- @angular-modernizer/worker@2.1.1
|
|
20
|
+
- @angular-modernizer/plugin-system@2.1.1
|
|
21
|
+
|
|
22
|
+
## 2.1.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- 5306ac3: scan-all, scan-solid, scan-angular, scan-architecture and analyze-project warn about library imports that do not resolve (missing or incomplete node_modules), also on a warm run served from the scan cache: the warning goes into `warnings` and one summary line, the counts into `unresolvedLibraryImports`. Without library types, type-dependent rules report very different numbers. The unresolved packages are part of the scan cache version, so entries written without a complete node_modules are not served once it is complete, and the other way round. The scan cache layout versions move to scan-5, scan-all-6 and scan-architecture-4, so every cache written before this release is stale once (one cold scan per project); refresh-state lists such entries as `outdated-layout`. compare-health records `libraryTypesResolved` in its snapshot (older snapshots count as resolved) and answers `environment-mismatch` without a delta when the current run and the snapshot differ in it; the snapshot is then replaced only with `updateSnapshot: true`.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- a7a2e6a: Suppression comments count wherever they clearly belong to the reported construct. A marker on any line of the contiguous comment block directly above the reported node counts (before, only a comment ending on the line directly above did, so a marker on the first line of a two-line block was ignored); a blank line still ends the block. A finding on a line inside a decorator, such as the `changeDetection` property of `@Component({...})`, is also suppressed by a marker anywhere inside that decorator (above the property or trailing another property) or in the comment block directly above the decorator list; the class body and the decorators of other declarations do not count. Templates are unchanged. The scan cache versions move to `scan-5`, `scan-all-6` and `scan-architecture-4`, because cached findings were filtered with the old placement and are analyzed again once.
|
|
31
|
+
- Updated dependencies [b1ad47b]
|
|
32
|
+
- Updated dependencies [8e55c18]
|
|
33
|
+
- Updated dependencies [a3d2ad1]
|
|
34
|
+
- Updated dependencies [2709195]
|
|
35
|
+
- Updated dependencies [3f77a02]
|
|
36
|
+
- Updated dependencies [a7a2e6a]
|
|
37
|
+
- @angular-modernizer/plugin-angular@2.1.0
|
|
38
|
+
- @angular-modernizer/plugin-solid@2.1.0
|
|
39
|
+
- @angular-modernizer/api@2.1.0
|
|
40
|
+
- @angular-modernizer/core@2.1.0
|
|
41
|
+
- @angular-modernizer/worker@2.1.0
|
|
42
|
+
- @angular-modernizer/orchestration@2.1.0
|
|
43
|
+
- @angular-modernizer/plugin-analyzer@2.1.0
|
|
44
|
+
- @angular-modernizer/plugin-architecture@2.1.0
|
|
45
|
+
- @angular-modernizer/plugin-standalone@2.1.0
|
|
46
|
+
- @angular-modernizer/plugin-system@2.1.0
|
|
47
|
+
|
|
3
48
|
## 2.0.0
|
|
4
49
|
|
|
5
50
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Arguments are validated against each tool's input schema (JSON Schema 2020-12) b
|
|
|
62
62
|
|
|
63
63
|
Every tool has an output schema and answers with `structuredContent`: the result object, which always carries a `summary` string. The text content holds only that summary (repeating the JSON there made the answers 1.6 times as large; Claude Code shows the model `structuredContent`). `structuredContent` is validated against the output schema; a result that does not match comes back as an error result. Tools that run a command (run-angular-cli, run-build, run-schematic) keep the full output in the result and repeat only its last lines in the summary on failure. orchestrate-migration reports its step counts in `counts` and `workflowId` at the top level.
|
|
64
64
|
|
|
65
|
-
Config warnings: when a call loads a `.angular-modernizer.json` with parts that have no effect, `structuredContent` carries `configWarnings` (`code`: `deprecated-key`, `layers-drift` or `layers-source-failed`; `message`; optional `key`) and the summary gets one line `Config: N warning(s), see configWarnings: <first message>`. The field is part of every output schema and absent when there is nothing to report; it is filled on cache hits and from the scan worker too. A tool that fails after loading the config adds `Config: N warning(s): <first message>` to its error text. Codes and causes: [docs/CONFIGURATION.md](../../docs/CONFIGURATION.md#config-warnings-in-the-tool-answer).
|
|
65
|
+
Config warnings: when a call loads a `.angular-modernizer.json` with parts that have no effect, `structuredContent` carries `configWarnings` (`code`: `deprecated-key`, `layers-drift` or `layers-source-failed`; `message`; optional `key`) and the summary gets one line `Config: N warning(s), see configWarnings: <first message>`. Every answer also carries code `stale-build` once a package `dist/` was rebuilt after the server started (checked at most every 5 s): the session still runs the old code, reconnect the MCP server. Answers that never reach the tool get the same warning as one `Config:` line: rejected arguments, an output replaced by the output validation, and the `-32602` error of an unknown tool. The field is part of every output schema and absent when there is nothing to report; it is filled on cache hits and from the scan worker too. A tool that fails after loading the config adds `Config: N warning(s): <first message>` to its error text. Codes and causes: [docs/CONFIGURATION.md](../../docs/CONFIGURATION.md#config-warnings-in-the-tool-answer).
|
|
66
66
|
|
|
67
67
|
Set `ANGULAR_MODERNIZER_DEBUG=1` in the server environment for diagnostics: a debug log `./mcp-server.log` in the working directory and a health check on `http://localhost:9999/health` and `/status`. Both are off by default.
|
|
68
68
|
|
|
@@ -237,6 +237,8 @@ orchestration: {
|
|
|
237
237
|
|
|
238
238
|
The `learn-patterns` tool persists discovered patterns across scans in `.angular-modernizer-cache/pattern-knowledge.json`. This enables pattern evolution tracking, confidence improvement over time, style shift detection, and pattern velocity measurement.
|
|
239
239
|
|
|
240
|
+
Patterns are keyed by `learned-<category>-<type>` (core `learnedPatternId`). Files written before 2.0 used `learned-<type>-<timestamp>`; loading migrates those ids and merges entries that land on the same id (history in time order, scan and occurrence counts summed), and the next run saves them with schema version `1.1.0`. Patterns a run does not find stay in the file as `declining`.
|
|
241
|
+
|
|
240
242
|
Example evolution output:
|
|
241
243
|
|
|
242
244
|
```json
|
package/dist/cli.js
CHANGED
|
@@ -55,6 +55,7 @@ import { FindAngularSymbolTool } from './tools/find-angular-symbol.js';
|
|
|
55
55
|
import { SearchCodebaseTool } from './tools/search-codebase.js';
|
|
56
56
|
import { VerifyCitationsTool } from './tools/verify-citations.js';
|
|
57
57
|
import { ServerStatusTool } from './tools/server-status.js';
|
|
58
|
+
import { BuildStaleness, configureBuildStaleness } from './server/build-staleness.js';
|
|
58
59
|
/**
|
|
59
60
|
* Write debug message to MCP log file (mcp-server.log), the file the MCP
|
|
60
61
|
* Watcher uses. Only with ANGULAR_MODERNIZER_DEBUG set: the file lands in the
|
|
@@ -131,6 +132,10 @@ function main() {
|
|
|
131
132
|
console.error(`Scan worker: --max-heap-mb ${heapMb} is below the minimum of ${MIN_WORKER_HEAP_MB} MB; scans will fail`);
|
|
132
133
|
}
|
|
133
134
|
debugLog(`CLI Scan worker: ${scanWorker.enabled ? 'on' : 'off'}`);
|
|
135
|
+
// One baseline of the dist mtimes for server-status and the stale-build
|
|
136
|
+
// warning every answer carries after a rebuild
|
|
137
|
+
const buildStaleness = new BuildStaleness(distDirectories());
|
|
138
|
+
configureBuildStaleness(buildStaleness);
|
|
134
139
|
server.registerTool(new AnalyzeProjectTool());
|
|
135
140
|
server.registerTool(new ScanArchitectureTool());
|
|
136
141
|
server.registerTool(new ScanSolidTool());
|
|
@@ -173,7 +178,7 @@ function main() {
|
|
|
173
178
|
server.registerTool(new FindAngularSymbolTool(projects));
|
|
174
179
|
server.registerTool(new SearchCodebaseTool(projects));
|
|
175
180
|
server.registerTool(new VerifyCitationsTool());
|
|
176
|
-
server.registerTool(new ServerStatusTool(projects, () => server.getRuntimeStats(),
|
|
181
|
+
server.registerTool(new ServerStatusTool(projects, () => server.getRuntimeStats(), buildStaleness));
|
|
177
182
|
debugLog(`CLI ${server.getToolsMap().size} tools registered successfully`);
|
|
178
183
|
// Register orchestration tool with access to all other tools
|
|
179
184
|
const orchestrateTool = new OrchestrateMigrationTool();
|
package/dist/index.d.ts
CHANGED
|
@@ -105,6 +105,8 @@ export type { ServerRuntimeStats } from './server/mcp-server.js';
|
|
|
105
105
|
export type { ProjectCache } from './tools/helpers/project-cache.js';
|
|
106
106
|
export type { HealthScan, CompareHealthOutput } from './tools/compare-health.js';
|
|
107
107
|
export type { DistDirectory, ServerStatusOutput } from './tools/server-status.js';
|
|
108
|
+
export { BuildStaleness } from './server/build-staleness.js';
|
|
109
|
+
export type { BuildStalenessOptions } from './server/build-staleness.js';
|
|
108
110
|
export type { AnalyzeBuildImpactOutput } from './tools/analyze-build-impact.js';
|
|
109
111
|
export type { AnalyzeCoreToSharedResult } from './tools/analyze-core-to-shared.js';
|
|
110
112
|
export type { AnalyzeParserPerformanceOutput } from './tools/analyze-parser-performance.js';
|
|
@@ -169,6 +171,7 @@ export type { IncrementalMetadata as ValidateTransformationIncrementalMetadata }
|
|
|
169
171
|
export type { VerifiedCitation } from './tools/verify-citations.js';
|
|
170
172
|
export type { ScanCounts } from './tools/helpers/analysis-output.js';
|
|
171
173
|
export type { FileDelta, HealthViolation, RuleDelta, } from './tools/helpers/health-delta.js';
|
|
174
|
+
export type { UnresolvedLibraryImports } from './tools/helpers/library-import-warning.js';
|
|
172
175
|
export type { AcquireControl, CachedProjectInfo, EvictionReason, EvictionStats, ProjectCacheLimits, ProjectEviction, } from './tools/helpers/project-cache.js';
|
|
173
176
|
export type { RuleTiming } from './tools/helpers/rule-runner.js';
|
|
174
177
|
export type { Performance, Suggestion } from './tools/helpers/suggestion-generator.js';
|
package/dist/index.js
CHANGED
|
@@ -101,4 +101,5 @@ export { VerifyCitationsTool } from './tools/verify-citations.js';
|
|
|
101
101
|
export { ProgressStore, } from './streaming/progress-store.js';
|
|
102
102
|
// Re-export existing project analyzer for compatibility
|
|
103
103
|
export { analyzeProject } from './core/project-analyzer.js';
|
|
104
|
+
export { BuildStaleness } from './server/build-staleness.js';
|
|
104
105
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects package `dist/` directories rebuilt after the server started.
|
|
3
|
+
*
|
|
4
|
+
* A session keeps the code it started with; after a rebuild it serves stale
|
|
5
|
+
* tools until the client reconnects. server-status reports the state per
|
|
6
|
+
* package, and every tool answer carries a `stale-build` config warning once a
|
|
7
|
+
* package was rebuilt (`ToolRegistry.executeTool` calls {@link reportStaleBuild}).
|
|
8
|
+
*/
|
|
9
|
+
import { type ConfigWarning } from '@angular-modernizer/core';
|
|
10
|
+
/** A package `dist/` directory to watch for rebuilds. */
|
|
11
|
+
export interface DistDirectory {
|
|
12
|
+
/** Package folder name, e.g. `core`. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Absolute path of the package's `dist/` directory. */
|
|
15
|
+
dir: string;
|
|
16
|
+
}
|
|
17
|
+
/** Build state of one package. */
|
|
18
|
+
export interface DistPackageState {
|
|
19
|
+
/** Package folder name. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Absolute path of the package's `dist/` directory. */
|
|
22
|
+
dir: string;
|
|
23
|
+
/** Newest `.js` mtime when the server started. */
|
|
24
|
+
builtAtStart?: string;
|
|
25
|
+
/** Newest `.js` mtime now. */
|
|
26
|
+
builtNow?: string;
|
|
27
|
+
/** The newest `.js` mtime changed since the server started. */
|
|
28
|
+
rebuilt: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Options of {@link BuildStaleness}; tests inject clock and mtime lookup. */
|
|
31
|
+
export interface BuildStalenessOptions {
|
|
32
|
+
/** Current time in ms; default `Date.now`. */
|
|
33
|
+
now?: () => number;
|
|
34
|
+
/** Newest `.js` mtime under a directory in ms; default walks the directory. */
|
|
35
|
+
newestMtime?: (dir: string) => number | undefined;
|
|
36
|
+
/** Minimum time between two checks of {@link BuildStaleness.staleWarning}; default 5000 ms. */
|
|
37
|
+
minIntervalMs?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Newest `.js` mtime under `dir` in ms, or undefined when there is none. */
|
|
40
|
+
export declare function newestJsMtime(dir: string): number | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Newest `.js` mtime per package `dist/` at start versus now. The baseline is
|
|
43
|
+
* taken in the constructor; missing directories are skipped.
|
|
44
|
+
*/
|
|
45
|
+
export declare class BuildStaleness {
|
|
46
|
+
private readonly distDirectories;
|
|
47
|
+
private readonly baseline;
|
|
48
|
+
private readonly now;
|
|
49
|
+
private readonly newestMtime;
|
|
50
|
+
private readonly minIntervalMs;
|
|
51
|
+
private readonly startedAt;
|
|
52
|
+
private lastCheckAt;
|
|
53
|
+
private stale;
|
|
54
|
+
/**
|
|
55
|
+
* @param distDirectories - Package `dist/` directories to watch; missing ones are skipped.
|
|
56
|
+
* @param options - Clock, mtime lookup and throttle interval.
|
|
57
|
+
*/
|
|
58
|
+
constructor(distDirectories?: readonly DistDirectory[], options?: BuildStalenessOptions);
|
|
59
|
+
/** State of every watched package that existed at start, read now (no throttle). */
|
|
60
|
+
packages(): DistPackageState[];
|
|
61
|
+
/**
|
|
62
|
+
* The `stale-build` warning when a package was rebuilt since start, else
|
|
63
|
+
* undefined. Walks the directories at most once per `minIntervalMs`; between
|
|
64
|
+
* checks it returns the last result, and once stale it stays stale without
|
|
65
|
+
* walking again.
|
|
66
|
+
*/
|
|
67
|
+
staleWarning(): ConfigWarning | undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sets the tracker {@link reportStaleBuild} reads; `cli.ts` calls it once
|
|
71
|
+
* with the watched packages. Without a call (tests, library use) nothing is
|
|
72
|
+
* reported.
|
|
73
|
+
*/
|
|
74
|
+
export declare function configureBuildStaleness(tracker: BuildStaleness | undefined): void;
|
|
75
|
+
/**
|
|
76
|
+
* Reports the `stale-build` warning into the current config warning scope
|
|
77
|
+
* when the configured tracker finds a rebuilt package.
|
|
78
|
+
*/
|
|
79
|
+
export declare function reportStaleBuild(): void;
|
|
80
|
+
/**
|
|
81
|
+
* The `stale-build` warning of the configured tracker (same throttle), or
|
|
82
|
+
* undefined without a tracker or a rebuild.
|
|
83
|
+
*/
|
|
84
|
+
export declare function staleBuildWarning(): ConfigWarning | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* `text` plus one `Config: 1 warning(s): <message>` line when the build is
|
|
87
|
+
* stale. For answers that never reach `ToolRegistry.executeTool`: rejected
|
|
88
|
+
* arguments, a replaced output, an unknown tool. A stale server rejects
|
|
89
|
+
* exactly what only the new build knows, so these answers need the hint most.
|
|
90
|
+
*/
|
|
91
|
+
export declare function withStaleBuildLine(text: string): string;
|
|
92
|
+
//# sourceMappingURL=build-staleness.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects package `dist/` directories rebuilt after the server started.
|
|
3
|
+
*
|
|
4
|
+
* A session keeps the code it started with; after a rebuild it serves stale
|
|
5
|
+
* tools until the client reconnects. server-status reports the state per
|
|
6
|
+
* package, and every tool answer carries a `stale-build` config warning once a
|
|
7
|
+
* package was rebuilt (`ToolRegistry.executeTool` calls {@link reportStaleBuild}).
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { reportConfigWarning } from '@angular-modernizer/core';
|
|
12
|
+
import { configWarningsLine } from '../tools/helpers/output-contract.js';
|
|
13
|
+
/** Default minimum time between two throttled checks. */
|
|
14
|
+
const DEFAULT_MIN_INTERVAL_MS = 5000;
|
|
15
|
+
/** Newest `.js` mtime under `dir` in ms, or undefined when there is none. */
|
|
16
|
+
export function newestJsMtime(dir) {
|
|
17
|
+
let newest;
|
|
18
|
+
const stack = [dir];
|
|
19
|
+
while (stack.length > 0) {
|
|
20
|
+
const current = stack.pop();
|
|
21
|
+
if (current === undefined) {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
let entries;
|
|
25
|
+
try {
|
|
26
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const full = join(current, entry.name);
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
stack.push(full);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (entry.name.endsWith('.js')) {
|
|
38
|
+
const mtime = statSync(full).mtimeMs;
|
|
39
|
+
newest = newest === undefined ? mtime : Math.max(newest, mtime);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return newest;
|
|
44
|
+
}
|
|
45
|
+
function iso(ms) {
|
|
46
|
+
return ms === undefined ? undefined : new Date(ms).toISOString();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Newest `.js` mtime per package `dist/` at start versus now. The baseline is
|
|
50
|
+
* taken in the constructor; missing directories are skipped.
|
|
51
|
+
*/
|
|
52
|
+
export class BuildStaleness {
|
|
53
|
+
distDirectories;
|
|
54
|
+
baseline;
|
|
55
|
+
now;
|
|
56
|
+
newestMtime;
|
|
57
|
+
minIntervalMs;
|
|
58
|
+
startedAt;
|
|
59
|
+
lastCheckAt;
|
|
60
|
+
stale;
|
|
61
|
+
/**
|
|
62
|
+
* @param distDirectories - Package `dist/` directories to watch; missing ones are skipped.
|
|
63
|
+
* @param options - Clock, mtime lookup and throttle interval.
|
|
64
|
+
*/
|
|
65
|
+
constructor(distDirectories = [], options = {}) {
|
|
66
|
+
this.distDirectories = distDirectories;
|
|
67
|
+
this.now = options.now ?? Date.now;
|
|
68
|
+
this.newestMtime = options.newestMtime ?? newestJsMtime;
|
|
69
|
+
this.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
|
|
70
|
+
this.baseline = new Map(distDirectories
|
|
71
|
+
.filter((d) => existsSync(d.dir))
|
|
72
|
+
.map((d) => [d.dir, this.newestMtime(d.dir)]));
|
|
73
|
+
this.startedAt = this.now();
|
|
74
|
+
this.lastCheckAt = this.startedAt;
|
|
75
|
+
}
|
|
76
|
+
/** State of every watched package that existed at start, read now (no throttle). */
|
|
77
|
+
packages() {
|
|
78
|
+
return this.distDirectories
|
|
79
|
+
.filter((d) => this.baseline.has(d.dir))
|
|
80
|
+
.map((d) => {
|
|
81
|
+
const atStart = this.baseline.get(d.dir);
|
|
82
|
+
const now = this.newestMtime(d.dir);
|
|
83
|
+
const builtAtStart = iso(atStart);
|
|
84
|
+
const builtNow = iso(now);
|
|
85
|
+
return {
|
|
86
|
+
name: d.name,
|
|
87
|
+
dir: d.dir,
|
|
88
|
+
...(builtAtStart === undefined ? {} : { builtAtStart }),
|
|
89
|
+
...(builtNow === undefined ? {} : { builtNow }),
|
|
90
|
+
rebuilt: now !== undefined && (atStart === undefined || now > atStart),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The `stale-build` warning when a package was rebuilt since start, else
|
|
96
|
+
* undefined. Walks the directories at most once per `minIntervalMs`; between
|
|
97
|
+
* checks it returns the last result, and once stale it stays stale without
|
|
98
|
+
* walking again.
|
|
99
|
+
*/
|
|
100
|
+
staleWarning() {
|
|
101
|
+
if (this.stale !== undefined) {
|
|
102
|
+
return this.stale;
|
|
103
|
+
}
|
|
104
|
+
const now = this.now();
|
|
105
|
+
if (now - this.lastCheckAt < this.minIntervalMs) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
this.lastCheckAt = now;
|
|
109
|
+
const rebuilt = this.packages().filter((p) => p.rebuilt);
|
|
110
|
+
if (rebuilt.length === 0) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const newest = rebuilt.reduce((latest, p) => (p.builtNow !== undefined && p.builtNow > latest ? p.builtNow : latest), '');
|
|
114
|
+
this.stale = {
|
|
115
|
+
code: 'stale-build',
|
|
116
|
+
message: `Server runs code from ${new Date(this.startedAt).toISOString()}, dist of ` +
|
|
117
|
+
`${rebuilt.map((p) => p.name).join(', ')} rebuilt at ${newest}: ` +
|
|
118
|
+
'reconnect the MCP server to load the new build.',
|
|
119
|
+
};
|
|
120
|
+
return this.stale;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let active;
|
|
124
|
+
/**
|
|
125
|
+
* Sets the tracker {@link reportStaleBuild} reads; `cli.ts` calls it once
|
|
126
|
+
* with the watched packages. Without a call (tests, library use) nothing is
|
|
127
|
+
* reported.
|
|
128
|
+
*/
|
|
129
|
+
export function configureBuildStaleness(tracker) {
|
|
130
|
+
active = tracker;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reports the `stale-build` warning into the current config warning scope
|
|
134
|
+
* when the configured tracker finds a rebuilt package.
|
|
135
|
+
*/
|
|
136
|
+
export function reportStaleBuild() {
|
|
137
|
+
const warning = staleBuildWarning();
|
|
138
|
+
if (warning !== undefined) {
|
|
139
|
+
reportConfigWarning(warning);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The `stale-build` warning of the configured tracker (same throttle), or
|
|
144
|
+
* undefined without a tracker or a rebuild.
|
|
145
|
+
*/
|
|
146
|
+
export function staleBuildWarning() {
|
|
147
|
+
return active?.staleWarning();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* `text` plus one `Config: 1 warning(s): <message>` line when the build is
|
|
151
|
+
* stale. For answers that never reach `ToolRegistry.executeTool`: rejected
|
|
152
|
+
* arguments, a replaced output, an unknown tool. A stale server rejects
|
|
153
|
+
* exactly what only the new build knows, so these answers need the hint most.
|
|
154
|
+
*/
|
|
155
|
+
export function withStaleBuildLine(text) {
|
|
156
|
+
const warning = staleBuildWarning();
|
|
157
|
+
return warning === undefined ? text : `${text}\n${configWarningsLine([warning], false)}`;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=build-staleness.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* `isError` result, and the sizes are kept for `server-status`.
|
|
7
7
|
*/
|
|
8
8
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
9
|
+
import { withStaleBuildLine } from './build-staleness.js';
|
|
9
10
|
/**
|
|
10
11
|
* Largest serialized response written to stdout, in bytes.
|
|
11
12
|
*
|
|
@@ -19,6 +20,32 @@ export const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
|
19
20
|
function isResponse(message) {
|
|
20
21
|
return 'id' in message && ('result' in message || 'error' in message);
|
|
21
22
|
}
|
|
23
|
+
/** The SDK's `-32602` error for a tools/call naming a tool it does not have. */
|
|
24
|
+
const UNKNOWN_TOOL_ERROR = /^Tool .+ (?:not found|disabled)$/;
|
|
25
|
+
/**
|
|
26
|
+
* Adds the stale-build line to the error of a call to an unknown tool. The SDK
|
|
27
|
+
* answers it before any handler of ours runs, and a stale server is exactly
|
|
28
|
+
* the one that lacks a tool of the new build.
|
|
29
|
+
*/
|
|
30
|
+
function withStaleBuildHintOnUnknownTool(message) {
|
|
31
|
+
const error = message.error;
|
|
32
|
+
if (typeof error !== 'object' || error === null) {
|
|
33
|
+
return message;
|
|
34
|
+
}
|
|
35
|
+
const { code, message: text, data } = error;
|
|
36
|
+
if (code !== -32602 || typeof text !== 'string' || !UNKNOWN_TOOL_ERROR.test(text)) {
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
const hinted = withStaleBuildLine(text);
|
|
40
|
+
if (hinted === text) {
|
|
41
|
+
return message;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
jsonrpc: '2.0',
|
|
45
|
+
id: message.id,
|
|
46
|
+
error: { code, message: hinted, ...(data === undefined ? {} : { data }) },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
22
49
|
/**
|
|
23
50
|
* How to get a smaller answer: the narrowing options the tool has (a lower
|
|
24
51
|
* value or `summaryOnly: true`), never options of other tools.
|
|
@@ -65,7 +92,7 @@ export class LimitedStdioTransport extends StdioServerTransport {
|
|
|
65
92
|
}
|
|
66
93
|
const call = this.toolCalls.get(message.id);
|
|
67
94
|
this.toolCalls.delete(message.id);
|
|
68
|
-
return super.send(this.withinLimit(message, call?.tool, call?.narrowing ?? []));
|
|
95
|
+
return super.send(this.withinLimit(withStaleBuildHintOnUnknownTool(message), call?.tool, call?.narrowing ?? []));
|
|
69
96
|
}
|
|
70
97
|
/**
|
|
71
98
|
* Returns `message` when it serializes within the limit, otherwise a small
|
|
@@ -57,6 +57,12 @@ export declare const INPUT_VALIDATOR: jsonSchemaValidator;
|
|
|
57
57
|
* field never fails; a missing required field or a wrong type does.
|
|
58
58
|
*/
|
|
59
59
|
export declare const OUTPUT_VALIDATOR: jsonSchemaValidator;
|
|
60
|
+
/**
|
|
61
|
+
* `validator` whose error message gets the stale-build line. The SDK answers
|
|
62
|
+
* rejected arguments and a non-matching output before or after
|
|
63
|
+
* `ToolRegistry.executeTool`, so those answers would not carry the warning.
|
|
64
|
+
*/
|
|
65
|
+
export declare function withStaleBuildHint(validator: jsonSchemaValidator): jsonSchemaValidator;
|
|
60
66
|
/**
|
|
61
67
|
* Factory for `serveStdio`: registers every tool of `registry` on a fresh
|
|
62
68
|
* `McpServer` for the era the SDK asks for.
|
|
@@ -23,6 +23,7 @@ import { PACKAGE_VERSION } from './package-version.js';
|
|
|
23
23
|
import { throttleProgress } from '../tools/helpers/tool-context.js';
|
|
24
24
|
import { configWarningsLine, withConfigWarningsSchema } from '../tools/helpers/output-contract.js';
|
|
25
25
|
import { configWarningsOf } from '@angular-modernizer/core';
|
|
26
|
+
import { withStaleBuildLine } from './build-staleness.js';
|
|
26
27
|
/**
|
|
27
28
|
* Input options that make a tool answer smaller, in the order the size limit
|
|
28
29
|
* message names them.
|
|
@@ -59,6 +60,24 @@ export const INPUT_VALIDATOR = new AjvJsonSchemaValidator();
|
|
|
59
60
|
* field never fails; a missing required field or a wrong type does.
|
|
60
61
|
*/
|
|
61
62
|
export const OUTPUT_VALIDATOR = new AjvJsonSchemaValidator();
|
|
63
|
+
/**
|
|
64
|
+
* `validator` whose error message gets the stale-build line. The SDK answers
|
|
65
|
+
* rejected arguments and a non-matching output before or after
|
|
66
|
+
* `ToolRegistry.executeTool`, so those answers would not carry the warning.
|
|
67
|
+
*/
|
|
68
|
+
export function withStaleBuildHint(validator) {
|
|
69
|
+
return {
|
|
70
|
+
getValidator(schema) {
|
|
71
|
+
const validate = validator.getValidator(schema);
|
|
72
|
+
return (input) => {
|
|
73
|
+
const result = validate(input);
|
|
74
|
+
return result.valid ? result : { ...result, errorMessage: withStaleBuildLine(result.errorMessage) };
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const INPUT_VALIDATOR_WITH_HINT = withStaleBuildHint(INPUT_VALIDATOR);
|
|
80
|
+
const OUTPUT_VALIDATOR_WITH_HINT = withStaleBuildHint(OUTPUT_VALIDATOR);
|
|
62
81
|
/**
|
|
63
82
|
* Factory for `serveStdio`: registers every tool of `registry` on a fresh
|
|
64
83
|
* `McpServer` for the era the SDK asks for.
|
|
@@ -81,11 +100,11 @@ export function createServerFactory(registry, hooks = {}) {
|
|
|
81
100
|
mcp.registerTool(tool.name, {
|
|
82
101
|
...(tool.title === undefined ? {} : { title: tool.title }),
|
|
83
102
|
description: tool.description,
|
|
84
|
-
inputSchema: fromJsonSchema(tool.inputSchema,
|
|
103
|
+
inputSchema: fromJsonSchema(tool.inputSchema, INPUT_VALIDATOR_WITH_HINT),
|
|
85
104
|
...(tool.outputSchema === undefined
|
|
86
105
|
? {}
|
|
87
106
|
: {
|
|
88
|
-
outputSchema: fromJsonSchema(withConfigWarningsSchema(tool.outputSchema),
|
|
107
|
+
outputSchema: fromJsonSchema(withConfigWarningsSchema(tool.outputSchema), OUTPUT_VALIDATOR_WITH_HINT),
|
|
89
108
|
}),
|
|
90
109
|
...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),
|
|
91
110
|
}, async (args, ctx) => {
|
|
@@ -40,7 +40,8 @@ export declare class ToolRegistry {
|
|
|
40
40
|
/**
|
|
41
41
|
* Execute a tool by name with given arguments. Config warnings the tool
|
|
42
42
|
* reports while it runs (core `reportConfigWarning`) come back as
|
|
43
|
-
* `configWarnings` plus one summary line
|
|
43
|
+
* `configWarnings` plus one summary line, and so does a `stale-build`
|
|
44
|
+
* warning when a package `dist/` was rebuilt after the server started.
|
|
44
45
|
* @param name - Tool name
|
|
45
46
|
* @param args - Tool arguments
|
|
46
47
|
* @param ctx - Cancellation and progress of the request
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { collectConfigWarnings } from '@angular-modernizer/core';
|
|
2
2
|
import { withConfigWarnings } from '../tools/helpers/output-contract.js';
|
|
3
|
+
import { reportStaleBuild } from './build-staleness.js';
|
|
3
4
|
import { formatStructuredToolResponse } from '../utils/format-tool-response.js';
|
|
4
5
|
/**
|
|
5
6
|
* Central registry for MCP tools: registration, discovery and execution.
|
|
@@ -57,7 +58,8 @@ export class ToolRegistry {
|
|
|
57
58
|
/**
|
|
58
59
|
* Execute a tool by name with given arguments. Config warnings the tool
|
|
59
60
|
* reports while it runs (core `reportConfigWarning`) come back as
|
|
60
|
-
* `configWarnings` plus one summary line
|
|
61
|
+
* `configWarnings` plus one summary line, and so does a `stale-build`
|
|
62
|
+
* warning when a package `dist/` was rebuilt after the server started.
|
|
61
63
|
* @param name - Tool name
|
|
62
64
|
* @param args - Tool arguments
|
|
63
65
|
* @param ctx - Cancellation and progress of the request
|
|
@@ -70,7 +72,11 @@ export class ToolRegistry {
|
|
|
70
72
|
throw new Error(`Unknown tool: ${name}`);
|
|
71
73
|
}
|
|
72
74
|
// Config warnings the call reported (any depth, after awaits) go into the answer
|
|
73
|
-
|
|
75
|
+
// A rebuilt dist warns in every answer, also when the tool throws
|
|
76
|
+
const { result, warnings } = await collectConfigWarnings(() => {
|
|
77
|
+
reportStaleBuild();
|
|
78
|
+
return tool.execute(args, ctx);
|
|
79
|
+
});
|
|
74
80
|
return formatStructuredToolResponse(withConfigWarnings(result, warnings));
|
|
75
81
|
}
|
|
76
82
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
2
2
|
import { type CancelledExecution } from './helpers/tool-context.js';
|
|
3
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
3
4
|
/**
|
|
4
5
|
* Result from the analyze-project tool.
|
|
5
6
|
*/
|
|
@@ -204,8 +205,13 @@ export interface AnalyzeProjectResult {
|
|
|
204
205
|
};
|
|
205
206
|
/** Set when the client cancelled the analysis; counts cover the analyzed files. */
|
|
206
207
|
execution?: CancelledExecution;
|
|
207
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* Program files that could not be read and were left out of the analysis,
|
|
210
|
+
* and library imports that do not resolve.
|
|
211
|
+
*/
|
|
208
212
|
warnings?: string[];
|
|
213
|
+
/** Library imports of the analyzed files that do not resolve (sequential path); absent when all resolve. */
|
|
214
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
209
215
|
}
|
|
210
216
|
/**
|
|
211
217
|
* MCP tool `analyze-project`: detects the framework (Angular CLI, Nx),
|
|
@@ -342,6 +348,25 @@ export declare class AnalyzeProjectTool implements MCPTool {
|
|
|
342
348
|
summary: {
|
|
343
349
|
type: string;
|
|
344
350
|
};
|
|
351
|
+
unresolvedLibraryImports: {
|
|
352
|
+
readonly type: "object";
|
|
353
|
+
readonly description: "Library imports of the scanned files that do not resolve (node_modules missing or incomplete); rules that need library types can report less. Absent when all resolve.";
|
|
354
|
+
readonly properties: {
|
|
355
|
+
readonly imports: {
|
|
356
|
+
readonly type: "integer";
|
|
357
|
+
};
|
|
358
|
+
readonly packages: {
|
|
359
|
+
readonly type: "integer";
|
|
360
|
+
};
|
|
361
|
+
readonly examples: {
|
|
362
|
+
readonly type: "array";
|
|
363
|
+
readonly items: {
|
|
364
|
+
readonly type: "string";
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
readonly required: readonly ["imports", "packages", "examples"];
|
|
369
|
+
};
|
|
345
370
|
warnings: {
|
|
346
371
|
readonly type: "array";
|
|
347
372
|
readonly items: {
|
|
@@ -11,7 +11,8 @@ import { PAGINATION_SCHEMA, SCAN_EXECUTION_SCHEMA, nameList, pageNote, } from '.
|
|
|
11
11
|
import { cancelledExecution, fileProgressMessage, finalFileProgress, forwardKernelProgress, } from './helpers/tool-context.js';
|
|
12
12
|
import { runScan } from '../scan-host/scan-host.js';
|
|
13
13
|
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
14
|
-
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
14
|
+
import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
15
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
15
16
|
/** Application or library entry of `framework.projects`. */
|
|
16
17
|
const NAMED_PROJECT_SCHEMA = {
|
|
17
18
|
type: 'object',
|
|
@@ -352,6 +353,7 @@ export class AnalyzeProjectTool {
|
|
|
352
353
|
execution: SCAN_EXECUTION_SCHEMA,
|
|
353
354
|
progress: { type: 'object' },
|
|
354
355
|
...WARNINGS_OUTPUT_SCHEMA,
|
|
356
|
+
...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
|
|
355
357
|
summary: { type: 'string' },
|
|
356
358
|
},
|
|
357
359
|
required: [
|
|
@@ -414,6 +416,7 @@ export class AnalyzeProjectTool {
|
|
|
414
416
|
let filesAnalyzed = 0;
|
|
415
417
|
let execution;
|
|
416
418
|
const warnings = [];
|
|
419
|
+
let unresolvedLibraryImports;
|
|
417
420
|
let fileCap;
|
|
418
421
|
const maxFiles = parseMaxFiles(mergedParams.maxFiles);
|
|
419
422
|
let lastProgress;
|
|
@@ -539,6 +542,7 @@ export class AnalyzeProjectTool {
|
|
|
539
542
|
rootPath: mergedParams.rootPath,
|
|
540
543
|
files: sequentialFiles,
|
|
541
544
|
mode: 'sequential',
|
|
545
|
+
libraryImports: true,
|
|
542
546
|
}, {
|
|
543
547
|
file: (event) => {
|
|
544
548
|
for (const finding of event.findings) {
|
|
@@ -562,6 +566,7 @@ export class AnalyzeProjectTool {
|
|
|
562
566
|
if (unreadableWarning !== undefined) {
|
|
563
567
|
warnings.push(unreadableWarning);
|
|
564
568
|
}
|
|
569
|
+
unresolvedLibraryImports = engine.unresolvedLibraryImports;
|
|
565
570
|
if (engine.cancelled) {
|
|
566
571
|
execution = cancelledExecution(done, sequentialFiles.length - done);
|
|
567
572
|
}
|
|
@@ -648,10 +653,10 @@ export class AnalyzeProjectTool {
|
|
|
648
653
|
progress: lastProgress,
|
|
649
654
|
...(execution === undefined ? {} : { execution }),
|
|
650
655
|
};
|
|
651
|
-
const result = withWarnings({
|
|
656
|
+
const result = withLibraryImportWarning(withWarnings({
|
|
652
657
|
...analysis,
|
|
653
658
|
summary: describeAnalysis({ ...analysis, fileCap }, totalResults),
|
|
654
|
-
}, warnings);
|
|
659
|
+
}, warnings), unresolvedLibraryImports);
|
|
655
660
|
// Mark operation as completed successfully
|
|
656
661
|
if (opId) {
|
|
657
662
|
const message = paginationMetadata
|