@dimassetoid/septum-mcp 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +253 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -1,8 +1,13 @@
1
1
  import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
2
- import { readOptionalSourceFile } from "../../resources/source-files.ts";
2
+ import { probeSourcePath, readOptionalSourceFile } from "../../resources/source-files.ts";
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
- import { blankCommentsAndStrings } from "../boundary-tracker.ts";
5
+ import ts from "typescript";
6
+ import type { ExecutionChainNode } from "../../../types/index.ts";
7
+ import { lineOf, TypeScriptBindings, nodes } from "./typescript-bindings.ts";
8
+ import { cliRegistrations, mcpRegistrations, type Registration } from "./mcp-cli-dispatch.ts";
9
+ import { isPathContained } from "../../resolver/path-resolver.ts";
10
+ import { readPackageJson } from "./manifest-helpers.ts";
6
11
  import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
7
12
 
8
13
  export class McpCliSemanticExtractor implements SemanticSliceExtractor {
@@ -18,350 +23,94 @@ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
18
23
  if (hasMcp || hasCli) return true;
19
24
 
20
25
  // Check package.json for bin or MCP SDK
21
- const pkgPath = path.join(projectRoot, "package.json");
22
- if (fs.existsSync(pkgPath)) {
23
- try {
24
- const pkg = JSON.parse(readOptionalSourceFile(pkgPath, "utf-8"));
25
- if (pkg.bin || pkg.dependencies?.["@modelcontextprotocol/sdk"]) {
26
- return true;
27
- }
28
- } catch {}
26
+ const pkg = readPackageJson(projectRoot);
27
+ if (pkg && (pkg.bin || pkg.dependencies?.["@modelcontextprotocol/sdk"])) {
28
+ return true;
29
29
  }
30
30
 
31
31
  return false;
32
32
  }
33
33
 
34
34
  public extractSlices(projectRoot: string, domainId?: number, signal?: AbortSignal, inventory?: SourceInventory): VerticalSliceCandidate[] {
35
- const slices: VerticalSliceCandidate[] = [];
36
- const { toolPrefix, cliBinName } = this.resolveProjectNaming(projectRoot);
37
- const registeredTools = this.scanRegisteredMcpToolNames(projectRoot);
38
-
39
- // 1. Extract MCP Tools
40
- const mcpToolsDir = path.join(projectRoot, "src/mcp/tools");
41
- if (fs.existsSync(mcpToolsDir)) {
42
- try {
43
- const toolFiles = listSourceFiles(mcpToolsDir, /\.[jt]s$/, inventory).filter(file => path.dirname(file) === mcpToolsDir).map(file => path.basename(file));
44
-
45
- for (const file of toolFiles) {
46
- const fullPath = path.join(mcpToolsDir, file);
47
- const relPath = path.relative(projectRoot, fullPath).replace(/\\/g, "/");
48
- const content = readOptionalSourceFile(fullPath, "utf-8");
49
- const baseName = path.basename(file, path.extname(file));
50
- const snakeBase = baseName.replace(/-/g, "_");
51
-
52
- // MCP-07: Only create ingress slices for whitelisted public MCP tools
53
- const toolIdentifier = registeredTools.get(snakeBase) || registeredTools.get(`${toolPrefix}_${snakeBase}`);
54
- if (!toolIdentifier) continue;
55
-
56
- // Detect handler function (both sync and async) and its 1-indexed line number
57
- const handlerMatch = /export\s+(?:async\s+)?function\s+([a-zA-Z0-9_]+)/.exec(content);
58
- const classMatch = /export\s+class\s+([A-Za-z0-9_]+)/.exec(content);
59
- const actionName = handlerMatch ? handlerMatch[1] : `handle_${snakeBase}`;
60
- const controllerClass = classMatch ? classMatch[1] : baseName;
61
- const handlerLine =
62
- handlerMatch && handlerMatch.index !== undefined
63
- ? content.slice(0, handlerMatch.index).split("\n").length
64
- : 1;
65
-
66
- // Detect args interface and its line number
67
- const argsMatch = /(?:export\s+)?interface\s+([a-zA-Z0-9_]+Args)\b/.exec(content);
68
- const formRequestClass = argsMatch ? argsMatch[1] : null;
69
- const argsLine =
70
- argsMatch && argsMatch.index !== undefined
71
- ? content.slice(0, argsMatch.index).split("\n").length
72
- : undefined;
73
-
74
- // Detect service/repository dependency and its actual file path
75
- const serviceDep = this.resolveServiceDependency(projectRoot, fullPath, content);
76
-
77
- const mcpChain: Array<{
78
- stage: string;
79
- symbol: string;
80
- file?: string;
81
- line?: number;
82
- description?: string;
83
- }> = [
84
- {
85
- stage: "ingress",
86
- symbol: `tool:${toolIdentifier}`,
87
- file: relPath,
88
- line: handlerLine,
89
- description: `MCP Tool Endpoint: ${toolIdentifier}`,
90
- },
91
- ];
92
-
93
- if (formRequestClass) {
94
- mcpChain.push({
95
- stage: "validation",
96
- symbol: formRequestClass,
97
- file: relPath,
98
- ...(argsLine ? { line: argsLine } : {}),
99
- description: "MCP Argument Schema",
100
- });
101
- }
102
-
103
- mcpChain.push({
104
- stage: "controller",
105
- symbol: classMatch ? `${controllerClass}::${actionName}` : actionName,
106
- file: relPath,
107
- line: handlerLine,
108
- description: "Tool Handler Execution",
109
- });
110
-
111
- if (serviceDep) {
112
- mcpChain.push({
113
- stage: "service",
114
- symbol: serviceDep.symbol,
115
- ...(serviceDep.file ? { file: serviceDep.file } : {}),
116
- description: "Core Engine Service",
117
- });
118
- }
119
-
120
- slices.push({
121
- domain_id: domainId ?? null,
122
- feature_key: `mcp.${baseName}`,
123
- http_method: "MCP",
124
- route_uri: `tool:${toolIdentifier}`,
125
- route_name: toolIdentifier,
126
- controller_class: controllerClass,
127
- action_name: actionName,
128
- controller_file: relPath,
129
- controller_line: handlerLine,
130
- architecture_style: "rpc",
131
- entry_kind: "mcp_tool",
132
- execution_chain_json: JSON.stringify(mcpChain),
133
- });
134
- }
135
- } catch {}
35
+ const root = path.resolve(projectRoot);
36
+ const files = new Set(listSourceFiles(root, /\.(?:[cm]?[jt]s|[jt]sx)$/, inventory));
37
+ const bindings = new TypeScriptBindings(root, files, signal);
38
+ const registrations: Registration[] = [];
39
+ const relative = (file: string) => path.relative(root, file).replace(/\\/g, "/");
40
+
41
+ for (const file of files) {
42
+ if (!/^src\/mcp\/server\.[cm]?[jt]s$/.test(relative(file))) continue;
43
+ const unit = bindings.load(file);
44
+ if (unit) registrations.push(...mcpRegistrations(unit.source, bindings));
136
45
  }
137
-
138
- // 2. Extract CLI Commands
139
- const cliCommandsDir = path.join(projectRoot, "src/cli/commands");
140
- if (fs.existsSync(cliCommandsDir)) {
141
- try {
142
- const commandFiles = listSourceFiles(cliCommandsDir, /\.[jt]s$/, inventory).filter(file => path.dirname(file) === cliCommandsDir).map(file => path.basename(file));
143
-
144
- for (const file of commandFiles) {
145
- const fullPath = path.join(cliCommandsDir, file);
146
- const relPath = path.relative(projectRoot, fullPath).replace(/\\/g, "/");
147
- const content = readOptionalSourceFile(fullPath, "utf-8");
148
- const commandName = path.basename(file, path.extname(file));
149
-
150
- const handlerMatch = /export\s+(?:async\s+)?function\s+([a-zA-Z0-9_]+)/.exec(content);
151
- const classMatch = /export\s+class\s+([A-Za-z0-9_]+)/.exec(content);
152
- const actionName = handlerMatch
153
- ? handlerMatch[1]
154
- : `handle${commandName.charAt(0).toUpperCase() + commandName.slice(1)}Command`;
155
- const controllerClass = classMatch ? classMatch[1] : commandName;
156
- const handlerLine =
157
- handlerMatch && handlerMatch.index !== undefined
158
- ? content.slice(0, handlerMatch.index).split("\n").length
159
- : 1;
160
-
161
- // Detect options / args
162
- const optionsMatch = /(?:export\s+)?interface\s+([a-zA-Z0-9_]+(?:Options|Args))\b/.exec(content);
163
- const formRequestClass = optionsMatch ? optionsMatch[1] : null;
164
- const optionsLine =
165
- optionsMatch && optionsMatch.index !== undefined
166
- ? content.slice(0, optionsMatch.index).split("\n").length
167
- : undefined;
168
-
169
- const serviceDep = this.resolveServiceDependency(projectRoot, fullPath, content);
170
-
171
- const cliChain: Array<{
172
- stage: string;
173
- symbol: string;
174
- file?: string;
175
- line?: number;
176
- description?: string;
177
- }> = [
178
- {
179
- stage: "ingress",
180
- symbol: `${cliBinName} ${commandName}`,
181
- file: relPath,
182
- line: handlerLine,
183
- description: `CLI Command Entrypoint: ${cliBinName} ${commandName}`,
184
- },
185
- ];
186
-
187
- if (formRequestClass) {
188
- cliChain.push({
189
- stage: "validation",
190
- symbol: formRequestClass,
191
- file: relPath,
192
- ...(optionsLine ? { line: optionsLine } : {}),
193
- description: "CLI Options Interface",
194
- });
195
- }
196
-
197
- cliChain.push({
198
- stage: "controller",
199
- symbol: classMatch ? `${controllerClass}::${actionName}` : actionName,
200
- file: relPath,
201
- line: handlerLine,
202
- description: "Command Execution Handler",
203
- });
204
-
205
- if (serviceDep) {
206
- cliChain.push({
207
- stage: "service",
208
- symbol: serviceDep.symbol,
209
- ...(serviceDep.file ? { file: serviceDep.file } : {}),
210
- description: "Core Engine Service",
211
- });
212
- }
213
-
214
- slices.push({
215
- domain_id: domainId ?? null,
216
- feature_key: `cli.${commandName}`,
217
- http_method: "CLI",
218
- route_uri: `command:${commandName}`,
219
- route_name: `${cliBinName} ${commandName}`,
220
- controller_class: controllerClass,
221
- action_name: actionName,
222
- controller_file: relPath,
223
- controller_line: handlerLine,
224
- architecture_style: "cli",
225
- entry_kind: "cli_command",
226
- execution_chain_json: JSON.stringify(cliChain),
227
- });
46
+ const bins = new Map<string, string>();
47
+ try {
48
+ const manifest = path.join(root, "package.json");
49
+ const text = probeSourcePath(manifest) === "file" ? readOptionalSourceFile(manifest, "utf-8") : "";
50
+ const pkg = text ? JSON.parse(text) : {};
51
+ const name = typeof pkg.name === "string" ? pkg.name.split("/").at(-1)! : "cli";
52
+ const entries = typeof pkg.bin === "string" ? [[name, pkg.bin]] : Object.entries(pkg.bin ?? {});
53
+ for (const [bin, file] of entries) {
54
+ if (typeof bin !== "string" || typeof file !== "string") continue;
55
+ const target = path.resolve(root, file);
56
+ if (/\.[cm]?[jt]sx?$/.test(target) && isPathContained(target, root) &&
57
+ probeSourcePath(target) === "file" && !bins.has(target)) {
58
+ bins.set(target, bin);
59
+ // package.json is explicit entrypoint evidence even under the default bin/ exclusion.
60
+ files.add(target);
228
61
  }
229
- } catch {}
62
+ }
63
+ } catch (error) {
64
+ if (!(error instanceof SyntaxError)) throw error;
230
65
  }
231
-
232
- return slices;
233
- }
234
-
235
- private resolveProjectNaming(projectRoot: string): { toolPrefix: string; cliBinName: string } {
236
- const pkgPath = path.join(projectRoot, "package.json");
237
- if (fs.existsSync(pkgPath)) {
238
- try {
239
- const pkg = JSON.parse(readOptionalSourceFile(pkgPath, "utf-8"));
240
- const rawName = typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : "mcp";
241
- const toolPrefix = rawName.replace(/[^a-zA-Z0-9_]/g, "_").toLowerCase() || "mcp";
242
- let cliBinName = rawName;
243
- if (typeof pkg.bin === "string") {
244
- cliBinName = rawName;
245
- } else if (pkg.bin && typeof pkg.bin === "object") {
246
- const firstBin = Object.keys(pkg.bin)[0];
247
- if (firstBin) cliBinName = firstBin;
248
- }
249
- return { toolPrefix, cliBinName };
250
- } catch {}
66
+ for (const [file, bin] of bins) {
67
+ const unit = bindings.load(file);
68
+ if (unit) registrations.push(...cliRegistrations(unit.source, bin, bindings));
251
69
  }
252
- return { toolPrefix: "mcp", cliBinName: "cli" };
253
- }
254
70
 
255
- private scanRegisteredMcpToolNames(projectRoot: string): Map<string, string> {
256
- const map = new Map<string, string>();
257
- const serverPath = path.join(projectRoot, "src/mcp/server.ts");
258
- if (!fs.existsSync(serverPath)) return map;
259
-
260
- try {
261
- const content = readOptionalSourceFile(serverPath, "utf-8");
262
- const masked = blankCommentsAndStrings(content);
263
- const scan = (start: number, namesInArray: boolean) => {
264
- let depth = 0;
265
- const names: string[] = [];
266
- const property = /\b([A-Za-z_]\w*)\s*:\s*(['"])?/y;
267
- for (let i = start; i < masked.length; i++) {
268
- const ch = masked[i];
269
- if ("[{(".includes(ch)) depth++;
270
- else if ("]})".includes(ch)) {
271
- if (--depth === 0) break;
71
+ return registrations.map(entry => {
72
+ signal?.throwIfAborted();
73
+ const cli = entry.bin !== undefined;
74
+ const uri = (cli ? "command:" : "tool:") + entry.name;
75
+ const name = cli ? entry.bin + " " + entry.name : entry.name;
76
+ const ingress = { file: relative(entry.node.getSourceFile().fileName), line: lineOf(entry.node) };
77
+ const handler = entry.handler;
78
+ const handlerFile = handler ? relative(handler.node.getSourceFile().fileName) : null;
79
+ const chain: ExecutionChainNode[] = [{
80
+ stage: "ingress", symbol: cli ? name : uri, ...ingress,
81
+ description: cli ? "CLI command case" : "MCP tool registration",
82
+ relationship: { kind: "declares", derivation: "source", source: ingress, reason: "Literal public name" },
83
+ }];
84
+ if (handler && handlerFile) {
85
+ const typeNodes = handler.node.parameters.flatMap(param => param.type ? nodes(param.type).filter(ts.isIdentifier) : []);
86
+ for (const ref of typeNodes) {
87
+ const declaration = bindings.declaration(ref);
88
+ if (declaration && ts.isInterfaceDeclaration(declaration) && /(?:Options|Args)$/.test(ref.text)) {
89
+ chain.push({ stage: "validation", symbol: ref.text, file: handlerFile, line: lineOf(declaration),
90
+ description: "Handler parameter interface",
91
+ relationship: { kind: "schema_binding", derivation: "source", reason: "Parameter type reference" } });
272
92
  }
273
- if (depth !== (namesInArray ? 2 : 1) || (i > 0 && /\w/.test(masked[i - 1]))) continue;
274
- property.lastIndex = i;
275
- const match = property.exec(masked);
276
- if (!match) continue;
277
- if (!namesInArray) names.push(match[1]);
278
- else if (match[1] === "name" && match[2]) {
279
- const quoteStart = i + match[0].lastIndexOf(match[2]);
280
- const quoteEnd = masked.indexOf(match[2], quoteStart + 1);
281
- const name = content.slice(quoteStart + 1, quoteEnd);
282
- if (/^[A-Za-z0-9_-]+$/.test(name)) names.push(name);
283
- }
284
- }
285
- // Unbalanced declarations are not evidence of public registration.
286
- if (depth !== 0) return;
287
- for (const fullToolName of names) {
288
- const normalized = fullToolName.replace(/-/g, "_");
289
- map.set(normalized, fullToolName);
290
- const withoutPrefix = normalized.replace(/^[a-z0-9]+_/, "");
291
- if (withoutPrefix) map.set(withoutPrefix, fullToolName);
292
93
  }
293
- };
294
- const listCall = /setRequestHandler\s*\(\s*ListToolsRequestSchema\b/.exec(masked);
295
- if (listCall) {
296
- const callStart = masked.indexOf("(", listCall.index);
297
- let depth = 1;
298
- let end = callStart + 1;
299
- for (; end < masked.length && depth; end++) {
300
- if (masked[end] === "(") depth++;
301
- else if (masked[end] === ")") depth--;
302
- }
303
- const tools = /\btools\s*:\s*\[/.exec(masked.slice(callStart, end));
304
- if (tools && depth === 0) scan(callStart + tools.index + tools[0].length - 1, true);
305
- } else {
306
- const schemas = /\bTOOL_SCHEMAS\s*=\s*\{/.exec(masked);
307
- if (schemas) scan(schemas.index + schemas[0].length - 1, false);
94
+ chain.push({
95
+ stage: "controller", symbol: handler.name, file: handlerFile, line: lineOf(handler.node),
96
+ description: "Statically bound handler",
97
+ relationship: { kind: "route_binding", derivation: "source", source: ingress, reason: "Registration or dispatcher binding" },
98
+ });
308
99
  }
309
- } catch {}
310
- return map;
311
- }
312
-
313
- private resolveServiceDependency(
314
- projectRoot: string,
315
- sourceFile: string,
316
- content: string
317
- ): { symbol: string; file?: string } | null {
318
- const importRegex = /import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g;
319
- let match: RegExpExecArray | null;
320
-
321
- while ((match = importRegex.exec(content)) !== null) {
322
- if (/^import\s+type\b/.test(match[0])) continue;
323
- const clause = match[1];
324
- const spec = match[2];
325
- const identifiers = clause
326
- .split(",")
327
- .filter(s => !/^\s*type\s+/.test(s))
328
- .map((s) => s.trim().split(/\s+as\s+/)[0].trim())
329
- .filter(Boolean);
330
-
331
- for (const id of identifiers) {
332
- if (
333
- /(?:Repository|Service|Manager|Loader|Pipeline|Evaluator|Tracer|Detector|Engine|Store)$/.test(
334
- id
335
- )
336
- ) {
337
- const resolvedFile = this.resolveImportFile(projectRoot, sourceFile, spec);
338
- return {
339
- symbol: id,
340
- ...(resolvedFile ? { file: resolvedFile } : {}),
341
- };
342
- }
343
- }
344
- }
345
-
346
- return null;
347
- }
348
-
349
- private resolveImportFile(projectRoot: string, sourceFile: string, importSpec: string): string | undefined {
350
- if (!importSpec.startsWith(".")) return undefined;
351
- const baseResolved = path.resolve(path.dirname(sourceFile), importSpec);
352
- const candidates = [
353
- baseResolved,
354
- `${baseResolved}.ts`,
355
- `${baseResolved}.js`,
356
- baseResolved.replace(/\.js$/, ".ts"),
357
- path.join(baseResolved, "index.ts"),
358
- ];
359
- for (const c of candidates) {
360
- if (fs.existsSync(c) && fs.statSync(c).isFile()) {
361
- return path.relative(projectRoot, c).replace(/\\/g, "/");
362
- }
363
- }
364
- return undefined;
100
+ return {
101
+ domain_id: domainId ?? null,
102
+ feature_key: (cli ? "cli." : "mcp.") + entry.name,
103
+ http_method: cli ? "CLI" : "MCP",
104
+ route_uri: uri,
105
+ route_name: name,
106
+ controller_class: handlerFile ? path.basename(handlerFile, path.extname(handlerFile)) : "Unresolved",
107
+ action_name: handler?.name ?? "unresolved_handler",
108
+ controller_file: handlerFile,
109
+ controller_line: handler ? lineOf(handler.node) : 0,
110
+ architecture_style: cli ? "cli" : "rpc",
111
+ entry_kind: cli ? "cli_command" : "mcp_tool",
112
+ execution_chain_json: JSON.stringify(chain),
113
+ };
114
+ });
365
115
  }
366
116
  }
367
-