@ismaelsoilet/synapsejs 1.8.0 → 1.9.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/src/mcp/server.ts CHANGED
@@ -33,6 +33,32 @@ import { checkSchemaDrift } from '../compiler/schema-drift';
33
33
  import { findSliceFiles, resolveSlicesDir } from '../compiler/slice-discovery';
34
34
  import { artifactDirectory, splitSlice, verifySplit, writeSplitArtifacts } from '../compiler/slice-splitter';
35
35
  import { SYNAPSE_VERSION } from '../version';
36
+ import { MCP_TOOLS } from './tools';
37
+
38
+ /**
39
+ * Caps a tool payload so a broken workspace cannot flood the caller's context, and
40
+ * makes every path relative to the project root so a tool result carries no absolute
41
+ * filesystem location.
42
+ */
43
+ const MCP_MAX_ITEMS = 100;
44
+
45
+ export function capItems<T>(items: T[]): { items: T[]; truncated: boolean; total: number } {
46
+ return {
47
+ items: items.slice(0, MCP_MAX_ITEMS),
48
+ truncated: items.length > MCP_MAX_ITEMS,
49
+ total: items.length
50
+ };
51
+ }
52
+
53
+ export function toRelativePath(root: string, value: unknown): unknown {
54
+ if (typeof value !== 'string' || !path.isAbsolute(value)) {
55
+ return value;
56
+ }
57
+
58
+ const relative = path.relative(root, value);
59
+
60
+ return relative.startsWith('..') ? path.basename(value) : relative;
61
+ }
36
62
 
