@dimassetoid/septum-mcp 0.0.0-stage → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +142 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +133 -0
- package/src/cli/commands/hook.ts +205 -0
- package/src/cli/commands/init.ts +570 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +39 -0
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +124 -0
- package/src/cli/scaffold/harness-config.ts +661 -0
- package/src/cli/templates/hooks.ts +110 -0
- package/src/cli/templates/rules.ts +35 -0
- package/src/cli/templates/skill.ts +55 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +426 -0
- package/src/core/boundary/staged-auditor.ts +120 -0
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +174 -0
- package/src/core/config/schema.ts +59 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +733 -0
- package/src/core/database/repositories/domain.repository.ts +373 -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 +647 -0
- package/src/core/database/repository.ts +358 -0
- package/src/core/database/schema.ts +123 -0
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +863 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +590 -0
- package/src/core/parser/behavioral-analyzer.ts +123 -0
- package/src/core/parser/boundary-tracker.ts +458 -0
- package/src/core/parser/extractors/base.ts +71 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +248 -0
- package/src/core/parser/extractors/django-semantic.ts +655 -0
- package/src/core/parser/extractors/elysia-semantic.ts +517 -0
- package/src/core/parser/extractors/express-semantic.ts +429 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +702 -0
- package/src/core/parser/extractors/fastify-semantic.ts +759 -0
- package/src/core/parser/extractors/flask-semantic.ts +482 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +670 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +546 -0
- package/src/core/parser/extractors/java.ts +227 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1150 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +367 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +527 -0
- package/src/core/parser/extractors/php.ts +585 -0
- package/src/core/parser/extractors/python.ts +503 -0
- package/src/core/parser/extractors/registry.ts +99 -0
- package/src/core/parser/extractors/ruby.ts +237 -0
- package/src/core/parser/extractors/rust.ts +304 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +24 -0
- package/src/core/parser/extractors/symfony-semantic.ts +321 -0
- package/src/core/parser/extractors/typescript.ts +839 -0
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +87 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +239 -0
- package/src/core/parser/schema/schema-provider-registry.ts +41 -0
- package/src/core/parser/schema/schema-provider.interface.ts +34 -0
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -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 +1033 -0
- package/src/core/resolver/import-resolver.ts +365 -0
- package/src/core/resolver/interpretation-inputs.ts +7 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +115 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +71 -0
- package/src/core/resolver/module-resolver.ts +486 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -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 +344 -0
- package/src/core/resources/ignore.ts +144 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +185 -0
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +142 -0
- package/src/index.ts +18 -0
- package/src/mcp/schemas.ts +746 -0
- package/src/mcp/server.ts +600 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +382 -0
- package/src/mcp/tools/get-domain-catalog.ts +39 -0
- package/src/mcp/tools/get-symbol-impact.ts +104 -0
- package/src/mcp/tools/get-symbol.ts +399 -0
- package/src/mcp/tools/locate-symbol.ts +236 -0
- package/src/mcp/tools/map.ts +26 -0
- package/src/mcp/tools/register-domain.ts +113 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +95 -0
- package/src/mcp/tools/trace-vertical-slice.ts +106 -0
- package/src/mcp/workspace-manager.ts +170 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +438 -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,600 @@
|
|
|
1
|
+
import { buildUnindexedCatalog } from "./tools/get-domain-catalog.ts";
|
|
2
|
+
import { WorkspaceManager, resolveServerWorkspace, isWorkspaceInitialized, type WorkspaceLease } from "./workspace-manager.ts";
|
|
3
|
+
import { RESOURCE_LIMITS } from "../core/resources/limits.ts";
|
|
4
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import {
|
|
7
|
+
CallToolRequestSchema,
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import { ConfigLoader } from "../core/config/loader.ts";
|
|
11
|
+
import { SeptumTelemetry } from "../core/telemetry/telemetry.ts";
|
|
12
|
+
import { handleMapTool } from "./tools/map.ts";
|
|
13
|
+
import { handleSymbolTool } from "./tools/symbol.ts";
|
|
14
|
+
import { handleSliceTool } from "./tools/slice.ts";
|
|
15
|
+
import { handleBoundaryTool } from "./tools/boundary.ts";
|
|
16
|
+
import { DomainRootConflictError } from "../core/config/domain-ownership.ts";
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
parseToolRequest,
|
|
20
|
+
} from "./schemas.ts";
|
|
21
|
+
import { SEPTUM_VERSION, checkRuntimeVersion } from "../utils/version-check.ts";
|
|
22
|
+
|
|
23
|
+
export function extractPathHint(args: unknown): string | undefined {
|
|
24
|
+
if (!args) return undefined;
|
|
25
|
+
|
|
26
|
+
if (typeof args === "string") {
|
|
27
|
+
const trimmed = args.trim();
|
|
28
|
+
if (trimmed.length > 0) return trimmed;
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(args)) {
|
|
33
|
+
if (typeof args[0] === "string" && args[0].trim()) {
|
|
34
|
+
return args[0].trim();
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof args === "object" && args !== null) {
|
|
40
|
+
const record = args as Record<string, any>;
|
|
41
|
+
|
|
42
|
+
const explicitWorkspace =
|
|
43
|
+
record.workspace_path ??
|
|
44
|
+
record.workspacePath ??
|
|
45
|
+
record.workspace ??
|
|
46
|
+
record.project_root ??
|
|
47
|
+
record.projectRoot ??
|
|
48
|
+
record.target_path ??
|
|
49
|
+
record.targetPath;
|
|
50
|
+
if (typeof explicitWorkspace === "string" && explicitWorkspace.trim()) {
|
|
51
|
+
return explicitWorkspace.trim();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const filePath =
|
|
55
|
+
record.file_path ??
|
|
56
|
+
record.filePath ??
|
|
57
|
+
record.from_file ??
|
|
58
|
+
record.fromFile ??
|
|
59
|
+
record.source_file ??
|
|
60
|
+
record.sourceFile ??
|
|
61
|
+
record.entry_file ??
|
|
62
|
+
record.entryFile;
|
|
63
|
+
if (typeof filePath === "string" && filePath.trim()) {
|
|
64
|
+
return filePath.trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const filePaths =
|
|
68
|
+
record.file_paths ??
|
|
69
|
+
record.filePaths ??
|
|
70
|
+
record.files ??
|
|
71
|
+
record.paths;
|
|
72
|
+
if (Array.isArray(filePaths) && typeof filePaths[0] === "string" && filePaths[0].trim()) {
|
|
73
|
+
return filePaths[0].trim();
|
|
74
|
+
}
|
|
75
|
+
if (typeof filePaths === "string" && filePaths.trim()) {
|
|
76
|
+
return filePaths.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
!record.domain &&
|
|
81
|
+
!record.name &&
|
|
82
|
+
!record.domain_name &&
|
|
83
|
+
!record.domainName &&
|
|
84
|
+
typeof record.root === "string" &&
|
|
85
|
+
record.root.trim()
|
|
86
|
+
) {
|
|
87
|
+
return record.root.trim();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function countLines(text: string): number {
|
|
95
|
+
let count = 1;
|
|
96
|
+
for (let i = 0; i < text.length; i++) {
|
|
97
|
+
if (text.charCodeAt(i) === 10) count++;
|
|
98
|
+
}
|
|
99
|
+
return count;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const SEPTUM_SERVER_INSTRUCTIONS = `Septum indexes supported declarations, imports, domain policies and static entrypoints.
|
|
103
|
+
Guidelines for AI Coding Agents:
|
|
104
|
+
1. CONTEXT: Call septum_symbol(action: 'context') for declaration source and supporting references. Deep TypeScript context uses budget_bytes and continuation; source inspection uses line limits. Read freshness, diagnostics and omissions, then inspect further source when needed.
|
|
105
|
+
2. NAVIGATION: Call septum_map(action: 'catalog') for domain/file locations, import relationships, static entrypoints and index health.
|
|
106
|
+
3. CONSUMERS: Before changing public contracts, inspect septum_symbol(action: 'impact') and relevant consumers. Import dependents and caller hints are incomplete static evidence; verify affected application behavior.
|
|
107
|
+
4. ENTRYPOINTS: Call septum_slice(query: '<route|handler>') for catalog matches and related nodes. Matching confidence does not establish runtime reachability or execution order.
|
|
108
|
+
5. BOUNDARIES: Call septum_boundary(scope: 'file', file_path: '...', proposed_imports: [...]) for candidate imports, or scope: 'all'/'domain'/'staged' for those audit scopes. Proposal approval does not audit existing imports. Unknown is not approval; approved describes only the evaluated static scope.`;
|
|
109
|
+
|
|
110
|
+
export async function runMCPServer(): Promise<void> {
|
|
111
|
+
const manager = new WorkspaceManager();
|
|
112
|
+
void checkRuntimeVersion().catch(() => {});
|
|
113
|
+
|
|
114
|
+
const server = new Server(
|
|
115
|
+
{
|
|
116
|
+
name: "septum-mcp-server",
|
|
117
|
+
version: SEPTUM_VERSION,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
capabilities: {
|
|
121
|
+
tools: {},
|
|
122
|
+
},
|
|
123
|
+
instructions: SEPTUM_SERVER_INSTRUCTIONS,
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
128
|
+
return {
|
|
129
|
+
tools: [
|
|
130
|
+
{
|
|
131
|
+
name: "septum_map",
|
|
132
|
+
description:
|
|
133
|
+
"Navigate architecture: workspace domains and cross-domain import adjacency, domain/file neighborhoods, static entrypoints and coverage. Output schema navigation/v1. Signatures, member lists and source belong to septum_symbol; full expands navigation only. Use file_filter to focus, include_evidence for one file's import details, or septum_slice for static handler relationships. Example: {action:'catalog',domain:'mcp'}.",
|
|
134
|
+
inputSchema: {
|
|
135
|
+
type: "object",
|
|
136
|
+
properties: {
|
|
137
|
+
action: {
|
|
138
|
+
type: "string",
|
|
139
|
+
enum: ["catalog", "register"],
|
|
140
|
+
default: "catalog",
|
|
141
|
+
description: "Sub-operation to execute: 'catalog' (inspect domain/macro map) or 'register' (dynamically register bounded-context domain).",
|
|
142
|
+
},
|
|
143
|
+
domain: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description: "Target domain name (e.g. 'orders', 'core'). If omitted in catalog action, returns project-wide Macro Semantic Map.",
|
|
146
|
+
},
|
|
147
|
+
detail_level: {
|
|
148
|
+
type: "string",
|
|
149
|
+
enum: ["compact", "full"],
|
|
150
|
+
default: "compact",
|
|
151
|
+
description: "Navigation extent: compact selects up to 40 files, full up to 100. Neither includes signatures or source; use septum_symbol for declaration inspection.",
|
|
152
|
+
},
|
|
153
|
+
archetype_filter: {
|
|
154
|
+
type: "string",
|
|
155
|
+
description: "Optional archetype filter (e.g. 'service', 'model', 'controller', 'repository').",
|
|
156
|
+
},
|
|
157
|
+
file_filter: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Optional substring filter to inspect specific file(s) within the domain.",
|
|
160
|
+
},
|
|
161
|
+
file_offset: { type: "integer", minimum: 0, description: "Start of the catalog file page; copy next_file_offset from pagination." },
|
|
162
|
+
file_limit: { type: "integer", minimum: 1, maximum: 100, description: "Optional navigation selection limit. Small scopes return together; pagination appears only when files remain." },
|
|
163
|
+
include_evidence: { type: "boolean", description: "Opt in to up to 20 raw import-evidence records; requires file_filter matching exactly one file." },
|
|
164
|
+
include_capabilities: { type: "boolean", description: "Opt in to language/parser capabilities; omitted from navigation by default." },
|
|
165
|
+
root: {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: "Root directory path for domain registration (action='register').",
|
|
168
|
+
},
|
|
169
|
+
description: {
|
|
170
|
+
type: "string",
|
|
171
|
+
description: "Architectural purpose of the domain (action='register').",
|
|
172
|
+
},
|
|
173
|
+
allowed_dependencies: {
|
|
174
|
+
type: "array",
|
|
175
|
+
items: { type: "string" },
|
|
176
|
+
description: "List of domain names this domain is allowed to import (action='register').",
|
|
177
|
+
},
|
|
178
|
+
forbidden_dependencies: {
|
|
179
|
+
type: "array",
|
|
180
|
+
items: { type: "string" },
|
|
181
|
+
description: "List of domain names strictly forbidden from being imported (action='register').",
|
|
182
|
+
},
|
|
183
|
+
archetypes: {
|
|
184
|
+
type: "object",
|
|
185
|
+
description: "Layer archetypes mapping (action='register').",
|
|
186
|
+
},
|
|
187
|
+
ingest_now: {
|
|
188
|
+
type: "boolean",
|
|
189
|
+
default: false,
|
|
190
|
+
description: "Whether to immediately run AST ingestion on domain files upon registration.",
|
|
191
|
+
},
|
|
192
|
+
workspace_path: {
|
|
193
|
+
type: "string",
|
|
194
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
required: [],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "septum_symbol",
|
|
202
|
+
description:
|
|
203
|
+
"Locate indexed declarations, retrieve source/contracts, or inspect potential consumers. action='context' (alias 'inspect') selects deep TypeScript references or bounded source inspection; read mode, freshness, diagnostics and omissions. action='impact' separates import dependents from supported static call sites and inferred caller hints; the caller set is incomplete. Use septum_map for domain/file navigation and septum_slice for static entrypoint context. Example: {action:'context',query:'handleOrder',file_path:'src/orders.ts'}.",
|
|
204
|
+
inputSchema: {
|
|
205
|
+
type: "object",
|
|
206
|
+
properties: {
|
|
207
|
+
action: {
|
|
208
|
+
type: "string",
|
|
209
|
+
enum: ["locate", "context", "inspect", "impact"],
|
|
210
|
+
default: "locate",
|
|
211
|
+
description: "'locate' finds declarations; 'context' (or 'inspect') retrieves declaration source along with local/import-bound supporting declarations for TypeScript within budget_bytes, or bounded source for polyglot files; 'impact' reports static caller hints. Example: {action:'context',query:'submit',file_path:'src/submit.ts'}.",
|
|
212
|
+
},
|
|
213
|
+
query: {
|
|
214
|
+
type: "string",
|
|
215
|
+
description: "Symbol name, call syntax (e.g. 'OrderController::cancelOrder'), or search query.",
|
|
216
|
+
},
|
|
217
|
+
domain: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "Optional domain filter (e.g. 'orders').",
|
|
220
|
+
},
|
|
221
|
+
file_path: {
|
|
222
|
+
type: "string",
|
|
223
|
+
description: "Exact indexed repository-relative file path. Use it to select one candidate when names are ambiguous.",
|
|
224
|
+
},
|
|
225
|
+
symbol_ref: {
|
|
226
|
+
type: "object",
|
|
227
|
+
description: "Declaration reference returned by locate or catalog. Stale indexed fingerprints are refused.",
|
|
228
|
+
properties: {
|
|
229
|
+
file_path: { type: "string", minLength: 1 },
|
|
230
|
+
language: { type: "string", minLength: 1 },
|
|
231
|
+
name: { type: "string", minLength: 1 },
|
|
232
|
+
kind: { type: "string", minLength: 1 },
|
|
233
|
+
signature: { type: "string" },
|
|
234
|
+
start_line: { type: "integer", minimum: 1 },
|
|
235
|
+
end_line: { type: "integer", minimum: 1 },
|
|
236
|
+
indexed_content_hash: { type: "string", minLength: 1 },
|
|
237
|
+
container: { type: "string" },
|
|
238
|
+
receiver: { type: "string" },
|
|
239
|
+
},
|
|
240
|
+
required: ["file_path", "language", "name", "kind", "signature", "start_line", "end_line", "indexed_content_hash"],
|
|
241
|
+
},
|
|
242
|
+
include_source: {
|
|
243
|
+
type: "boolean",
|
|
244
|
+
description: "Explicit true selects bounded source; explicit false selects declaration details without source. Omit for deep TypeScript context or default polyglot source. Source hashes must match disk.",
|
|
245
|
+
},
|
|
246
|
+
source_start_line: {
|
|
247
|
+
type: "number",
|
|
248
|
+
minimum: 1,
|
|
249
|
+
description: "First line to return within the selected symbol range.",
|
|
250
|
+
},
|
|
251
|
+
source_line_limit: {
|
|
252
|
+
type: "number",
|
|
253
|
+
minimum: 1,
|
|
254
|
+
maximum: 200,
|
|
255
|
+
description: "Select bounded source inspection with this line limit (capped at 200). Bounded mode uses 120 lines when omitted.",
|
|
256
|
+
},
|
|
257
|
+
context_mode: {
|
|
258
|
+
type: "string", enum: ["deep", "source"],
|
|
259
|
+
description: "Explicit context mode. deep selects referenced TypeScript declarations; source selects bounded source inspection. Omit for legacy automatic selection.",
|
|
260
|
+
},
|
|
261
|
+
include_dependencies: {
|
|
262
|
+
type: "boolean",
|
|
263
|
+
default: true,
|
|
264
|
+
description: "Whether to include injected dependencies and outbound calls.",
|
|
265
|
+
},
|
|
266
|
+
budget_bytes: {
|
|
267
|
+
type: "integer",
|
|
268
|
+
minimum: 2048,
|
|
269
|
+
maximum: 2097152,
|
|
270
|
+
default: 16384,
|
|
271
|
+
description: "For deep TypeScript context (including inspect alias): maximum UTF-8 bytes of the serialized MCP tool result, including evidence and continuation. Do not combine with bounded source options.",
|
|
272
|
+
},
|
|
273
|
+
continuation: {
|
|
274
|
+
type: "string",
|
|
275
|
+
minLength: 1,
|
|
276
|
+
maxLength: 4096,
|
|
277
|
+
description: "For action='context': copy the previous page token with the same target and budget.",
|
|
278
|
+
},
|
|
279
|
+
limit: {
|
|
280
|
+
type: "number",
|
|
281
|
+
description: "Maximum results to return for locate (default: 10).",
|
|
282
|
+
},
|
|
283
|
+
workspace_path: {
|
|
284
|
+
type: "string",
|
|
285
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
required: [],
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "septum_slice",
|
|
293
|
+
description:
|
|
294
|
+
"Match a supported static entrypoint and inspect related nodes with relationship evidence and diagnostics. Supports cataloged routes, handlers, jobs, CLI commands and events; results do not establish runtime execution order or complete reachability. Use septum_symbol for declarations and septum_boundary for import policy. Example: {query:'POST /orders/{id}/pay',max_depth:5} or {query:'OrderController@pay'}.",
|
|
295
|
+
inputSchema: {
|
|
296
|
+
type: "object",
|
|
297
|
+
properties: {
|
|
298
|
+
query: {
|
|
299
|
+
type: "string",
|
|
300
|
+
description: "Route URI (e.g. 'POST /orders/{id}/pay'), action (e.g. 'OrderController@pay'), or high-level task intent.",
|
|
301
|
+
},
|
|
302
|
+
controller_file: {
|
|
303
|
+
type: "string",
|
|
304
|
+
minLength: 1,
|
|
305
|
+
description: "Exact catalog controller/handler file copied from an ambiguity candidate. Filters target selection.",
|
|
306
|
+
},
|
|
307
|
+
max_depth: {
|
|
308
|
+
type: "number",
|
|
309
|
+
default: 5,
|
|
310
|
+
minimum: 1,
|
|
311
|
+
maximum: 8,
|
|
312
|
+
description: "Maximum depth to trace (default: 5, min: 1, max: 8). Use 6-8 for deep Event/Job/Queue traces.",
|
|
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: ["query"],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "septum_boundary",
|
|
324
|
+
description:
|
|
325
|
+
"Architectural firewall: validate proposed or staged imports against domain boundaries and circular dependency constraints. When to use: (1) scope='file' with proposed_imports BEFORE writing new import statements, (2) scope='staged' BEFORE git commit to prevent cross-domain leaks, (3) scope='all' or 'domain' for codebase audits. When NOT to use: do NOT use to read source code or locate symbols. Status 'approved' confirms zero violations; 'rejected' requires refactoring. Example: {scope:'file',file_path:'src/order/service.ts',proposed_imports:['../billing/repo']}.",
|
|
326
|
+
inputSchema: {
|
|
327
|
+
type: "object",
|
|
328
|
+
properties: {
|
|
329
|
+
scope: {
|
|
330
|
+
type: "string",
|
|
331
|
+
enum: ["file", "staged", "all", "domain"],
|
|
332
|
+
default: "file",
|
|
333
|
+
description: "'file' evaluates proposed imports against domain policies; 'staged' audits git index changes; 'domain' checks a specific domain's violations; 'all' audits the entire workspace.",
|
|
334
|
+
},
|
|
335
|
+
file_path: {
|
|
336
|
+
type: "string",
|
|
337
|
+
description: "Path of the file being edited or created (scope='file' only). Use either file_path or file_paths.",
|
|
338
|
+
},
|
|
339
|
+
file_paths: {
|
|
340
|
+
type: "array",
|
|
341
|
+
items: { type: "string" },
|
|
342
|
+
description: "Non-empty list of file paths for batch proposed-import checks (scope='file' only).",
|
|
343
|
+
},
|
|
344
|
+
proposed_imports: {
|
|
345
|
+
type: "array",
|
|
346
|
+
items: { type: "string" },
|
|
347
|
+
description: "List of proposed import statements or target symbols (scope='file' only).",
|
|
348
|
+
},
|
|
349
|
+
domain: {
|
|
350
|
+
type: "string",
|
|
351
|
+
description: "Registered domain name, required for scope='domain'; optional for staged/file checks.",
|
|
352
|
+
},
|
|
353
|
+
staged: {
|
|
354
|
+
type: "boolean",
|
|
355
|
+
description: "Convenience flag equivalent to scope='staged'.",
|
|
356
|
+
},
|
|
357
|
+
workspace_path: {
|
|
358
|
+
type: "string",
|
|
359
|
+
description: "Explicit workspace root path. Specifies the target project root in multi-root environments.",
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
required: [],
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
370
|
+
const { name, arguments: args } = request.params;
|
|
371
|
+
const startTime = performance.now();
|
|
372
|
+
let lease: WorkspaceLease | undefined;
|
|
373
|
+
try {
|
|
374
|
+
extra?.signal?.throwIfAborted();
|
|
375
|
+
let parsed;
|
|
376
|
+
try { parsed = parseToolRequest(name, args); }
|
|
377
|
+
catch (error) { throw new Error(`[Septum Validation Error] Invalid arguments for ${name}: ${error instanceof Error ? error.message : String(error)}`); }
|
|
378
|
+
const record = parsed.args;
|
|
379
|
+
const raw = (args ?? {}) as Record<string, any>;
|
|
380
|
+
const workspacePath = record.workspace_path ?? raw.workspace_path ?? raw.workspacePath ?? raw.workspace ?? raw.project_root ?? raw.projectRoot;
|
|
381
|
+
const knownRoots = manager.activeRoots;
|
|
382
|
+
if (manager.initialRoot && !knownRoots.includes(manager.initialRoot)) {
|
|
383
|
+
knownRoots.unshift(manager.initialRoot);
|
|
384
|
+
}
|
|
385
|
+
const fallbackRoot = manager.initialRoot || manager.lastRoot;
|
|
386
|
+
const root = resolveServerWorkspace({
|
|
387
|
+
workspacePath,
|
|
388
|
+
filePath: workspacePath ? undefined : extractPathHint(args),
|
|
389
|
+
fallbackRoot,
|
|
390
|
+
knownRoots,
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
if (!isWorkspaceInitialized(root)) {
|
|
394
|
+
if (name === "septum_map" && (!("action" in record) || !record.action || record.action === "catalog")) {
|
|
395
|
+
const runtimeVersion = await checkRuntimeVersion();
|
|
396
|
+
const diagnostic = buildUnindexedCatalog(root, runtimeVersion);
|
|
397
|
+
return {
|
|
398
|
+
content: [
|
|
399
|
+
{
|
|
400
|
+
type: "text",
|
|
401
|
+
text: JSON.stringify(diagnostic, null, 2),
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
metadata: diagnostic,
|
|
405
|
+
runtime_version: runtimeVersion,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
const isRegistration = name === "septum_map" && "action" in record && record.action === "register";
|
|
409
|
+
if (!isRegistration) {
|
|
410
|
+
return {
|
|
411
|
+
isError: true,
|
|
412
|
+
content: [
|
|
413
|
+
{
|
|
414
|
+
type: "text",
|
|
415
|
+
text: `[Septum MCP Error] Workspace '${root}' belum diinisialisasi. Jalankan 'septum init' di terminal workspace atau gunakan tool 'septum_map' dengan action='register' untuk mendaftarkan domain.`,
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
extra?.signal?.throwIfAborted();
|
|
423
|
+
const isDomainRegistration = parsed.name === "septum_map" && parsed.args.action === "register";
|
|
424
|
+
lease = manager.acquire(root, { deferDiscovery: isDomainRegistration });
|
|
425
|
+
const ctx = lease.context;
|
|
426
|
+
await ctx.ready;
|
|
427
|
+
extra?.signal?.throwIfAborted();
|
|
428
|
+
const registrationBeforeDiscovery = isDomainRegistration && Object.keys(ctx.config.domains).length === 0 && ctx.repo.getAllDomains().length === 0;
|
|
429
|
+
try { if (!registrationBeforeDiscovery) await ctx.watcher.flush(false, extra?.signal); }
|
|
430
|
+
catch (error) { if (!isDomainRegistration || !(error instanceof DomainRootConflictError)) throw error; }
|
|
431
|
+
if (ctx.repo.getMeta("sync_error") && !(isDomainRegistration && ctx.repo.getMeta("sync_error_code") === "DOMAIN_ROOT_CONFLICT")) {
|
|
432
|
+
throw new Error(`Workspace index synchronization failed: ${ctx.repo.getMeta("sync_error")}`);
|
|
433
|
+
}
|
|
434
|
+
ctx.config = ConfigLoader.load(undefined, ctx.root);
|
|
435
|
+
// External policy writes do not emit source watcher events. Keep this cheap
|
|
436
|
+
// ownership gate independent of full reconciliation and target JIT refresh.
|
|
437
|
+
if (!isDomainRegistration) ctx.pipeline.assertDomainOwnership(ctx.config, ctx.root);
|
|
438
|
+
ctx.evaluator.getResolver().setRepository(ctx.repo);
|
|
439
|
+
|
|
440
|
+
const executeTool = async () => {
|
|
441
|
+
switch (parsed.name) {
|
|
442
|
+
case "septum_map": return handleMapTool(ctx.repo, ctx.config, parsed.args, ctx.root, extra?.signal);
|
|
443
|
+
case "septum_symbol": return handleSymbolTool(ctx.repo, ctx.config, parsed.args, ctx.pipeline, ctx.root, extra?.signal);
|
|
444
|
+
case "septum_slice": return handleSliceTool(ctx.repo, ctx.config, parsed.args, ctx.root, extra?.signal);
|
|
445
|
+
case "septum_boundary": return handleBoundaryTool(ctx.evaluator, ctx.config, parsed.args, ctx.repo, ctx.root);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
const response = await manager.runTool(executeTool, extra?.signal);
|
|
451
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
452
|
+
|
|
453
|
+
let bytesOut = 0;
|
|
454
|
+
let linesOut = 0;
|
|
455
|
+
let combinedText = "";
|
|
456
|
+
if (Array.isArray(response?.content)) {
|
|
457
|
+
for (const item of response.content) {
|
|
458
|
+
if (typeof item.text === "string") {
|
|
459
|
+
bytesOut += Buffer.byteLength(item.text, "utf8");
|
|
460
|
+
linesOut += countLines(item.text);
|
|
461
|
+
if (combinedText.length < 1500) {
|
|
462
|
+
combinedText += item.text;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const inputArgs = (args as Record<string, any>) ?? {};
|
|
469
|
+
const actionName = typeof inputArgs.action === "string" ? inputArgs.action : (typeof inputArgs.scope === "string" ? inputArgs.scope : undefined);
|
|
470
|
+
const estimatedTokens = Math.round(bytesOut / 4);
|
|
471
|
+
const bloatAlert = bytesOut >= SeptumTelemetry.BLOAT_BYTE_THRESHOLD;
|
|
472
|
+
const outputDigest = SeptumTelemetry.createOutputDigest(combinedText);
|
|
473
|
+
let outcome: string | undefined;
|
|
474
|
+
try {
|
|
475
|
+
const payload = JSON.parse(combinedText);
|
|
476
|
+
const candidate = payload.status ?? (payload.found === false ? "not_found" : undefined);
|
|
477
|
+
if (["success", "partial", "unknown", "approved", "rejected", "ambiguous", "not_found", "NOT_INDEXED", "stale_reference", "invalid_context_options", "budget_too_small"].includes(candidate)) outcome = candidate;
|
|
478
|
+
} catch { /* Non-JSON results retain transport status only. */ }
|
|
479
|
+
|
|
480
|
+
SeptumTelemetry.recordToolCall({
|
|
481
|
+
event: "tool_call_completed",
|
|
482
|
+
tool: name,
|
|
483
|
+
action: actionName,
|
|
484
|
+
duration_ms: durationMs,
|
|
485
|
+
input: inputArgs,
|
|
486
|
+
metrics: {
|
|
487
|
+
bytes_out: bytesOut,
|
|
488
|
+
lines_out: linesOut,
|
|
489
|
+
estimated_tokens: estimatedTokens,
|
|
490
|
+
},
|
|
491
|
+
bloat_alert: bloatAlert,
|
|
492
|
+
output_digest: outputDigest,
|
|
493
|
+
outcome,
|
|
494
|
+
session: null,
|
|
495
|
+
status: (response as { isError?: boolean } | undefined)?.isError ? "error" : "success",
|
|
496
|
+
}, ctx.root);
|
|
497
|
+
|
|
498
|
+
return response;
|
|
499
|
+
} catch (err) {
|
|
500
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
501
|
+
const errorInstance = err instanceof Error ? err : new Error(String(err));
|
|
502
|
+
const inputArgs = (args as Record<string, any>) ?? {};
|
|
503
|
+
const actionName = typeof inputArgs.action === "string" ? inputArgs.action : (typeof inputArgs.scope === "string" ? inputArgs.scope : undefined);
|
|
504
|
+
|
|
505
|
+
SeptumTelemetry.recordToolCall({
|
|
506
|
+
event: "tool_call_failed",
|
|
507
|
+
tool: name,
|
|
508
|
+
action: actionName,
|
|
509
|
+
duration_ms: durationMs,
|
|
510
|
+
input: inputArgs,
|
|
511
|
+
session: null,
|
|
512
|
+
status: "error",
|
|
513
|
+
error: {
|
|
514
|
+
message: errorInstance.message,
|
|
515
|
+
stack: errorInstance.stack,
|
|
516
|
+
},
|
|
517
|
+
}, ctx.root);
|
|
518
|
+
|
|
519
|
+
return {
|
|
520
|
+
isError: true,
|
|
521
|
+
content: [
|
|
522
|
+
{
|
|
523
|
+
type: "text",
|
|
524
|
+
text: `[Septum MCP Error] ${errorInstance.message}`,
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
} catch (error) {
|
|
530
|
+
return {isError: true, content: [{type: "text" as const, text: `[Septum MCP Error] ${error instanceof Error ? error.message : String(error)}`}]};
|
|
531
|
+
} finally { lease?.release(); }
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const transport = new StdioServerTransport();
|
|
535
|
+
|
|
536
|
+
let stopping = false;
|
|
537
|
+
let memoryTimer: ReturnType<typeof setInterval> | undefined;
|
|
538
|
+
const cleanup = () => {
|
|
539
|
+
if (stopping) return;
|
|
540
|
+
stopping = true;
|
|
541
|
+
if (memoryTimer) clearInterval(memoryTimer);
|
|
542
|
+
const deadline = setTimeout(() => {
|
|
543
|
+
console.error("[Septum MCP] Shutdown deadline exceeded; indexing may require reconciliation.");
|
|
544
|
+
process.exit(1);
|
|
545
|
+
}, RESOURCE_LIMITS.shutdownMs);
|
|
546
|
+
void (async () => {
|
|
547
|
+
try {
|
|
548
|
+
await server.close();
|
|
549
|
+
await manager.close();
|
|
550
|
+
clearTimeout(deadline);
|
|
551
|
+
console.error("[Septum MCP] All workspace resources closed cleanly.");
|
|
552
|
+
process.exit(0);
|
|
553
|
+
} catch (error) {
|
|
554
|
+
console.error(`[Septum MCP] Cleanup failed: ${String(error)}`);
|
|
555
|
+
clearTimeout(deadline);
|
|
556
|
+
process.exit(1);
|
|
557
|
+
}
|
|
558
|
+
})();
|
|
559
|
+
};
|
|
560
|
+
process.once("SIGINT", cleanup);
|
|
561
|
+
process.once("SIGTERM", cleanup);
|
|
562
|
+
process.stdin.once("end", cleanup);
|
|
563
|
+
process.stdin.once("close", cleanup);
|
|
564
|
+
server.onclose = cleanup;
|
|
565
|
+
await server.connect(transport);
|
|
566
|
+
try {
|
|
567
|
+
const initialRoot = resolveServerWorkspace({initial:true});
|
|
568
|
+
manager.initialRoot = initialRoot;
|
|
569
|
+
manager.lastRoot = initialRoot;
|
|
570
|
+
if (isWorkspaceInitialized(initialRoot)) {
|
|
571
|
+
const initial = manager.acquire(initialRoot);
|
|
572
|
+
try { await initial.context.ready; } finally { initial.release(); }
|
|
573
|
+
}
|
|
574
|
+
if (process.env.SEPTUM_MEMORY_DIAGNOSTICS === "1") {
|
|
575
|
+
memoryTimer = setInterval(() => {
|
|
576
|
+
const sample = { ...process.memoryUsage(), workspaces: manager.size, watches: manager.watchCount, pending_paths: manager.pendingPaths, sync_duration_ms: manager.syncDurationMs };
|
|
577
|
+
if (manager.lastRoot && isWorkspaceInitialized(manager.lastRoot)) {
|
|
578
|
+
SeptumTelemetry.recordMemorySample(sample, manager.lastRoot);
|
|
579
|
+
} else {
|
|
580
|
+
console.error(`[Septum Memory] ${JSON.stringify({timestamp: new Date().toISOString(), event: "memory_sample", metrics: sample})}`);
|
|
581
|
+
}
|
|
582
|
+
}, 60_000);
|
|
583
|
+
memoryTimer.unref();
|
|
584
|
+
}
|
|
585
|
+
} catch (error) {
|
|
586
|
+
await manager.close();
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (process.stdin.isTTY) {
|
|
591
|
+
console.error(
|
|
592
|
+
`\x1b[36m[Septum MCP]\x1b[0m Server daemon running on stdio (PID: ${process.pid}, v${SEPTUM_VERSION}).`
|
|
593
|
+
);
|
|
594
|
+
console.error(
|
|
595
|
+
`\x1b[36m[Septum MCP]\x1b[0m Listening for JSON-RPC client messages. Press Ctrl+C to terminate.`
|
|
596
|
+
);
|
|
597
|
+
} else {
|
|
598
|
+
console.error(`[Septum MCP] Server started successfully on stdio transport (v${SEPTUM_VERSION}).`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
|
|
2
|
+
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
3
|
+
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
4
|
+
import type { BoundaryToolArgs } from "../schemas.ts";
|
|
5
|
+
import { evaluateBoundary } from "./check-boundary.ts";
|
|
6
|
+
|
|
7
|
+
export type { BoundaryToolArgs };
|
|
8
|
+
|
|
9
|
+
export async function handleBoundaryTool(
|
|
10
|
+
evaluator: BoundaryEvaluator,
|
|
11
|
+
config: ValidatedSeptumConfig,
|
|
12
|
+
args: BoundaryToolArgs,
|
|
13
|
+
repo?: SeptumRepository,
|
|
14
|
+
workspaceRoot?: string
|
|
15
|
+
) {
|
|
16
|
+
return await evaluateBoundary(evaluator, config, args, repo, workspaceRoot);
|
|
17
|
+
}
|