@dimassetoid/septum-mcp 0.3.0 → 0.5.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 (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 +255 -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
@@ -0,0 +1,268 @@
1
+ import ts from "typescript";
2
+ import { type Handler, literal, TypeScriptBindings, nameText, nodes, unwrap } from "./typescript-bindings.ts";
3
+
4
+ export type Registration = { name: string; node: ts.Node; handler?: Handler; bin?: string };
5
+
6
+ function returns(handler: Handler): Array<ts.Expression | undefined> {
7
+ const body = handler.node.body;
8
+ if (!body) return [];
9
+ if (!ts.isBlock(body)) return [body];
10
+ return nodes(body, true).filter(ts.isReturnStatement).map(node => node.expression);
11
+ }
12
+
13
+ function property(object: ts.ObjectLiteralExpression, name: string): ts.Expression | undefined {
14
+ const matches = object.properties.filter(item => (ts.isPropertyAssignment(item) || ts.isShorthandPropertyAssignment(item)) &&
15
+ nameText(item.name) === name);
16
+ if (matches.length !== 1 || object.properties.some(item => ts.isSpreadAssignment(item) || item.name && ts.isComputedPropertyName(item.name))) {
17
+ return undefined;
18
+ }
19
+ const item = matches[0]!;
20
+ return ts.isPropertyAssignment(item) ? item.initializer : ts.isShorthandPropertyAssignment(item) ? item.name : undefined;
21
+ }
22
+
23
+ function constant(expression: ts.Expression | undefined, bindings: TypeScriptBindings, depth = 0): ts.Expression | undefined {
24
+ if (!expression || depth > 16) return undefined;
25
+ const node = unwrap(expression);
26
+ if (ts.isIdentifier(node)) return constant(bindings.initializer(bindings.declaration(node)), bindings, depth + 1);
27
+ return node;
28
+ }
29
+
30
+ function unique(handlers: Array<Handler | undefined>): Handler | undefined {
31
+ const first = handlers[0];
32
+ return first && handlers.every(item => item?.node === first.node) ? first : undefined;
33
+ }
34
+
35
+ function endsCase(statement: ts.Statement | undefined): boolean {
36
+ if (!statement) return false;
37
+ if (ts.isBlock(statement)) return endsCase(statement.statements.at(-1));
38
+ return ts.isReturnStatement(statement) || ts.isThrowStatement(statement) ||
39
+ ts.isBreakStatement(statement) && !statement.label;
40
+ }
41
+
42
+ class Dispatch {
43
+ private readonly assignments = new Map<ts.Declaration, Array<ts.Expression | undefined>>();
44
+
45
+ constructor(private readonly bindings: TypeScriptBindings, private readonly body: ts.Node | undefined, private readonly seeds: Map<ts.Declaration, string>) {
46
+ if (!body) return;
47
+ for (const node of nodes(body)) {
48
+ if (!ts.isBinaryExpression(node) || !ts.isIdentifier(node.left) ||
49
+ node.operatorToken.kind < ts.SyntaxKind.FirstAssignment || node.operatorToken.kind > ts.SyntaxKind.LastAssignment) continue;
50
+ const declaration = bindings.declaration(node.left);
51
+ if (!declaration) continue;
52
+ const writes = this.assignments.get(declaration) ?? [];
53
+ writes.push(node.operatorToken.kind === ts.SyntaxKind.EqualsToken ? node.right : undefined);
54
+ this.assignments.set(declaration, writes);
55
+ }
56
+ }
57
+
58
+ private origin(expression: ts.Expression | undefined, depth = 0): string | undefined {
59
+ if (!expression || depth > 20) return undefined;
60
+ const node = unwrap(expression);
61
+ const from = (value: ts.Expression | undefined) => this.origin(value, depth + 1);
62
+ if (ts.isIdentifier(node)) {
63
+ if (node.text === "process" && !this.bindings.declaration(node)) return "process";
64
+ const declaration = this.bindings.declaration(node);
65
+ if (!declaration) return undefined;
66
+ const seed = this.seeds.get(declaration);
67
+ if (seed) return seed;
68
+ const writes = this.assignments.get(declaration);
69
+ if (ts.isVariableDeclaration(declaration)) {
70
+ if (writes) return writes.length === 1 && !declaration.initializer && (writes[0]?.getStart() ?? Infinity) < node.getStart()
71
+ ? from(writes[0]) : undefined;
72
+ return from(declaration.initializer);
73
+ }
74
+ if (ts.isBindingElement(declaration) && ts.isObjectBindingPattern(declaration.parent) && !declaration.initializer && !declaration.dotDotDotToken) {
75
+ const field = nameText(declaration.propertyName ?? declaration.name);
76
+ const owner = declaration.parent.parent;
77
+ const parent = ts.isVariableDeclaration(owner) ? from(owner.initializer) : this.seeds.get(owner);
78
+ if (parent && field && !writes) return parent + "." + field;
79
+ }
80
+ }
81
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
82
+ const base = from(node.expression);
83
+ const field = ts.isPropertyAccessExpression(node) ? node.name.text
84
+ : ts.isNumericLiteral(node.argumentExpression) || ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : undefined;
85
+ if (base && field !== undefined) return base + "." + field;
86
+ }
87
+ if (ts.isCallExpression(node)) {
88
+ if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "slice" &&
89
+ from(node.expression.expression) === "process.argv" && node.arguments[0]?.getText() === "2") return "argv";
90
+ if (this.bindings.sdk(node.expression, "parseArgs", "node:util") || this.bindings.sdk(node.expression, "parseArgs", "util")) {
91
+ const options = node.arguments[0] && unwrap(node.arguments[0]);
92
+ if (options && ts.isObjectLiteralExpression(options) && from(property(options, "args")) === "argv") return "cli";
93
+ }
94
+ if (from(node.arguments[0]) === "request.params.name") {
95
+ const handler = this.bindings.handler(node.expression);
96
+ const param = handler?.node.parameters[0];
97
+ if (handler && param) {
98
+ const values = returns(handler);
99
+ // Support a local validation helper only when each return preserves its input name.
100
+ if (values.length && values.every(value => {
101
+ const object = value && unwrap(value);
102
+ const name = object && ts.isObjectLiteralExpression(object) ? property(object, "name") : undefined;
103
+ return name && ts.isIdentifier(name) && this.bindings.declaration(name) === param;
104
+ })) return "validated";
105
+ }
106
+ }
107
+ }
108
+ return undefined;
109
+ }
110
+
111
+ cases(origins: string[], cli = false): Registration[] {
112
+ const entries: Registration[] = [];
113
+ const body = this.body;
114
+ if (!body) return entries;
115
+ const visited = new Set<ts.Node>();
116
+ const visit = (node: ts.Node): void => {
117
+ if (visited.has(node) || visited.size > 24) return;
118
+ visited.add(node);
119
+ for (const child of nodes(node, true)) {
120
+ if (ts.isSwitchStatement(child) && origins.includes(this.origin(child.expression) ?? "")) {
121
+ let labels: Array<{ name: string; node: ts.CaseClause }> = [];
122
+ const clauses = child.caseBlock.clauses;
123
+ for (const [index, clause] of clauses.entries()) {
124
+ if (!ts.isCaseClause(clause)) { labels = []; continue; }
125
+ const name = literal(clause.expression);
126
+ if (name) labels.push({ name, node: clause });
127
+ if (!clause.statements.length) continue;
128
+ const statements = nodes(clause, true);
129
+ const values = statements.filter(ts.isReturnStatement).map(statement => statement.expression);
130
+ if (cli) values.push(...statements.filter(ts.isExpressionStatement).map(statement => statement.expression));
131
+ const handlers = values.flatMap(expression => {
132
+ if (!expression) return cli ? [] : [undefined];
133
+ const call = unwrap(expression);
134
+ if (!ts.isCallExpression(call)) return cli ? [] : [undefined];
135
+ return [this.bindings.handler(call.expression)];
136
+ });
137
+ const fallsThrough = index < clauses.length - 1 && !endsCase(clause.statements.at(-1));
138
+ for (const label of labels) entries.push({ ...label, handler: fallsThrough ? undefined : unique(handlers) });
139
+ labels = [];
140
+ }
141
+ } else if (ts.isCallExpression(child) && !cli) {
142
+ const callee = child.expression;
143
+ const callbacks = ts.isPropertyAccessExpression(callee) && callee.name.text === "runTool" ? child.arguments : [];
144
+ for (const expression of [callee, ...callbacks]) {
145
+ const handler = this.bindings.handler(expression);
146
+ if (handler?.node.body && handler.node.getSourceFile() === node.getSourceFile() &&
147
+ handler.node.pos >= body.pos && handler.node.end <= body.end) visit(handler.node.body);
148
+ }
149
+ }
150
+ }
151
+ };
152
+ visit(body);
153
+ return entries;
154
+ }
155
+ }
156
+
157
+ function sdkServer(expression: ts.Expression, bindings: TypeScriptBindings, depth = 0): { node: ts.NewExpression; highLevel: boolean } | undefined {
158
+ if (depth > 16) return undefined;
159
+ const node = unwrap(expression);
160
+ if (ts.isIdentifier(node)) {
161
+ const init = bindings.initializer(bindings.declaration(node));
162
+ return init && sdkServer(init, bindings, depth + 1);
163
+ }
164
+ if (!ts.isNewExpression(node)) return undefined;
165
+ if (bindings.sdk(node.expression, "McpServer")) return { node, highLevel: true };
166
+ if (bindings.sdk(node.expression, "Server")) return { node, highLevel: false };
167
+ return undefined;
168
+ }
169
+
170
+ /** Recognize a literal tool catalog projected directly by a tools/list handler. */
171
+ function projectedToolCatalog(expression: ts.Expression | undefined, bindings: TypeScriptBindings): Registration[] {
172
+ if (!expression || !ts.isCallExpression(expression) || !ts.isPropertyAccessExpression(expression.expression) ||
173
+ expression.expression.name.text !== "map" || expression.arguments.length !== 1) return [];
174
+ const projection = expression.arguments[0];
175
+ if (!ts.isArrowFunction(projection) || !ts.isParenthesizedExpression(projection.body)) return [];
176
+ const body = unwrap(projection.body);
177
+ if (!ts.isObjectLiteralExpression(body) || !property(body, "name") || !property(body, "inputSchema")) return [];
178
+ const array = bindings.value(expression.expression.expression);
179
+ if (!array || !ts.isArrayLiteralExpression(array)) return [];
180
+ return array.elements.flatMap(element => {
181
+ if (!ts.isCallExpression(element) || !ts.isIdentifier(element.expression) ||
182
+ element.expression.text !== "defineTool" || element.arguments.length !== 1) return [];
183
+ const definition = element.arguments[0];
184
+ if (!ts.isObjectLiteralExpression(definition)) return [];
185
+ const name = literal(property(definition, "name"));
186
+ if (!name || !property(definition, "schema") || !property(definition, "inputSchema")) return [];
187
+ const execute = bindings.handler(property(definition, "execute"));
188
+ const results = execute ? returns(execute) : [];
189
+ const call = results.length === 1 ? results[0] : undefined;
190
+ const handler = call && ts.isCallExpression(call) ? bindings.handler(call.expression) : undefined;
191
+ return [{ name, node: definition, handler }];
192
+ });
193
+ }
194
+
195
+ export function mcpRegistrations(source: ts.SourceFile, bindings: TypeScriptBindings): Registration[] {
196
+ const lists = new Map<ts.NewExpression, Registration[]>();
197
+ const dispatches = new Map<ts.NewExpression, Registration[]>();
198
+ const direct: Registration[] = [];
199
+ for (const node of nodes(source)) {
200
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) continue;
201
+ const method = node.expression.name.text;
202
+ if (!["registerTool", "tool", "setRequestHandler"].includes(method)) continue;
203
+ const server = sdkServer(node.expression.expression, bindings);
204
+ if (!server) continue;
205
+ if (method !== "setRequestHandler") {
206
+ if (!server.highLevel || node.arguments.length < (method === "registerTool" ? 3 : 2)) continue;
207
+ const name = literal(constant(node.arguments[0], bindings));
208
+ if (name) direct.push({ name, node, handler: bindings.handler(node.arguments.at(-1)) });
209
+ continue;
210
+ }
211
+ if (server.highLevel) continue;
212
+ const schema = node.arguments[0];
213
+ const callback = bindings.handler(node.arguments[1]);
214
+ if (!callback) continue;
215
+ if (bindings.sdk(schema, "ListToolsRequestSchema")) {
216
+ const entries = lists.get(server.node) ?? [];
217
+ const results = returns(callback);
218
+ if (results.length !== 1) continue;
219
+ const object = constant(results[0], bindings);
220
+ const array = object && ts.isObjectLiteralExpression(object) ? constant(property(object, "tools"), bindings) : undefined;
221
+ if (!array || !ts.isArrayLiteralExpression(array)) {
222
+ entries.push(...projectedToolCatalog(array, bindings));
223
+ lists.set(server.node, entries);
224
+ continue;
225
+ }
226
+ for (const element of array.elements) {
227
+ if (!ts.isObjectLiteralExpression(element)) continue;
228
+ const name = literal(constant(property(element, "name"), bindings));
229
+ if (name) entries.push({ name, node: element });
230
+ }
231
+ lists.set(server.node, entries);
232
+ } else if (bindings.sdk(schema, "CallToolRequestSchema")) {
233
+ const param = callback.node.parameters[0];
234
+ if (!param) continue;
235
+ const dispatch = new Dispatch(bindings, callback.node.body, new Map([[param, "request"]]));
236
+ const entries = dispatches.get(server.node) ?? [];
237
+ entries.push(...dispatch.cases(["request.params.name", "validated.name"]));
238
+ dispatches.set(server.node, entries);
239
+ }
240
+ }
241
+ for (const [server, published] of lists) {
242
+ const registered = dispatches.get(server) ?? [];
243
+ for (const entry of published) direct.push({
244
+ ...entry, handler: entry.handler ?? unique(registered.filter(item => item.name === entry.name).map(item => item.handler)),
245
+ });
246
+ }
247
+ return direct;
248
+ }
249
+
250
+ export function cliRegistrations(source: ts.SourceFile, bin: string, bindings: TypeScriptBindings): Registration[] {
251
+ const entries: Registration[] = [];
252
+ const argv = (expr?: ts.Expression): boolean => Boolean(expr && ts.isPropertyAccessExpression(expr) &&
253
+ expr.name.text === "argv" && ts.isIdentifier(expr.expression) && expr.expression.text === "process" && !bindings.declaration(expr.expression));
254
+ // A bin may dispatch directly or invoke a statically bound function with process.argv.
255
+ const origins = ["process.argv.2", "argv.0", "cli.positionals.0"];
256
+ entries.push(...new Dispatch(bindings, source, new Map()).cases(origins, true));
257
+ for (const statement of source.statements) {
258
+ if (!ts.isExpressionStatement(statement)) continue;
259
+ const call = unwrap(statement.expression);
260
+ if (!ts.isCallExpression(call)) continue;
261
+ const handler = bindings.handler(call.expression);
262
+ if (!handler) continue;
263
+ const seeds = new Map<ts.Declaration, string>();
264
+ handler.node.parameters.forEach((param, index) => { if (argv(call.arguments[index])) seeds.set(param, "process.argv"); });
265
+ if (seeds.size) entries.push(...new Dispatch(bindings, handler.node.body, seeds).cases(origins, true));
266
+ }
267
+ return entries.map(entry => ({ ...entry, bin }));
268
+ }