37
63
  interface JsonRpcRequest {
38
64
  jsonrpc: string;
@@ -110,220 +136,7 @@ export class SynapseMcpServer {
110
136
  jsonrpc: '2.0',
111
137
  id,
112
138
  result: {
113
- tools: [
114
- {
115
- name: 'synapse_get_repo_map',
116
- description:
117
- 'Get compressed codebase skeleton map (.codebase/repo-map.d.ts) for AI context (<3000 tokens)',
118
- inputSchema: { type: 'object', properties: {} }
119
- },
120
- {
121
- name: 'synapse_get_db_schema',
122
- description:
123
- 'Get the centralized database schema catalog (.codebase/db-schema.d.ts) for AI context and type-safe relational queries',
124
- inputSchema: { type: 'object', properties: {} }
125
- },
126
- {
127
- name: 'synapse_check',
128
- description:
129
- 'Run machine-centric compiler diagnostics, returning exact JSON coordinates (file, line, col, message)',
130
- inputSchema: {
131
- type: 'object',
132
- properties: {
133
- targetFile: { type: 'string', description: 'Optional specific file to check' }
134
- }
135
- }
136
- },
137
- {
138
- name: 'synapse_split',
139
- description:
140
- 'Run slice splitter and leak verification gates to enforce server/client isolation and zero leakage',
141
- inputSchema: {
142
- type: 'object',
143
- properties: {
144
- targetSlice: { type: 'string', description: 'Optional specific slice name to split' }
145
- }
146
- }
147
- },
148
- {
149
- name: 'synapse_run_pbt',
150
- description: 'Execute Fast-Check Property-Based Testing (PBT) invariant test suite across all slices',
151
- inputSchema: { type: 'object', properties: {} }
152
- },
153
- {
154
- name: 'synapse_scaffold_slice',
155
- description:
156
- 'Scaffold a new fullstack atomic vertical slice with TypeBox, Result, Action, React UI, and PBT oracles',
157
- inputSchema: {
158
- type: 'object',
159
- required: ['domain', 'name'],
160
- properties: {
161
- domain: { type: 'string', description: 'Domain name (e.g. billing, customers, orders)' },
162
- name: { type: 'string', description: 'Slice name in kebab-case (e.g. cancel-subscription)' },
163
- template: {
164
- type: 'string',
165
- enum: ['create', 'list', 'update', 'delete', 'login', 'oauth-github', 'crud'],
166
- description: 'Optional slice template shape (default: create)'
167
- },
168
- fields: {
169
- type: 'string',
170
- description:
171
- 'Optional fields grammar, e.g. "name:string,email:string,status:enum(ACTIVE|INACTIVE),price:number"'
172
- }
173
- }
174
- }
175
- },
176
- {
177
- name: 'synapse_contract',
178
- description:
179
- 'Return the machine contract: slice exports and suffixes, Result and HTTP semantics, session rules, addressing, SSR behavior and the gates to run',
180
- inputSchema: { type: 'object', properties: {} }
181
- },
182
- {
183
- name: 'synapse_migrate',
184
- description:
185
- 'Auto-discover and apply sliceSchema DDL declarations across slices into the active database',
186
- inputSchema: { type: 'object', properties: {} }
187
- },
188
- {
189
- name: 'synapse_check_db_drift',
190
- description:
191
- 'Inspects live database catalog against sliceSchema DDL contracts, identifying missing tables, missing columns, and orphan tables',
192
- inputSchema: { type: 'object', properties: {} }
193
- },
194
- {
195
- name: 'synapse_diff_impact',
196
- description:
197
- 'Analyzes cross-slice dependencies (Foreign Keys, shared module imports, and table references) to report all slices impacted by a file or table change',
198
- inputSchema: {
199
- type: 'object',
200
- required: ['target'],
201
- properties: {
202
- target: {
203
- type: 'string',
204
- description: 'Slice file path, slice name, shared module path, or table name'
205
- }
206
- }
207
- }
208
- },
209
- {
210
- name: 'synapse_rollback',
211
- description: 'Roll back applied sliceSchema migrations by executing their -- down: statements',
212
- inputSchema: {
213
- type: 'object',
214
- properties: {
215
- targetSlice: { type: 'string', description: 'Optional target slice to rollback' },
216
- steps: { type: 'number', description: 'Number of recent migrations to rollback (default: 1)' }
217
- }
218
- }
219
- },
220
- {
221
- name: 'synapse_test_gate',
222
- description:
223
- 'Execute Fast-Check PBT oracles and immediately triage failures with Jev System One semantic test-gate to prevent LLM token waste',
224
- inputSchema: {
225
- type: 'object',
226
- properties: {}
227
- }
228
- },
229
- {
230
- name: 'synapse_abort_check',
231
- description:
232
- 'Evaluate plan and error history with Jev System One to detect doomed trajectories, circular loops, or high-risk refactor dead ends',
233
- inputSchema: {
234
- type: 'object',
235
- required: ['plan', 'history'],
236
- properties: {
237
- plan: { type: 'string', description: 'Proposed implementation plan or architectural change' },
238
- history: { type: 'string', description: 'Recent attempt history, error logs, or failure reasons' }
239
- }
240
- }
241
- },
242
- {
243
- name: 'synapse_verify_completion',
244
- description:
245
- 'Verify slice implementation and test outputs against acceptance criteria using Jev System One before committing work',
246
- inputSchema: {
247
- type: 'object',
248
- required: ['criteria', 'output'],
249
- properties: {
250
- criteria: { type: 'string', description: 'Acceptance criteria or requirement specifications' },
251
- output: {
252
- type: 'string',
253
- description: 'Actual implementation summary, test output, or slice behavior'
254
- }
255
- }
256
- }
257
- },
258
- {
259
- name: 'synapse_reasoning_effort',
260
- description:
261
- 'Dynamically modulate agent reasoning effort (Astra-Jev) to low/medium/high based on step context (lowering effort for mechanical commands like split/migrate/skeleton)',
262
- inputSchema: {
263
- type: 'object',
264
- required: ['context'],
265
- properties: {
266
- context: {
267
- type: 'string',
268
- description: 'Immediate command or task context, e.g. "synapse split", "git commit"'
269
- },
270
- provider: {
271
- type: 'string',
272
- description: 'Target LLM provider, e.g. "deepseek", "anthropic", "openai"'
273
- },
274
- sessionContextTokens: {
275
- type: 'number',
276
- description: 'Estimated session context token count to protect prompt cache'
277
- }
278
- }
279
- }
280
- },
281
- {
282
- name: 'synapse_triage_error',
283
- description:
284
- 'Triage an arbitrary test failure or execution error log using Jev System One to classify root causes (env_missing vs flaky_transient vs deep_logic) and avoid token waste',
285
- inputSchema: {
286
- type: 'object',
287
- required: ['failureLog'],
288
- properties: {
289
- failureLog: {
290
- type: 'string',
291
- description: 'Error log, stack trace or terminal output to triage'
292
- }
293
- }
294
- }
295
- },
296
- {
297
- name: 'synapse_route_task',
298
- description:
299
- 'Semantically route a development task to the optimal model/reasoning tier via Jev System One',
300
- inputSchema: {
301
- type: 'object',
302
- required: ['task'],
303
- properties: {
304
- task: {
305
- type: 'string',
306
- description: 'Description of the coding, refactoring, or diagnostic task'
307
- }
308
- }
309
- }
310
- },
311
- {
312
- name: 'synapse_evaluate_nudge',
313
- description:
314
- 'Evaluate whether an agent is prematurely stopping or needs a proactive nudge to continue verification',
315
- inputSchema: {
316
- type: 'object',
317
- required: ['transcriptTail'],
318
- properties: {
319
- transcriptTail: {
320
- type: 'string',
321
- description: 'Recent transcript steps or conversation history tail'
322
- }
323
- }
324
- }
325
- }
326
- ]
139
+ tools: MCP_TOOLS
327
140
  }
328
141
  };
329
142
  }
