@dimassetoid/septum-mcp 0.0.0-stage → 0.2.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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -2
  3. package/bin/septum.ts +4 -0
  4. package/package.json +70 -4
  5. package/scripts/postinstall.ts +25 -0
  6. package/src/cli/commands/check.ts +122 -0
  7. package/src/cli/commands/hook.ts +268 -0
  8. package/src/cli/commands/init.ts +553 -0
  9. package/src/cli/commands/serve.ts +5 -0
  10. package/src/cli/commands/sync.ts +41 -0
  11. package/src/cli/commands/topology.ts +161 -0
  12. package/src/cli/index.ts +167 -0
  13. package/src/cli/scaffold/harness-config.ts +621 -0
  14. package/src/cli/templates/hooks.ts +75 -0
  15. package/src/cli/templates/rules.ts +50 -0
  16. package/src/cli/templates/skill.ts +51 -0
  17. package/src/cli/ui/prompts.ts +122 -0
  18. package/src/core/boundary/evaluator.ts +442 -0
  19. package/src/core/boundary/staged-auditor.ts +58 -0
  20. package/src/core/config/loader.ts +122 -0
  21. package/src/core/config/schema.ts +69 -0
  22. package/src/core/database/client.ts +60 -0
  23. package/src/core/database/repositories/dependency.repository.ts +712 -0
  24. package/src/core/database/repositories/domain.repository.ts +330 -0
  25. package/src/core/database/repositories/environment.repository.ts +207 -0
  26. package/src/core/database/repositories/file.repository.ts +117 -0
  27. package/src/core/database/repositories/meta.repository.ts +33 -0
  28. package/src/core/database/repositories/symbol.repository.ts +508 -0
  29. package/src/core/database/repository.ts +303 -0
  30. package/src/core/database/schema.ts +154 -0
  31. package/src/core/discovery/topology-detector.ts +805 -0
  32. package/src/core/ingestion/hasher.ts +5 -0
  33. package/src/core/ingestion/pipeline.ts +623 -0
  34. package/src/core/parser/behavioral-analyzer.ts +119 -0
  35. package/src/core/parser/boundary-tracker.ts +443 -0
  36. package/src/core/parser/extractors/base.ts +67 -0
  37. package/src/core/parser/extractors/blade.ts +159 -0
  38. package/src/core/parser/extractors/csharp.ts +244 -0
  39. package/src/core/parser/extractors/django-semantic.ts +687 -0
  40. package/src/core/parser/extractors/elysia-semantic.ts +538 -0
  41. package/src/core/parser/extractors/express-semantic.ts +444 -0
  42. package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
  43. package/src/core/parser/extractors/fastify-semantic.ts +774 -0
  44. package/src/core/parser/extractors/flask-semantic.ts +515 -0
  45. package/src/core/parser/extractors/frontend.ts +149 -0
  46. package/src/core/parser/extractors/go-semantic.ts +611 -0
  47. package/src/core/parser/extractors/go.ts +491 -0
  48. package/src/core/parser/extractors/hono-semantic.ts +567 -0
  49. package/src/core/parser/extractors/java.ts +225 -0
  50. package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
  52. package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
  53. package/src/core/parser/extractors/php.ts +569 -0
  54. package/src/core/parser/extractors/python.ts +498 -0
  55. package/src/core/parser/extractors/registry.ts +78 -0
  56. package/src/core/parser/extractors/ruby.ts +234 -0
  57. package/src/core/parser/extractors/rust.ts +286 -0
  58. package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
  59. package/src/core/parser/extractors/symfony-semantic.ts +354 -0
  60. package/src/core/parser/extractors/typescript.ts +826 -0
  61. package/src/core/parser/language-capabilities.ts +71 -0
  62. package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
  63. package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
  64. package/src/core/parser/schema/schema-provider-registry.ts +43 -0
  65. package/src/core/parser/schema/schema-provider.interface.ts +33 -0
  66. package/src/core/parser/tree-sitter.ts +63 -0
  67. package/src/core/parser/wasm-assets.ts +25 -0
  68. package/src/core/parser/wasm-loader.ts +274 -0
  69. package/src/core/resolver/call-graph-tracer.ts +724 -0
  70. package/src/core/resolver/import-resolver.ts +437 -0
  71. package/src/core/resolver/module-resolver.ts +482 -0
  72. package/src/core/resolver/path-resolver.ts +200 -0
  73. package/src/core/resolver/symbol-locator.ts +276 -0
  74. package/src/core/resolver/symbol-reference.ts +53 -0
  75. package/src/core/resolver/vertical-slice-tracer.ts +366 -0
  76. package/src/core/resources/ignore.ts +123 -0
  77. package/src/core/resources/limits.ts +14 -0
  78. package/src/core/resources/source-files.ts +62 -0
  79. package/src/core/resources/work-queue.ts +74 -0
  80. package/src/core/session/session-manager.ts +107 -0
  81. package/src/core/telemetry/telemetry.ts +97 -0
  82. package/src/core/topology/environment-detector.ts +973 -0
  83. package/src/core/topology/types.ts +83 -0
  84. package/src/index.ts +21 -0
  85. package/src/mcp/schemas.ts +1105 -0
  86. package/src/mcp/server.ts +774 -0
  87. package/src/mcp/tools/boundary.ts +17 -0
  88. package/src/mcp/tools/check-boundary.ts +387 -0
  89. package/src/mcp/tools/domain.ts +40 -0
  90. package/src/mcp/tools/feature.ts +67 -0
  91. package/src/mcp/tools/get-domain-catalog.ts +226 -0
  92. package/src/mcp/tools/get-environment-topology.ts +138 -0
  93. package/src/mcp/tools/get-feature-context.ts +224 -0
  94. package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
  95. package/src/mcp/tools/get-symbol-impact.ts +64 -0
  96. package/src/mcp/tools/get-symbol.ts +175 -0
  97. package/src/mcp/tools/locate-symbol.ts +196 -0
  98. package/src/mcp/tools/register-domain.ts +75 -0
  99. package/src/mcp/tools/register-feature.ts +110 -0
  100. package/src/mcp/tools/slice.ts +16 -0
  101. package/src/mcp/tools/symbol.ts +93 -0
  102. package/src/mcp/tools/trace-vertical-slice.ts +80 -0
  103. package/src/mcp/workspace-manager.ts +159 -0
  104. package/src/mcp/workspace-watcher.ts +202 -0
  105. package/src/types/index.ts +456 -0
  106. package/src/types/wasm.d.ts +4 -0
  107. package/src/utils/version-check.ts +209 -0
  108. package/src/version.ts +1 -0
