@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.
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
import { WorkspaceManager, resolveServerWorkspace, isWorkspaceInitialized, type WorkspaceLease } from "./workspace-manager.ts";
|
|
2
|
+
import { RESOURCE_LIMITS } from "../core/resources/limits.ts";
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import {
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
ListToolsRequestSchema,
|
|
8
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
+
import { ConfigLoader } from "../core/config/loader.ts";
|
|
10
|
+
import { SessionManager } from "../core/session/session-manager.ts";
|
|
11
|
+
import { SeptumTelemetry } from "../core/telemetry/telemetry.ts";
|
|
12
|
+
import { handleDomainTool } from "./tools/domain.ts";
|
|
13
|
+
import { handleSymbolTool } from "./tools/symbol.ts";
|
|
14
|
+
import { handleSliceTool } from "./tools/slice.ts";
|
|
15
|
+
import { handleBoundaryTool } from "./tools/boundary.ts";
|
|
16
|
+
import { handleFeatureTool } from "./tools/feature.ts";
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
DomainToolSchema,
|
|
20
|
+
SymbolToolSchema,
|
|
21
|
+
SliceToolSchema,
|
|
22
|
+
BoundaryToolSchema,
|
|
23
|
+
FeatureToolSchema,
|
|
24
|
+
} from "./schemas.ts";
|
|
25
|
+
import { SEPTUM_VERSION, checkRuntimeVersion } from "../utils/version-check.ts";
|
|
26
|
+
|
|
27
|
+
const TOOL_SCHEMAS = {
|
|
28
|
+
septum_domain: DomainToolSchema,
|
|
29
|
+
septum_symbol: SymbolToolSchema,
|
|
30
|
+
septum_slice: SliceToolSchema,
|
|
31
|
+
septum_boundary: BoundaryToolSchema,
|
|
32
|
+
septum_feature: FeatureToolSchema,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function extractPathHint(args: unknown): string | undefined {
|
|
36
|
+
if (!args) return undefined;
|
|
37
|
+
|
|
38
|
+
if (typeof args === "string") {
|
|
39
|
+
const trimmed = args.trim();
|
|
40
|
+
if (trimmed.length > 0) return trimmed;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Array.isArray(args)) {
|
|
45
|
+
if (typeof args[0] === "string" && args[0].trim()) {
|
|
46
|
+
return args[0].trim();
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof args === "object" && args !== null) {
|
|
52
|
+
const record = args as Record<string, any>;
|
|
53
|
+
|
|
54
|
+
const explicitWorkspace =
|
|
55
|
+
record.workspace_path ??
|
|
56
|
+
record.workspacePath ??
|
|
57
|
+
record.workspace ??
|
|
58
|
+
record.project_root ??
|
|
59
|
+
record.projectRoot ??
|
|
60
|
+
record.target_path ??
|
|
61
|
+
record.targetPath;
|
|
62
|
+
if (typeof explicitWorkspace === "string" && explicitWorkspace.trim()) {
|
|
63
|
+
return explicitWorkspace.trim();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const filePath =
|
|
67
|
+
record.file_path ??
|
|
68
|
+
record.filePath ??
|
|
69
|
+
record.from_file ??
|
|
70
|
+
record.fromFile ??
|
|
71
|
+
record.source_file ??
|
|
72
|
+
record.sourceFile ??
|
|
73
|
+
record.entry_file ??
|
|
74
|
+
record.entryFile;
|
|
75
|
+
if (typeof filePath === "string" && filePath.trim()) {
|
|
76
|
+
return filePath.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const filePaths =
|
|
80
|
+
record.file_paths ??
|
|
81
|
+
record.filePaths ??
|
|
82
|
+
record.files ??
|
|
83
|
+
record.paths;
|
|
84
|
+
if (Array.isArray(filePaths) && typeof filePaths[0] === "string" && filePaths[0].trim()) {
|
|
85
|
+
return filePaths[0].trim();
|
|
86
|
+
}
|
|
87
|
+
if (typeof filePaths === "string" && filePaths.trim()) {
|
|
88
|
+
return filePaths.trim();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (
|
|
92
|
+
!record.domain &&
|
|
93
|
+
!record.name &&
|
|
94
|
+
!record.domain_name &&
|
|
95
|
+
!record.domainName &&
|
|
96
|
+
typeof record.root === "string" &&
|
|
97
|
+
record.root.trim()
|
|
98
|
+
) {
|
|
99
|
+
return record.root.trim();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function countLines(text: string): number {
|
|
107
|
+
let count = 1;
|
|
108
|
+
for (let i = 0; i < text.length; i++) {
|
|
109
|
+
if (text.charCodeAt(i) === 10) count++;
|
|
110
|
+
}
|
|
111
|
+
return count;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function runMCPServer(): Promise<void> {
|
|
115
|
+
const manager = new WorkspaceManager();
|
|
116
|
+
|
|
117
|
+
const server = new Server(
|
|
118
|
+
{
|
|
119
|
+
name: "septum-mcp-server",
|
|
120
|
+
version: SEPTUM_VERSION,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
capabilities: {
|
|
124
|
+
tools: {},
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
130
|
+
return {
|
|
131
|
+
tools: [
|
|
132
|
+
{
|
|
133
|
+
name: "septum_domain",
|
|
134
|
+
description:
|
|
135
|
+
"Domain Catalog, Registration & Environment Topology Engine. Manages macro architecture, domain topology, bounded-context registration, and infrastructure plane (Edge, Gateway, Host, Runtime, Storage, Telemetry). Token-efficient (< 400 tokens).",
|
|
136
|
+
inputSchema: {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
action: {
|
|
140
|
+
type: "string",
|
|
141
|
+
enum: ["catalog", "register", "topology"],
|
|
142
|
+
default: "catalog",
|
|
143
|
+
description: "Sub-operation to execute: 'catalog' (inspect domain/macro map), 'register' (dynamically register bounded-context domain), or 'topology' (6-layer infrastructure plane).",
|
|
144
|
+
},
|
|
145
|
+
domain: {
|
|
146
|
+
type: "string",
|
|
147
|
+
description: "Target domain name (e.g. 'orders', 'core'). If omitted in catalog action, returns project-wide Macro Semantic Map.",
|
|
148
|
+
},
|
|
149
|
+
detail_level: {
|
|
150
|
+
type: "string",
|
|
151
|
+
enum: ["compact", "full"],
|
|
152
|
+
default: "compact",
|
|
153
|
+
description: "Catalog detail level: 'compact' (default, token-efficient summary with file connections) or 'full' (includes full signatures).",
|
|
154
|
+
},
|
|
155
|
+
archetype_filter: {
|
|
156
|
+
type: "string",
|
|
157
|
+
description: "Optional archetype filter (e.g. 'service', 'model', 'controller', 'repository').",
|
|
158
|
+
},
|
|
159
|
+
file_filter: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "Optional substring filter to inspect specific file(s) within the domain.",
|
|
162
|
+
},
|
|
163
|
+
root: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "Root directory path for domain registration (action='register').",
|
|
166
|
+
},
|
|
167
|
+
description: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Architectural purpose of the domain (action='register').",
|
|
170
|
+
},
|
|
171
|
+
allowed_dependencies: {
|
|
172
|
+
type: "array",
|
|
173
|
+
items: { type: "string" },
|
|
174
|
+
description: "List of domain names this domain is allowed to import (action='register').",
|
|
175
|
+
},
|
|
176
|
+
forbidden_dependencies: {
|
|
177
|
+
type: "array",
|
|
178
|
+
items: { type: "string" },
|
|
179
|
+
description: "List of domain names strictly forbidden from being imported (action='register').",
|
|
180
|
+
},
|
|
181
|
+
archetypes: {
|
|
182
|
+
type: "object",
|
|
183
|
+
description: "Layer archetypes mapping (action='register').",
|
|
184
|
+
},
|
|
185
|
+
ingest_now: {
|
|
186
|
+
type: "boolean",
|
|
187
|
+
default: false,
|
|
188
|
+
description: "Whether to immediately run AST ingestion on domain files upon registration.",
|
|
189
|
+
},
|
|
190
|
+
resolve: {
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: {
|
|
193
|
+
layer: {
|
|
194
|
+
type: "string",
|
|
195
|
+
enum: ["edge", "gateway", "host", "runtime", "storage", "telemetry"],
|
|
196
|
+
},
|
|
197
|
+
platform: { type: "string" },
|
|
198
|
+
constraints: { type: "array", items: { type: "string" } },
|
|
199
|
+
},
|
|
200
|
+
description: "Record and verify infrastructure layer in SQLite SSOT (action='topology').",
|
|
201
|
+
},
|
|
202
|
+
resolve_node: {
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: {
|
|
205
|
+
id: { type: "string" },
|
|
206
|
+
layer: { type: "string", enum: ["edge", "gateway", "host", "runtime", "storage", "telemetry"] },
|
|
207
|
+
name: { type: "string" },
|
|
208
|
+
platform: { type: "string" },
|
|
209
|
+
domain_or_ip: { type: "string" },
|
|
210
|
+
role: { type: "string" },
|
|
211
|
+
connected_to: { type: "array", items: { type: "string" } },
|
|
212
|
+
constraints: { type: "array", items: { type: "string" } },
|
|
213
|
+
},
|
|
214
|
+
description: "Record distributed topology node in SQLite SSOT (action='topology').",
|
|
215
|
+
},
|
|
216
|
+
refresh: {
|
|
217
|
+
type: "boolean",
|
|
218
|
+
description: "Force re-detection from codebase files, ignoring cached status (action='topology').",
|
|
219
|
+
},
|
|
220
|
+
workspace_path: {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
required: [],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "septum_symbol",
|
|
230
|
+
description:
|
|
231
|
+
"Unified Symbol Engine: single entrypoint for symbol location, full contract inspection, refactoring blast radius (impact), and Single Responsibility / God Function complexity hotspots.",
|
|
232
|
+
inputSchema: {
|
|
233
|
+
type: "object",
|
|
234
|
+
properties: {
|
|
235
|
+
action: {
|
|
236
|
+
type: "string",
|
|
237
|
+
enum: ["locate", "inspect", "impact", "hotspots"],
|
|
238
|
+
default: "locate",
|
|
239
|
+
description: "Sub-operation: 'locate' (fuzzy search/error log resolution), 'inspect' (physical coordinates & signatures), 'impact' (blast radius & inbound callers), or 'hotspots' (complexity & SRP smells).",
|
|
240
|
+
},
|
|
241
|
+
query: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description: "Symbol name, call syntax (e.g. 'OrderController::cancelOrder'), or search query (for locate, inspect, impact).",
|
|
244
|
+
},
|
|
245
|
+
domain: {
|
|
246
|
+
type: "string",
|
|
247
|
+
description: "Optional domain filter (e.g. 'orders').",
|
|
248
|
+
},
|
|
249
|
+
file_path: {
|
|
250
|
+
type: "string",
|
|
251
|
+
description: "Exact indexed repository-relative file path. Use it to select one candidate when names are ambiguous.",
|
|
252
|
+
},
|
|
253
|
+
symbol_ref: {
|
|
254
|
+
type: "object",
|
|
255
|
+
description: "Declaration reference returned by locate/inspect or a full catalog. Selects an overload for locate/inspect; stale indexed fingerprints are refused.",
|
|
256
|
+
properties: {
|
|
257
|
+
file_path: { type: "string", minLength: 1 },
|
|
258
|
+
language: { type: "string", minLength: 1 },
|
|
259
|
+
name: { type: "string", minLength: 1 },
|
|
260
|
+
kind: { type: "string", minLength: 1 },
|
|
261
|
+
signature: { type: "string" },
|
|
262
|
+
start_line: { type: "integer", minimum: 1 },
|
|
263
|
+
end_line: { type: "integer", minimum: 1 },
|
|
264
|
+
indexed_content_hash: { type: "string", minLength: 1 },
|
|
265
|
+
container: { type: "string" },
|
|
266
|
+
receiver: { type: "string" },
|
|
267
|
+
},
|
|
268
|
+
required: ["file_path", "language", "name", "kind", "signature", "start_line", "end_line", "indexed_content_hash"],
|
|
269
|
+
},
|
|
270
|
+
include_source: {
|
|
271
|
+
type: "boolean",
|
|
272
|
+
default: false,
|
|
273
|
+
description: "For action='inspect', include a bounded source slice only when the indexed file fingerprint still matches disk.",
|
|
274
|
+
},
|
|
275
|
+
source_start_line: {
|
|
276
|
+
type: "number",
|
|
277
|
+
minimum: 1,
|
|
278
|
+
description: "First line to return within the selected symbol range (action='inspect').",
|
|
279
|
+
},
|
|
280
|
+
source_line_limit: {
|
|
281
|
+
type: "number",
|
|
282
|
+
minimum: 1,
|
|
283
|
+
maximum: 200,
|
|
284
|
+
default: 120,
|
|
285
|
+
description: "Maximum source lines returned (action='inspect', capped at 200).",
|
|
286
|
+
},
|
|
287
|
+
include_dependencies: {
|
|
288
|
+
type: "boolean",
|
|
289
|
+
default: true,
|
|
290
|
+
description: "Whether to include injected dependencies and outbound calls (action='inspect').",
|
|
291
|
+
},
|
|
292
|
+
min_lines: {
|
|
293
|
+
type: "number",
|
|
294
|
+
description: "Minimum physical lines of code threshold (action='hotspots', default: 30).",
|
|
295
|
+
},
|
|
296
|
+
min_nesting: {
|
|
297
|
+
type: "number",
|
|
298
|
+
description: "Minimum control-flow nesting depth threshold (action='hotspots').",
|
|
299
|
+
},
|
|
300
|
+
kind: {
|
|
301
|
+
type: "string",
|
|
302
|
+
description: "Filter symbol kind: 'function' | 'method' | 'class' | 'struct' | 'interface' (action='hotspots').",
|
|
303
|
+
},
|
|
304
|
+
sort_by: {
|
|
305
|
+
type: "string",
|
|
306
|
+
enum: ["risk_score", "line_count", "lines", "nesting"],
|
|
307
|
+
default: "risk_score",
|
|
308
|
+
description: "Sorting criteria for hotspots (action='hotspots').",
|
|
309
|
+
},
|
|
310
|
+
limit: {
|
|
311
|
+
type: "number",
|
|
312
|
+
description: "Maximum results to return (default: 10 for locate, 30 for hotspots).",
|
|
313
|
+
},
|
|
314
|
+
workspace_path: {
|
|
315
|
+
type: "string",
|
|
316
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
required: [],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "septum_slice",
|
|
324
|
+
description:
|
|
325
|
+
"Vertical Execution Slice Tracer: traces end-to-end execution flow (Ingress -> Validation -> Controller -> Service -> Repository -> Entity) from route URI, controller action, or high-level intent without guessing files.",
|
|
326
|
+
inputSchema: {
|
|
327
|
+
type: "object",
|
|
328
|
+
properties: {
|
|
329
|
+
query: {
|
|
330
|
+
type: "string",
|
|
331
|
+
description: "Route URI (e.g. 'POST /orders/{id}/pay'), action (e.g. 'OrderController@pay'), or high-level task intent.",
|
|
332
|
+
},
|
|
333
|
+
max_depth: {
|
|
334
|
+
type: "number",
|
|
335
|
+
default: 5,
|
|
336
|
+
minimum: 1,
|
|
337
|
+
maximum: 8,
|
|
338
|
+
description: "Maximum depth to trace (default: 5, min: 1, max: 8). Use 6-8 for deep Event/Job/Queue traces.",
|
|
339
|
+
},
|
|
340
|
+
workspace_path: {
|
|
341
|
+
type: "string",
|
|
342
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
required: ["query"],
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "septum_boundary",
|
|
350
|
+
description:
|
|
351
|
+
"Architecture Guard & Circular Dependency Gate: Pre-flight boundary check verifying proposed file edits, additions, and imports against domain rules and feature touchpoints, or auditing the entire repository / staged files for cross-domain and circular dependencies.",
|
|
352
|
+
inputSchema: {
|
|
353
|
+
type: "object",
|
|
354
|
+
properties: {
|
|
355
|
+
scope: {
|
|
356
|
+
type: "string",
|
|
357
|
+
enum: ["file", "staged", "all", "domain"],
|
|
358
|
+
description: "Audit scope: 'file' requires file_path or non-empty file_paths; 'staged', 'all', and 'domain' reject file targets and proposed_imports. 'domain' requires a registered domain; 'all' rejects domain filters. If omitted, infer file/staged/domain/all from arguments.",
|
|
359
|
+
},
|
|
360
|
+
file_path: {
|
|
361
|
+
type: "string",
|
|
362
|
+
description: "Path of the file being edited or created (scope='file' only). Use either file_path or file_paths.",
|
|
363
|
+
},
|
|
364
|
+
file_paths: {
|
|
365
|
+
type: "array",
|
|
366
|
+
items: { type: "string" },
|
|
367
|
+
description: "Non-empty list of file paths for batch proposed-import checks (scope='file' only). Use either file_path or file_paths.",
|
|
368
|
+
},
|
|
369
|
+
proposed_imports: {
|
|
370
|
+
type: "array",
|
|
371
|
+
items: { type: "string" },
|
|
372
|
+
description: "List of proposed import statements or target symbols (scope='file' only).",
|
|
373
|
+
},
|
|
374
|
+
domain: {
|
|
375
|
+
type: "string",
|
|
376
|
+
description: "Registered domain name, required for scope='domain'; optional for staged/file checks. Explicit scope='all' does not accept a domain filter.",
|
|
377
|
+
},
|
|
378
|
+
feature_key: {
|
|
379
|
+
type: "string",
|
|
380
|
+
description: "Optional feature key to validate touchpoints against.",
|
|
381
|
+
},
|
|
382
|
+
workspace_path: {
|
|
383
|
+
type: "string",
|
|
384
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
required: [],
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: "septum_feature",
|
|
392
|
+
description:
|
|
393
|
+
"Active Touchpoint & Scope Lock Engine: manages feature task context, touchpoint locks (.septum/session.json), and session release to enforce surgical blast-radius boundaries.",
|
|
394
|
+
inputSchema: {
|
|
395
|
+
type: "object",
|
|
396
|
+
properties: {
|
|
397
|
+
action: {
|
|
398
|
+
type: "string",
|
|
399
|
+
enum: ["get", "lock", "release"],
|
|
400
|
+
default: "get",
|
|
401
|
+
description: "Feature lifecycle action: 'get' (retrieve feature context), 'lock' (register feature & establish active session lease), or 'release' (release active session lock).",
|
|
402
|
+
},
|
|
403
|
+
feature_key: {
|
|
404
|
+
type: "string",
|
|
405
|
+
description: "Unique feature identifier (e.g. 'checkout_flow'). Symmetrically accepts 'feature'.",
|
|
406
|
+
},
|
|
407
|
+
domain: {
|
|
408
|
+
type: "string",
|
|
409
|
+
description: "Bounded-context domain for this feature (action='lock').",
|
|
410
|
+
},
|
|
411
|
+
description: {
|
|
412
|
+
type: "string",
|
|
413
|
+
description: "Scope and rationale for the feature (action='lock').",
|
|
414
|
+
},
|
|
415
|
+
allowed_touchpoints: {
|
|
416
|
+
type: "array",
|
|
417
|
+
items: { type: "string" },
|
|
418
|
+
description: "Permitted file paths or glob patterns (action='lock').",
|
|
419
|
+
},
|
|
420
|
+
reuse_symbols: {
|
|
421
|
+
type: "array",
|
|
422
|
+
items: { type: "string" },
|
|
423
|
+
description: "Mandatory reusable symbols (action='lock').",
|
|
424
|
+
},
|
|
425
|
+
input_contract: {
|
|
426
|
+
type: "object",
|
|
427
|
+
description: "Expected input payload / DTO schema (action='lock').",
|
|
428
|
+
},
|
|
429
|
+
output_contract: {
|
|
430
|
+
type: "object",
|
|
431
|
+
description: "Expected output response contract (action='lock').",
|
|
432
|
+
},
|
|
433
|
+
force: {
|
|
434
|
+
type: "boolean",
|
|
435
|
+
default: false,
|
|
436
|
+
description: "Force release session (action='release').",
|
|
437
|
+
},
|
|
438
|
+
workspace_path: {
|
|
439
|
+
type: "string",
|
|
440
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
required: [],
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
],
|
|
447
|
+
};
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
451
|
+
const { name, arguments: args } = request.params;
|
|
452
|
+
const startTime = performance.now();
|
|
453
|
+
let lease: WorkspaceLease | undefined;
|
|
454
|
+
try {
|
|
455
|
+
extra?.signal?.throwIfAborted();
|
|
456
|
+
const schema = TOOL_SCHEMAS[name as keyof typeof TOOL_SCHEMAS];
|
|
457
|
+
if (!schema) throw new Error(`Unknown tool: '${name}'`);
|
|
458
|
+
const validated = schema.safeParse(args ?? {});
|
|
459
|
+
if (!validated.success) throw new Error(`[Septum Validation Error] Invalid arguments for ${name}: ${validated.error.message}`);
|
|
460
|
+
const record = (validated.data ?? {}) as Record<string, any>;
|
|
461
|
+
const raw = (args ?? {}) as Record<string, any>;
|
|
462
|
+
const workspacePath = record.workspace_path ?? raw.workspace_path ?? raw.workspacePath ?? raw.workspace ?? raw.project_root ?? raw.projectRoot;
|
|
463
|
+
const knownRoots = manager.activeRoots;
|
|
464
|
+
if (manager.initialRoot && !knownRoots.includes(manager.initialRoot)) {
|
|
465
|
+
knownRoots.unshift(manager.initialRoot);
|
|
466
|
+
}
|
|
467
|
+
const fallbackRoot = manager.initialRoot || manager.lastRoot;
|
|
468
|
+
const root = resolveServerWorkspace({
|
|
469
|
+
workspacePath,
|
|
470
|
+
filePath: workspacePath ? undefined : extractPathHint(args),
|
|
471
|
+
fallbackRoot,
|
|
472
|
+
knownRoots,
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
if (!isWorkspaceInitialized(root)) {
|
|
476
|
+
if (name === "septum_domain" && (!record.action || record.action === "catalog")) {
|
|
477
|
+
const runtimeVersion = await checkRuntimeVersion();
|
|
478
|
+
let agentGuidance =
|
|
479
|
+
"Panggil tool 'septum_domain(action: \"register\", name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks domain utama secara otomatis, atau jalankan 'septum init' di terminal workspace.";
|
|
480
|
+
if (runtimeVersion.update_available) {
|
|
481
|
+
agentGuidance += ` Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`;
|
|
482
|
+
}
|
|
483
|
+
const diagnostic: Record<string, any> = {
|
|
484
|
+
status: "NOT_INDEXED",
|
|
485
|
+
total_domains: 0,
|
|
486
|
+
runtime_version: runtimeVersion,
|
|
487
|
+
message: `Workspace '${root}' belum diinisialisasi dengan Septum. Jalankan 'septum init' terlebih dahulu di terminal workspace.`,
|
|
488
|
+
suggested_action: {
|
|
489
|
+
tool: "septum_domain",
|
|
490
|
+
params: {
|
|
491
|
+
action: "register",
|
|
492
|
+
name: "core",
|
|
493
|
+
root: "src",
|
|
494
|
+
ingest_now: true,
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
agent_guidance: agentGuidance,
|
|
498
|
+
...(runtimeVersion.update_available
|
|
499
|
+
? {
|
|
500
|
+
agent_instruction: `Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`,
|
|
501
|
+
}
|
|
502
|
+
: {}),
|
|
503
|
+
};
|
|
504
|
+
return {
|
|
505
|
+
content: [
|
|
506
|
+
{
|
|
507
|
+
type: "text",
|
|
508
|
+
text: JSON.stringify(diagnostic, null, 2),
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
metadata: diagnostic,
|
|
512
|
+
runtime_version: runtimeVersion,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
const isRegistration = name === "septum_domain" && record.action === "register";
|
|
516
|
+
if (!isRegistration) {
|
|
517
|
+
return {
|
|
518
|
+
isError: true,
|
|
519
|
+
content: [
|
|
520
|
+
{
|
|
521
|
+
type: "text",
|
|
522
|
+
text: `[Septum MCP Error] Workspace '${root}' belum diinisialisasi. Jalankan 'septum init' di terminal workspace atau gunakan tool 'septum_domain' dengan action='register' untuk mendaftarkan domain.`,
|
|
523
|
+
},
|
|
524
|
+
],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
extra?.signal?.throwIfAborted();
|
|
530
|
+
lease = manager.acquire(root);
|
|
531
|
+
const ctx = lease.context;
|
|
532
|
+
await ctx.ready;
|
|
533
|
+
extra?.signal?.throwIfAborted();
|
|
534
|
+
await ctx.watcher.flush(true, extra?.signal);
|
|
535
|
+
if (ctx.repo.getMeta("sync_error")) throw new Error(`Workspace index synchronization failed: ${ctx.repo.getMeta("sync_error")}`);
|
|
536
|
+
ctx.config = ConfigLoader.load(undefined, ctx.root);
|
|
537
|
+
ctx.evaluator.getResolver().setRepository(ctx.repo);
|
|
538
|
+
|
|
539
|
+
let activeSession = null;
|
|
540
|
+
let sessionCorruptError: Error | null = null;
|
|
541
|
+
try {
|
|
542
|
+
activeSession = SessionManager.getActiveSession(ctx.root);
|
|
543
|
+
} catch (err: any) {
|
|
544
|
+
sessionCorruptError = err instanceof Error ? err : new Error(String(err));
|
|
545
|
+
}
|
|
546
|
+
const sessionPayload = activeSession
|
|
547
|
+
? { feature_key: activeSession.feature_key, domain: activeSession.domain }
|
|
548
|
+
: null;
|
|
549
|
+
|
|
550
|
+
const executeTool = async () => {
|
|
551
|
+
// 5 Unified Tools Handlers
|
|
552
|
+
if (name === "septum_domain") {
|
|
553
|
+
const parsed = DomainToolSchema.safeParse(args ?? {});
|
|
554
|
+
if (!parsed.success) {
|
|
555
|
+
return {
|
|
556
|
+
isError: true,
|
|
557
|
+
content: [
|
|
558
|
+
{
|
|
559
|
+
type: "text",
|
|
560
|
+
text: `[Septum Validation Error] Invalid arguments for ${name}: ${parsed.error.message}`,
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return await handleDomainTool(ctx.repo, ctx.config, parsed.data, ctx.root, extra?.signal);
|
|
566
|
+
} else if (name === "septum_symbol") {
|
|
567
|
+
const parsed = SymbolToolSchema.safeParse(args ?? {});
|
|
568
|
+
if (!parsed.success) {
|
|
569
|
+
return {
|
|
570
|
+
isError: true,
|
|
571
|
+
content: [
|
|
572
|
+
{
|
|
573
|
+
type: "text",
|
|
574
|
+
text: `[Septum Validation Error] Invalid arguments for ${name}: ${parsed.error.message}`,
|
|
575
|
+
},
|
|
576
|
+
],
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
return await handleSymbolTool(ctx.repo, ctx.config, parsed.data, ctx.pipeline, ctx.root);
|
|
580
|
+
} else if (name === "septum_slice") {
|
|
581
|
+
const parsed = SliceToolSchema.safeParse(args ?? {});
|
|
582
|
+
if (!parsed.success) {
|
|
583
|
+
return {
|
|
584
|
+
isError: true,
|
|
585
|
+
content: [
|
|
586
|
+
{
|
|
587
|
+
type: "text",
|
|
588
|
+
text: `[Septum Validation Error] Invalid arguments for ${name}: ${parsed.error.message}`,
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return handleSliceTool(ctx.repo, ctx.config, parsed.data, ctx.root, extra?.signal);
|
|
594
|
+
} else if (name === "septum_boundary") {
|
|
595
|
+
if (sessionCorruptError) {
|
|
596
|
+
return {
|
|
597
|
+
isError: true,
|
|
598
|
+
content: [
|
|
599
|
+
{
|
|
600
|
+
type: "text",
|
|
601
|
+
text: `[Septum Session Error] Active feature session in '.septum/session.json' is corrupted or invalid: ${sessionCorruptError.message}. Release it explicitly with 'septum_feature({action: "release", force: true})' before evaluating boundaries.`,
|
|
602
|
+
},
|
|
603
|
+
],
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
const parsed = BoundaryToolSchema.safeParse(args ?? {});
|
|
607
|
+
if (!parsed.success) {
|
|
608
|
+
return {
|
|
609
|
+
isError: true,
|
|
610
|
+
content: [
|
|
611
|
+
{
|
|
612
|
+
type: "text",
|
|
613
|
+
text: `[Septum Validation Error] Invalid arguments for ${name}: ${parsed.error.message}`,
|
|
614
|
+
},
|
|
615
|
+
],
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
return await handleBoundaryTool(ctx.evaluator, ctx.config, parsed.data, ctx.repo, ctx.root);
|
|
619
|
+
} else if (name === "septum_feature") {
|
|
620
|
+
const parsed = FeatureToolSchema.safeParse(args ?? {});
|
|
621
|
+
if (!parsed.success) {
|
|
622
|
+
return {
|
|
623
|
+
isError: true,
|
|
624
|
+
content: [
|
|
625
|
+
{
|
|
626
|
+
type: "text",
|
|
627
|
+
text: `[Septum Validation Error] Invalid arguments for ${name}: ${parsed.error.message}`,
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
if (sessionCorruptError && (parsed.data.action !== "release" || !parsed.data.force)) {
|
|
633
|
+
return {
|
|
634
|
+
isError: true,
|
|
635
|
+
content: [
|
|
636
|
+
{
|
|
637
|
+
type: "text",
|
|
638
|
+
text: `[Septum Session Error] Active feature session in '.septum/session.json' is corrupted or invalid: ${sessionCorruptError.message}. Release it explicitly with 'septum_feature({action: "release", force: true})'.`,
|
|
639
|
+
},
|
|
640
|
+
],
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
extra?.signal?.throwIfAborted();
|
|
644
|
+
return await handleFeatureTool(ctx.repo, ctx.config, parsed.data, ctx.root);
|
|
645
|
+
} else {
|
|
646
|
+
throw new Error(`Unknown tool: '${name}'`);
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
const response = await manager.runTool(executeTool, extra?.signal);
|
|
652
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
653
|
+
|
|
654
|
+
let bytesOut = 0;
|
|
655
|
+
let linesOut = 0;
|
|
656
|
+
if (Array.isArray(response?.content)) {
|
|
657
|
+
for (const item of response.content) {
|
|
658
|
+
if (typeof item.text === "string") {
|
|
659
|
+
bytesOut += Buffer.byteLength(item.text, "utf8");
|
|
660
|
+
linesOut += countLines(item.text);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
SeptumTelemetry.recordToolCall({
|
|
666
|
+
event: "tool_call_completed",
|
|
667
|
+
tool: name,
|
|
668
|
+
duration_ms: durationMs,
|
|
669
|
+
input: (args as Record<string, any>) ?? {},
|
|
670
|
+
metrics: { bytes_out: bytesOut, lines_out: linesOut },
|
|
671
|
+
session: sessionPayload,
|
|
672
|
+
status: (response as { isError?: boolean } | undefined)?.isError ? "error" : "success",
|
|
673
|
+
}, ctx.root);
|
|
674
|
+
|
|
675
|
+
return response;
|
|
676
|
+
} catch (err) {
|
|
677
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
678
|
+
const errorInstance = err instanceof Error ? err : new Error(String(err));
|
|
679
|
+
|
|
680
|
+
SeptumTelemetry.recordToolCall({
|
|
681
|
+
event: "tool_call_failed",
|
|
682
|
+
tool: name,
|
|
683
|
+
duration_ms: durationMs,
|
|
684
|
+
input: (args as Record<string, any>) ?? {},
|
|
685
|
+
session: sessionPayload,
|
|
686
|
+
status: "error",
|
|
687
|
+
error: {
|
|
688
|
+
message: errorInstance.message,
|
|
689
|
+
stack: errorInstance.stack,
|
|
690
|
+
},
|
|
691
|
+
}, ctx.root);
|
|
692
|
+
|
|
693
|
+
return {
|
|
694
|
+
isError: true,
|
|
695
|
+
content: [
|
|
696
|
+
{
|
|
697
|
+
type: "text",
|
|
698
|
+
text: `[Septum MCP Error] ${errorInstance.message}`,
|
|
699
|
+
},
|
|
700
|
+
],
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
} catch (error) {
|
|
704
|
+
return {isError: true, content: [{type: "text" as const, text: `[Septum MCP Error] ${error instanceof Error ? error.message : String(error)}`}]};
|
|
705
|
+
} finally { lease?.release(); }
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
const transport = new StdioServerTransport();
|
|
709
|
+
|
|
710
|
+
let stopping = false;
|
|
711
|
+
let memoryTimer: ReturnType<typeof setInterval> | undefined;
|
|
712
|
+
const cleanup = () => {
|
|
713
|
+
if (stopping) return;
|
|
714
|
+
stopping = true;
|
|
715
|
+
if (memoryTimer) clearInterval(memoryTimer);
|
|
716
|
+
const deadline = setTimeout(() => {
|
|
717
|
+
console.error("[Septum MCP] Shutdown deadline exceeded; indexing may require reconciliation.");
|
|
718
|
+
process.exit(1);
|
|
719
|
+
}, RESOURCE_LIMITS.shutdownMs);
|
|
720
|
+
void (async () => {
|
|
721
|
+
try {
|
|
722
|
+
await server.close();
|
|
723
|
+
await manager.close();
|
|
724
|
+
clearTimeout(deadline);
|
|
725
|
+
console.error("[Septum MCP] All workspace resources closed cleanly.");
|
|
726
|
+
process.exit(0);
|
|
727
|
+
} catch (error) {
|
|
728
|
+
console.error(`[Septum MCP] Cleanup failed: ${String(error)}`);
|
|
729
|
+
clearTimeout(deadline);
|
|
730
|
+
process.exit(1);
|
|
731
|
+
}
|
|
732
|
+
})();
|
|
733
|
+
};
|
|
734
|
+
process.once("SIGINT", cleanup);
|
|
735
|
+
process.once("SIGTERM", cleanup);
|
|
736
|
+
process.stdin.once("end", cleanup);
|
|
737
|
+
process.stdin.once("close", cleanup);
|
|
738
|
+
server.onclose = cleanup;
|
|
739
|
+
await server.connect(transport);
|
|
740
|
+
try {
|
|
741
|
+
const initialRoot = resolveServerWorkspace({initial:true});
|
|
742
|
+
manager.initialRoot = initialRoot;
|
|
743
|
+
manager.lastRoot = initialRoot;
|
|
744
|
+
if (isWorkspaceInitialized(initialRoot)) {
|
|
745
|
+
const initial = manager.acquire(initialRoot);
|
|
746
|
+
try { await initial.context.ready; } finally { initial.release(); }
|
|
747
|
+
}
|
|
748
|
+
if (process.env.SEPTUM_MEMORY_DIAGNOSTICS === "1") {
|
|
749
|
+
memoryTimer = setInterval(() => {
|
|
750
|
+
const sample = { ...process.memoryUsage(), workspaces: manager.size, watches: manager.watchCount, pending_paths: manager.pendingPaths, sync_duration_ms: manager.syncDurationMs };
|
|
751
|
+
if (manager.lastRoot && isWorkspaceInitialized(manager.lastRoot)) {
|
|
752
|
+
SeptumTelemetry.recordMemorySample(sample, manager.lastRoot);
|
|
753
|
+
} else {
|
|
754
|
+
console.error(`[Septum Memory] ${JSON.stringify({timestamp: new Date().toISOString(), event: "memory_sample", metrics: sample})}`);
|
|
755
|
+
}
|
|
756
|
+
}, 60_000);
|
|
757
|
+
memoryTimer.unref();
|
|
758
|
+
}
|
|
759
|
+
} catch (error) {
|
|
760
|
+
await manager.close();
|
|
761
|
+
throw error;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
if (process.stdin.isTTY) {
|
|
765
|
+
console.error(
|
|
766
|
+
`\x1b[36m[Septum MCP]\x1b[0m Server daemon running on stdio (PID: ${process.pid}, v${SEPTUM_VERSION}).`
|
|
767
|
+
);
|
|
768
|
+
console.error(
|
|
769
|
+
`\x1b[36m[Septum MCP]\x1b[0m Listening for JSON-RPC client messages. Press Ctrl+C to terminate.`
|
|
770
|
+
);
|
|
771
|
+
} else {
|
|
772
|
+
console.error(`[Septum MCP] Server started successfully on stdio transport (v${SEPTUM_VERSION}).`);
|
|
773
|
+
}
|
|
774
|
+
}
|