@@ -405,7 +218,22 @@ export class SynapseMcpServer {
405
218
  );
406
219
  } else if (toolName === 'synapse_check') {
407
220
  const report = runMachineVerifications(this.root, args.targetFile);
408
- contentText = JSON.stringify(report, null, 2);
221
+ const issues = capItems(report.issues).items.map((issue) => ({
222
+ ...issue,
223
+ file: toRelativePath(this.root, issue.file)
224
+ }));
225
+
226
+ contentText = JSON.stringify(
227
+ {
228
+ ...report,
229
+ issues,
230
+ issuesTruncated: report.issues.length > MCP_MAX_ITEMS,
231
+ reportedIssues: issues.length,
232
+ totalIssues: report.issues.length
233
+ },
234
+ null,
235
+ 2
236
+ );
409
237
  } else if (toolName === 'synapse_split') {
410
238
  const resolution = resolveSlicesDir(this.root);
411
239
  if (!resolution.ok) {
@@ -475,13 +303,15 @@ export class SynapseMcpServer {
475
303
  }
476
304
 
477
305
  const splitStatus = failed || slices.length === 0 ? 'FAIL' : 'PASS';
306
+ const boundedSlices = capItems(slices);
478
307
  contentText = JSON.stringify(
479
308
  {
480
309
  status: splitStatus,
481
310
  operation: 'SLICE_SPLIT',
482
311
  slicesDir: path.relative(this.root, resolution.value.slicesDir),
483
312
  totalProcessed: slices.length,
484
- slices
313
+ slicesTruncated: boundedSlices.truncated,
314
+ slices: boundedSlices.items
485
315
  },
486
316
  null,
487
317
  2
@@ -617,7 +447,20 @@ export class SynapseMcpServer {
617
447
  };
618
448
  }
619
449
  const report = analyzeImpact(args.target, this.root);
620
- contentText = JSON.stringify(report, null, 2);
450
+ const bounded = capItems(report.impactedSlices);
451
+ contentText = JSON.stringify(
452
+ {
453
+ ...report,
454
+ impactedSlices: bounded.items.map((slice) => ({
455
+ ...slice,
456
+ filePath: toRelativePath(this.root, slice.filePath)
457
+ })),
458
+ impactedTruncated: bounded.truncated,
459
+ totalImpacted: report.totalImpacted
460
+ },
461
+ null,
462
+ 2
463
+ );
621
464
  } else if (toolName === 'synapse_rollback') {
622
465
  const report = await rollbackSliceMigrations(this.root, undefined, {
623
466
  targetSlice: args.targetSlice,
@@ -0,0 +1,238 @@
1
+ /**
2
+ * SynapseJS - Model Context Protocol Tool Inventory
3
+ *
4
+ * The declarative list of tools the MCP server registers: names, descriptions and
5
+ * input schemas, with no runtime dependency. Keeping it here means the count the
6
+ * documentation quotes is derived from the registered list rather than maintained by
7
+ * hand, and `synapse info` can report it without loading the JSON-RPC server.
8
+ */
9
+
10
+ import { PATH_SEGMENT_PATTERN } from '../core/path-guard';
11
+
12
+ export interface McpToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: Record<string, unknown>;
16
+ }
17
+
18
+ export const MCP_TOOLS: McpToolDefinition[] = [
19
+ {
20
+ name: 'synapse_get_repo_map',
21
+ description: 'Get compressed codebase skeleton map (.codebase/repo-map.d.ts) for AI context (<3000 tokens)',
22
+ inputSchema: { type: 'object', properties: {} }
23
+ },
24
+ {
25
+ name: 'synapse_get_db_schema',
26
+ description:
27
+ 'Get the centralized database schema catalog (.codebase/db-schema.d.ts) for AI context and type-safe relational queries',
28
+ inputSchema: { type: 'object', properties: {} }
29
+ },
30
+ {
31
+ name: 'synapse_check',
32
+ description:
33
+ 'Run machine-centric compiler diagnostics, returning exact JSON coordinates (file, line, col, message)',
34
+ inputSchema: {
35
+ type: 'object',
36
+ properties: {
37
+ targetFile: { type: 'string', description: 'Optional specific file to check' }
38
+ }
39
+ }
40
+ },
41
+ {
42
+ name: 'synapse_split',
43
+ description: 'Run slice splitter and leak verification gates to enforce server/client isolation and zero leakage',
44
+ inputSchema: {
45
+ type: 'object',
46
+ properties: {
47
+ targetSlice: { type: 'string', description: 'Optional specific slice name to split' }
48
+ }
49
+ }
50
+ },
51
+ {
52
+ name: 'synapse_run_pbt',
53
+ description: 'Execute Fast-Check Property-Based Testing (PBT) invariant test suite across all slices',
54
+ inputSchema: { type: 'object', properties: {} }
55
+ },
56
+ {
57
+ name: 'synapse_scaffold_slice',
58
+ description:
59
+ 'Scaffold a new fullstack atomic vertical slice with TypeBox, Result, Action, React UI, and PBT oracles',
60
+ inputSchema: {
61
+ type: 'object',
62
+ required: ['domain', 'name'],
63
+ properties: {
64
+ domain: {
65
+ type: 'string',
66
+ pattern: PATH_SEGMENT_PATTERN,
67
+ description: 'Domain name (e.g. billing, customers, orders)'
68
+ },
69
+ name: {
70
+ type: 'string',
71
+ pattern: PATH_SEGMENT_PATTERN,
72
+ description: 'Slice name in kebab-case (e.g. cancel-subscription)'
73
+ },
74
+ template: {
75
+ type: 'string',
76
+ enum: ['create', 'list', 'update', 'delete', 'login', 'oauth-github', 'crud'],
77
+ description: 'Optional slice template shape (default: create)'
78
+ },
79
+ fields: {
80
+ type: 'string',
81
+ description:
82
+ 'Optional fields grammar, e.g. "name:string,email:string,status:enum(ACTIVE|INACTIVE),price:number"'
83
+ }
84
+ }
85
+ }
86
+ },
87
+ {
88
+ name: 'synapse_contract',
89
+ description:
90
+ 'Return the machine contract: slice exports and suffixes, Result and HTTP semantics, session rules, addressing, SSR behavior and the gates to run',
91
+ inputSchema: { type: 'object', properties: {} }
92
+ },
93
+ {
94
+ name: 'synapse_migrate',
95
+ description: 'Auto-discover and apply sliceSchema DDL declarations across slices into the active database',
96
+ inputSchema: { type: 'object', properties: {} }
97
+ },
98
+ {
99
+ name: 'synapse_check_db_drift',
100
+ description:
101
+ 'Inspects live database catalog against sliceSchema DDL contracts, identifying missing tables, missing columns, and orphan tables',
102
+ inputSchema: { type: 'object', properties: {} }
103
+ },
104
+ {
105
+ name: 'synapse_diff_impact',
106
+ description:
107
+ 'Analyzes cross-slice dependencies (Foreign Keys, shared module imports, and table references) to report all slices impacted by a file or table change',
108
+ inputSchema: {
109
+ type: 'object',
110
+ required: ['target'],
111
+ properties: {
112
+ target: {
113
+ type: 'string',
114
+ description: 'Slice file path, slice name, shared module path, or table name'
115
+ }
116
+ }
117
+ }
118
+ },
119
+ {
120
+ name: 'synapse_rollback',
121
+ description: 'Roll back applied sliceSchema migrations by executing their -- down: statements',
122
+ inputSchema: {
123
+ type: 'object',
124
+ properties: {
125
+ targetSlice: { type: 'string', description: 'Optional target slice to rollback' },
126
+ steps: { type: 'number', description: 'Number of recent migrations to rollback (default: 1)' }
127
+ }
128
+ }
129
+ },
130
+ {
131
+ name: 'synapse_test_gate',
132
+ description:
133
+ 'Execute Fast-Check PBT oracles and immediately triage failures with Jev System One semantic test-gate to prevent LLM token waste',
134
+ inputSchema: {
135
+ type: 'object',
136
+ properties: {}
137
+ }
138
+ },
139
+ {
140
+ name: 'synapse_abort_check',
141
+ description:
142
+ 'Evaluate plan and error history with Jev System One to detect doomed trajectories, circular loops, or high-risk refactor dead ends',
143
+ inputSchema: {
144
+ type: 'object',
145
+ required: ['plan', 'history'],
146
+ properties: {
147
+ plan: { type: 'string', description: 'Proposed implementation plan or architectural change' },
148
+ history: { type: 'string', description: 'Recent attempt history, error logs, or failure reasons' }
149
+ }
150
+ }
151
+ },
152
+ {
153
+ name: 'synapse_verify_completion',
154
+ description:
155
+ 'Verify slice implementation and test outputs against acceptance criteria using Jev System One before committing work',
156
+ inputSchema: {
157
+ type: 'object',
158
+ required: ['criteria', 'output'],
159
+ properties: {
160
+ criteria: { type: 'string', description: 'Acceptance criteria or requirement specifications' },
161
+ output: {
162
+ type: 'string',
163
+ description: 'Actual implementation summary, test output, or slice behavior'
164
+ }
165
+ }
166
+ }
167
+ },
168
+ {
169
+ name: 'synapse_reasoning_effort',
170
+ description:
171
+ 'Dynamically modulate agent reasoning effort (Astra-Jev) to low/medium/high based on step context (lowering effort for mechanical commands like split/migrate/skeleton)',
172
+ inputSchema: {
173
+ type: 'object',
174
+ required: ['context'],
175
+ properties: {
176
+ context: {
177
+ type: 'string',
178
+ description: 'Immediate command or task context, e.g. "synapse split", "git commit"'
179
+ },
180
+ provider: {
181
+ type: 'string',
182
+ description: 'Target LLM provider, e.g. "deepseek", "anthropic", "openai"'
183
+ },
184
+ sessionContextTokens: {
185
+ type: 'number',
186
+ description: 'Estimated session context token count to protect prompt cache'
187
+ }
188
+ }
189
+ }
190
+ },
191
+ {
192
+ name: 'synapse_triage_error',
193
+ description:
194
+ 'Triage an arbitrary test failure or execution error log using Jev System One to classify root causes (env_missing vs flaky_transient vs deep_logic) and avoid token waste',
195
+ inputSchema: {
196
+ type: 'object',
197
+ required: ['failureLog'],
198
+ properties: {
199
+ failureLog: {
200
+ type: 'string',
201
+ description: 'Error log, stack trace or terminal output to triage'
202
+ }
203
+ }
204
+ }
205
+ },
206
+ {
207
+ name: 'synapse_route_task',
208
+ description: 'Semantically route a development task to the optimal model/reasoning tier via Jev System One',
209
+ inputSchema: {
210
+ type: 'object',
211
+ required: ['task'],
212
+ properties: {
213
+ task: {
214
+ type: 'string',
215
+ description: 'Description of the coding, refactoring, or diagnostic task'
216
+ }
217
+ }
218
+ }
219
+ },
220
+ {
221
+ name: 'synapse_evaluate_nudge',
222
+ description:
223
+ 'Evaluate whether an agent is prematurely stopping or needs a proactive nudge to continue verification',
224
+ inputSchema: {
225
+ type: 'object',
226
+ required: ['transcriptTail'],
227
+ properties: {
228
+ transcriptTail: {
229
+ type: 'string',
230
+ description: 'Recent transcript steps or conversation history tail'
231
+ }
232
+ }
233
+ }
234
+ }
235
+ ];
236
+
237
+ /** The registered tool names, in registration order. */
238
+ export const MCP_TOOL_NAMES: string[] = MCP_TOOLS.map((tool) => tool.name);