@@ -0,0 +1,368 @@
1
+ import { readOptionalSourceFile } from "../../resources/source-files.ts";
2
+ import * as fs from "node:fs";
3
+ import * as path from "node:path";
4
+ import { blankCommentsAndStrings } from "../boundary-tracker.ts";
5
+ import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
6
+
7
+ export class McpCliSemanticExtractor implements SemanticSliceExtractor {
8
+ public readonly id = "mcp-cli";
9
+ public readonly name = "MCP Server & CLI Semantic Extractor";
10
+
11
+ public canHandle(projectRoot: string, framework?: string): boolean {
12
+ if (framework === "mcp-server" || framework === "cli") return true;
13
+
14
+ // Check presence of CLI or MCP directories
15
+ const hasMcp = fs.existsSync(path.join(projectRoot, "src/mcp/tools"));
16
+ const hasCli = fs.existsSync(path.join(projectRoot, "src/cli/commands"));
17
+ if (hasMcp || hasCli) return true;
18
+
19
+ // Check package.json for bin or MCP SDK
20
+ const pkgPath = path.join(projectRoot, "package.json");
21
+ if (fs.existsSync(pkgPath)) {
22
+ try {
23
+ const pkg = JSON.parse(readOptionalSourceFile(pkgPath, "utf-8"));
24
+ if (pkg.bin || pkg.dependencies?.["@modelcontextprotocol/sdk"]) {
25
+ return true;
26
+ }
27
+ } catch {}
28
+ }
29
+
30
+ return false;
31
+ }
32
+
33
+ public extractSlices(projectRoot: string, domainId?: number): VerticalSliceCandidate[] {
34
+ const slices: VerticalSliceCandidate[] = [];
35
+ const { toolPrefix, cliBinName } = this.resolveProjectNaming(projectRoot);
36
+ const registeredTools = this.scanRegisteredMcpToolNames(projectRoot);
37
+
38
+ // 1. Extract MCP Tools
39
+ const mcpToolsDir = path.join(projectRoot, "src/mcp/tools");
40
+ if (fs.existsSync(mcpToolsDir)) {
41
+ try {
42
+ const toolFiles = fs
43
+ .readdirSync(mcpToolsDir)
44
+ .filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
45
+
46
+ for (const file of toolFiles) {
47
+ const fullPath = path.join(mcpToolsDir, file);
48
+ const relPath = path.relative(projectRoot, fullPath).replace(/\\/g, "/");
49
+ const content = readOptionalSourceFile(fullPath, "utf-8");
50
+ const baseName = path.basename(file, path.extname(file));
51
+ const snakeBase = baseName.replace(/-/g, "_");
52
+
53
+ // MCP-07: Only create ingress slices for whitelisted public MCP tools
54
+ const toolIdentifier = registeredTools.get(snakeBase) || registeredTools.get(`${toolPrefix}_${snakeBase}`);
55
+ if (!toolIdentifier) continue;
56
+
57
+ // Detect handler function (both sync and async) and its 1-indexed line number
58
+ const handlerMatch = /export\s+(?:async\s+)?function\s+([a-zA-Z0-9_]+)/.exec(content);
59
+ const classMatch = /export\s+class\s+([A-Za-z0-9_]+)/.exec(content);
60
+ const actionName = handlerMatch ? handlerMatch[1] : `handle_${snakeBase}`;
61
+ const controllerClass = classMatch ? classMatch[1] : baseName;
62
+ const handlerLine =
63
+ handlerMatch && handlerMatch.index !== undefined
64
+ ? content.slice(0, handlerMatch.index).split("\n").length
65
+ : 1;
66
+
67
+ // Detect args interface and its line number
68
+ const argsMatch = /(?:export\s+)?interface\s+([a-zA-Z0-9_]+Args)\b/.exec(content);
69
+ const formRequestClass = argsMatch ? argsMatch[1] : null;
70
+ const argsLine =
71
+ argsMatch && argsMatch.index !== undefined
72
+ ? content.slice(0, argsMatch.index).split("\n").length
73
+ : undefined;
74
+
75
+ // Detect service/repository dependency and its actual file path
76
+ const serviceDep = this.resolveServiceDependency(projectRoot, fullPath, content);
77
+
78
+ const mcpChain: Array<{
79
+ stage: string;
80
+ symbol: string;
81
+ file?: string;
82
+ line?: number;
83
+ description?: string;
84
+ }> = [
85
+ {
86
+ stage: "ingress",
87
+ symbol: `tool:${toolIdentifier}`,
88
+ file: relPath,
89
+ line: handlerLine,
90
+ description: `MCP Tool Endpoint: ${toolIdentifier}`,
91
+ },
92
+ ];
93
+
94
+ if (formRequestClass) {
95
+ mcpChain.push({
96
+ stage: "validation",
97
+ symbol: formRequestClass,
98
+ file: relPath,
99
+ ...(argsLine ? { line: argsLine } : {}),
100
+ description: "MCP Argument Schema",
101
+ });
102
+ }
103
+
104
+ mcpChain.push({
105
+ stage: "controller",
106
+ symbol: classMatch ? `${controllerClass}::${actionName}` : actionName,
107
+ file: relPath,
108
+ line: handlerLine,
109
+ description: "Tool Handler Execution",
110
+ });
111
+
112
+ if (serviceDep) {
113
+ mcpChain.push({
114
+ stage: "service",
115
+ symbol: serviceDep.symbol,
116
+ ...(serviceDep.file ? { file: serviceDep.file } : {}),
117
+ description: "Core Engine Service",
118
+ });
119
+ }
120
+
121
+ slices.push({
122
+ domain_id: domainId ?? null,
123
+ feature_key: `mcp.${baseName}`,
124
+ http_method: "MCP",
125
+ route_uri: `tool:${toolIdentifier}`,
126
+ route_name: toolIdentifier,
127
+ controller_class: controllerClass,
128
+ action_name: actionName,
129
+ controller_file: relPath,
130
+ controller_line: handlerLine,
131
+ architecture_style: "rpc",
132
+ entry_kind: "mcp_tool",
133
+ execution_chain_json: JSON.stringify(mcpChain),
134
+ });
135
+ }
136
+ } catch {}
137
+ }
138
+
139
+ // 2. Extract CLI Commands
140
+ const cliCommandsDir = path.join(projectRoot, "src/cli/commands");
141
+ if (fs.existsSync(cliCommandsDir)) {
142
+ try {
143
+ const commandFiles = fs
144
+ .readdirSync(cliCommandsDir)
145
+ .filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
146
+
147
+ for (const file of commandFiles) {
148
+ const fullPath = path.join(cliCommandsDir, file);
149
+ const relPath = path.relative(projectRoot, fullPath).replace(/\\/g, "/");
150
+ const content = readOptionalSourceFile(fullPath, "utf-8");
151
+ const commandName = path.basename(file, path.extname(file));
152
+
153
+ const handlerMatch = /export\s+(?:async\s+)?function\s+([a-zA-Z0-9_]+)/.exec(content);
154
+ const classMatch = /export\s+class\s+([A-Za-z0-9_]+)/.exec(content);
155
+ const actionName = handlerMatch
156
+ ? handlerMatch[1]
157
+ : `handle${commandName.charAt(0).toUpperCase() + commandName.slice(1)}Command`;
158
+ const controllerClass = classMatch ? classMatch[1] : commandName;
159
+ const handlerLine =
160
+ handlerMatch && handlerMatch.index !== undefined
161
+ ? content.slice(0, handlerMatch.index).split("\n").length
162
+ : 1;
163
+
164
+ // Detect options / args
165
+ const optionsMatch = /(?:export\s+)?interface\s+([a-zA-Z0-9_]+(?:Options|Args))\b/.exec(content);
166
+ const formRequestClass = optionsMatch ? optionsMatch[1] : null;
167
+ const optionsLine =
168
+ optionsMatch && optionsMatch.index !== undefined
169
+ ? content.slice(0, optionsMatch.index).split("\n").length
170
+ : undefined;
171
+
172
+ const serviceDep = this.resolveServiceDependency(projectRoot, fullPath, content);
173
+
174
+ const cliChain: Array<{
175
+ stage: string;
176
+ symbol: string;
177
+ file?: string;
178
+ line?: number;
179
+ description?: string;
180
+ }> = [
181
+ {
182
+ stage: "ingress",
183
+ symbol: `${cliBinName} ${commandName}`,
184
+ file: relPath,
185
+ line: handlerLine,
186
+ description: `CLI Command Entrypoint: ${cliBinName} ${commandName}`,
187
+ },
188
+ ];
189
+
190
+ if (formRequestClass) {
191
+ cliChain.push({
192
+ stage: "validation",
193
+ symbol: formRequestClass,
194
+ file: relPath,
195
+ ...(optionsLine ? { line: optionsLine } : {}),
196
+ description: "CLI Options Interface",
197
+ });
198
+ }
199
+
200
+ cliChain.push({
201
+ stage: "controller",
202
+ symbol: classMatch ? `${controllerClass}::${actionName}` : actionName,
203
+ file: relPath,
204
+ line: handlerLine,
205
+ description: "Command Execution Handler",
206
+ });
207
+
208
+ if (serviceDep) {
209
+ cliChain.push({
210
+ stage: "service",
211
+ symbol: serviceDep.symbol,
212
+ ...(serviceDep.file ? { file: serviceDep.file } : {}),
213
+ description: "Core Engine Service",
214
+ });
215
+ }
216
+
217
+ slices.push({
218
+ domain_id: domainId ?? null,
219
+ feature_key: `cli.${commandName}`,
220
+ http_method: "CLI",
221
+ route_uri: `command:${commandName}`,
222
+ route_name: `${cliBinName} ${commandName}`,
223
+ controller_class: controllerClass,
224
+ action_name: actionName,
225
+ controller_file: relPath,
226
+ controller_line: handlerLine,
227
+ architecture_style: "cli",
228
+ entry_kind: "cli_command",
229
+ execution_chain_json: JSON.stringify(cliChain),
230
+ });
231
+ }
232
+ } catch {}
233
+ }
234
+
235
+ return slices;
236
+ }
237
+
238
+ private resolveProjectNaming(projectRoot: string): { toolPrefix: string; cliBinName: string } {
239
+ const pkgPath = path.join(projectRoot, "package.json");
240
+ if (fs.existsSync(pkgPath)) {
241
+ try {
242
+ const pkg = JSON.parse(readOptionalSourceFile(pkgPath, "utf-8"));
243
+ const rawName = typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : "mcp";
244
+ const toolPrefix = rawName.replace(/[^a-zA-Z0-9_]/g, "_").toLowerCase() || "mcp";
245
+ let cliBinName = rawName;
246
+ if (typeof pkg.bin === "string") {
247
+ cliBinName = rawName;
248
+ } else if (pkg.bin && typeof pkg.bin === "object") {
249
+ const firstBin = Object.keys(pkg.bin)[0];
250
+ if (firstBin) cliBinName = firstBin;
251
+ }
252
+ return { toolPrefix, cliBinName };
253
+ } catch {}
254
+ }
255
+ return { toolPrefix: "mcp", cliBinName: "cli" };
256
+ }
257
+
258
+ private scanRegisteredMcpToolNames(projectRoot: string): Map<string, string> {
259
+ const map = new Map<string, string>();
260
+ const serverPath = path.join(projectRoot, "src/mcp/server.ts");
261
+ if (!fs.existsSync(serverPath)) return map;
262
+
263
+ try {
264
+ const content = readOptionalSourceFile(serverPath, "utf-8");
265
+ const masked = blankCommentsAndStrings(content);
266
+ const scan = (start: number, namesInArray: boolean) => {
267
+ let depth = 0;
268
+ const names: string[] = [];
269
+ const property = /\b([A-Za-z_]\w*)\s*:\s*(['"])?/y;
270
+ for (let i = start; i < masked.length; i++) {
271
+ const ch = masked[i];
272
+ if ("[{(".includes(ch)) depth++;
273
+ else if ("]})".includes(ch)) {
274
+ if (--depth === 0) break;
275
+ }
276
+ if (depth !== (namesInArray ? 2 : 1) || (i > 0 && /\w/.test(masked[i - 1]))) continue;
277
+ property.lastIndex = i;
278
+ const match = property.exec(masked);
279
+ if (!match) continue;
280
+ if (!namesInArray) names.push(match[1]);
281
+ else if (match[1] === "name" && match[2]) {
282
+ const quoteStart = i + match[0].lastIndexOf(match[2]);
283
+ const quoteEnd = masked.indexOf(match[2], quoteStart + 1);
284
+ const name = content.slice(quoteStart + 1, quoteEnd);
285
+ if (/^[A-Za-z0-9_-]+$/.test(name)) names.push(name);
286
+ }
287
+ }
288
+ // Unbalanced declarations are not evidence of public registration.
289
+ if (depth !== 0) return;
290
+ for (const fullToolName of names) {
291
+ const normalized = fullToolName.replace(/-/g, "_");
292
+ map.set(normalized, fullToolName);
293
+ const withoutPrefix = normalized.replace(/^[a-z0-9]+_/, "");
294
+ if (withoutPrefix) map.set(withoutPrefix, fullToolName);
295
+ }
296
+ };
297
+ const listCall = /setRequestHandler\s*\(\s*ListToolsRequestSchema\b/.exec(masked);
298
+ if (listCall) {
299
+ const callStart = masked.indexOf("(", listCall.index);
300
+ let depth = 1;
301
+ let end = callStart + 1;
302
+ for (; end < masked.length && depth; end++) {
303
+ if (masked[end] === "(") depth++;
304
+ else if (masked[end] === ")") depth--;
305
+ }
306
+ const tools = /\btools\s*:\s*\[/.exec(masked.slice(callStart, end));
307
+ if (tools && depth === 0) scan(callStart + tools.index + tools[0].length - 1, true);
308
+ } else {
309
+ const schemas = /\bTOOL_SCHEMAS\s*=\s*\{/.exec(masked);
310
+ if (schemas) scan(schemas.index + schemas[0].length - 1, false);
311
+ }
312
+ } catch {}
313
+ return map;
314
+ }
315
+
316
+ private resolveServiceDependency(
317
+ projectRoot: string,
318
+ sourceFile: string,
319
+ content: string
320
+ ): { symbol: string; file?: string } | null {
321
+ const importRegex = /import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g;
322
+ let match: RegExpExecArray | null;
323
+
324
+ while ((match = importRegex.exec(content)) !== null) {
325
+ const clause = match[1];
326
+ const spec = match[2];
327
+ const identifiers = clause
328
+ .split(",")
329
+ .map((s) => s.trim().split(/\s+as\s+/)[0].trim())
330
+ .filter(Boolean);
331
+
332
+ for (const id of identifiers) {
333
+ if (
334
+ /(?:Repository|Service|Manager|Loader|Pipeline|Evaluator|Tracer|Detector|Engine|Store)$/.test(
335
+ id
336
+ )
337
+ ) {
338
+ const resolvedFile = this.resolveImportFile(projectRoot, sourceFile, spec);
339
+ return {
340
+ symbol: id,
341
+ ...(resolvedFile ? { file: resolvedFile } : {}),
342
+ };
343
+ }
344
+ }
345
+ }
346
+
347
+ return null;
348
+ }
349
+
350
+ private resolveImportFile(projectRoot: string, sourceFile: string, importSpec: string): string | undefined {
351
+ if (!importSpec.startsWith(".")) return undefined;
352
+ const baseResolved = path.resolve(path.dirname(sourceFile), importSpec);
353
+ const candidates = [
354
+ baseResolved,
355
+ `${baseResolved}.ts`,
356
+ `${baseResolved}.js`,
357
+ baseResolved.replace(/\.js$/, ".ts"),
358
+ path.join(baseResolved, "index.ts"),
359
+ ];
360
+ for (const c of candidates) {
361
+ if (fs.existsSync(c) && fs.statSync(c).isFile()) {
362
+ return path.relative(projectRoot, c).replace(/\\/g, "/");
363
+ }
364
+ }
365
+ return undefined;
366
+ }
367
+ }
368
+