@atolis-hq/corum 0.1.43 → 0.1.45
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/README.md +108 -7
- package/dist/src/graph/index.js +69 -37
- package/dist/src/graph/overlay.js +106 -36
- package/dist/src/import/runner.js +17 -3
- package/dist/src/linter/index.js +242 -106
- package/dist/src/loader/cluster-loader.js +36 -3
- package/dist/src/loader/edge-loader.js +8 -2
- package/dist/src/mcp/index.js +438 -12
- package/dist/src/mcp/prompts/usage-guide.js +61 -21
- package/dist/src/mutate/alias.js +68 -0
- package/dist/src/mutate/apply-cluster.js +255 -0
- package/dist/src/mutate/delete.js +47 -0
- package/dist/src/mutate/errors.js +14 -0
- package/dist/src/mutate/index.js +11 -0
- package/dist/src/mutate/rename.js +135 -0
- package/dist/src/mutate/session.js +513 -0
- package/dist/src/mutate/util.js +62 -0
- package/dist/src/reconcile/index.js +126 -3
- package/dist/src/source/file-source.js +64 -15
- package/dist/src/source/git-source.js +121 -31
- package/dist/src/writer/graph-writer.js +64 -10
- package/package.json +2 -1
package/dist/src/mcp/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
6
6
|
import { computeClusterOverlay, expandExternalNodes, getClusterView, getGraphSummary, getLineage, getLinkedFields, getStructuralNodeTemplates, getVisibleEdgeTypes, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
|
|
7
7
|
import { loadGraph, loadMultiGraph } from '../loader/index.js';
|
|
8
8
|
import { QueryError } from '../schema/index.js';
|
|
9
|
+
import { MutationError, getActiveSession, startSession } from '../mutate/index.js';
|
|
9
10
|
import { createGraphRuntimeConfig } from '../source/config.js';
|
|
10
11
|
import { createMultiGraphCache, replaceGraph, startGraphFileWatcher, startWebServer } from '../web/server.js';
|
|
11
12
|
import { USAGE_GUIDE_PROMPT } from './prompts/usage-guide.js';
|
|
@@ -75,6 +76,7 @@ function fullNode(node, includeProvenance) {
|
|
|
75
76
|
component: node.component,
|
|
76
77
|
state: node.state,
|
|
77
78
|
stability: node.stability,
|
|
79
|
+
...(node.corum !== undefined ? { corum: node.corum } : {}),
|
|
78
80
|
properties: node.properties,
|
|
79
81
|
...(includeProvenance ? withProvenance(node) : {}),
|
|
80
82
|
};
|
|
@@ -131,6 +133,21 @@ function mapLineageNode(node, includeProvenance, lean) {
|
|
|
131
133
|
}
|
|
132
134
|
export function createMcpHandlers(graph, source, cache) {
|
|
133
135
|
const resolveMulti = (src) => cache ? cache.get() : loadMultiGraph({ source: src });
|
|
136
|
+
// Reads reflect the working session while one is open (design §7/§8):
|
|
137
|
+
// un-branched reads serve the session's working graph; branch-scoped reads
|
|
138
|
+
// for the session's own branch do too (see withBranchGraph). Behaviour with
|
|
139
|
+
// no open session is unchanged.
|
|
140
|
+
const readGraph = () => {
|
|
141
|
+
const session = getActiveSession();
|
|
142
|
+
return session && !session.isClosed() ? session.graph : graph;
|
|
143
|
+
};
|
|
144
|
+
const requireSession = () => {
|
|
145
|
+
const session = getActiveSession();
|
|
146
|
+
if (!session || session.isClosed()) {
|
|
147
|
+
throw new QueryError('no working session is open — call start_changes first');
|
|
148
|
+
}
|
|
149
|
+
return session;
|
|
150
|
+
};
|
|
134
151
|
return {
|
|
135
152
|
list_nodes(args) {
|
|
136
153
|
const run = (targetGraph) => {
|
|
@@ -143,7 +160,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
143
160
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
144
161
|
}
|
|
145
162
|
try {
|
|
146
|
-
return run(
|
|
163
|
+
return run(readGraph());
|
|
147
164
|
}
|
|
148
165
|
catch (err) {
|
|
149
166
|
return errorResult(err);
|
|
@@ -155,7 +172,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
155
172
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
156
173
|
}
|
|
157
174
|
try {
|
|
158
|
-
return run(
|
|
175
|
+
return run(readGraph());
|
|
159
176
|
}
|
|
160
177
|
catch (err) {
|
|
161
178
|
return errorResult(err);
|
|
@@ -189,7 +206,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
189
206
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
190
207
|
}
|
|
191
208
|
try {
|
|
192
|
-
return run(
|
|
209
|
+
return run(readGraph());
|
|
193
210
|
}
|
|
194
211
|
catch (err) {
|
|
195
212
|
return errorResult(err);
|
|
@@ -213,7 +230,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
213
230
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
214
231
|
}
|
|
215
232
|
try {
|
|
216
|
-
return run(
|
|
233
|
+
return run(readGraph());
|
|
217
234
|
}
|
|
218
235
|
catch (err) {
|
|
219
236
|
return errorResult(err);
|
|
@@ -222,7 +239,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
222
239
|
get_template(args) {
|
|
223
240
|
try {
|
|
224
241
|
const name = String(args.name);
|
|
225
|
-
const template =
|
|
242
|
+
const template = readGraph().templates.get(name);
|
|
226
243
|
if (!template) {
|
|
227
244
|
throw new QueryError(`Template not found: ${name}`);
|
|
228
245
|
}
|
|
@@ -315,7 +332,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
315
332
|
if (branchRef) {
|
|
316
333
|
return withBranchGraph(source, branchRef, branch => run(branch.graph, branchRef), cache);
|
|
317
334
|
}
|
|
318
|
-
return run(
|
|
335
|
+
return run(readGraph()).catch(err => errorResult(err));
|
|
319
336
|
},
|
|
320
337
|
get_graph(args) {
|
|
321
338
|
const run = (targetGraph) => {
|
|
@@ -344,7 +361,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
344
361
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
345
362
|
}
|
|
346
363
|
try {
|
|
347
|
-
return run(
|
|
364
|
+
return run(readGraph());
|
|
348
365
|
}
|
|
349
366
|
catch (err) {
|
|
350
367
|
return errorResult(err);
|
|
@@ -378,7 +395,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
378
395
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
379
396
|
}
|
|
380
397
|
try {
|
|
381
|
-
return run(
|
|
398
|
+
return run(readGraph());
|
|
382
399
|
}
|
|
383
400
|
catch (err) {
|
|
384
401
|
return errorResult(err);
|
|
@@ -421,7 +438,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
421
438
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
422
439
|
}
|
|
423
440
|
try {
|
|
424
|
-
return run(
|
|
441
|
+
return run(readGraph());
|
|
425
442
|
}
|
|
426
443
|
catch (err) {
|
|
427
444
|
return errorResult(err);
|
|
@@ -441,7 +458,7 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
441
458
|
return withBranchGraph(source, String(args.branch), branch => run(branch.graph), cache);
|
|
442
459
|
}
|
|
443
460
|
try {
|
|
444
|
-
return run(
|
|
461
|
+
return run(readGraph());
|
|
445
462
|
}
|
|
446
463
|
catch (err) {
|
|
447
464
|
return errorResult(err);
|
|
@@ -478,10 +495,202 @@ export function createMcpHandlers(graph, source, cache) {
|
|
|
478
495
|
return errorResult(err);
|
|
479
496
|
}
|
|
480
497
|
},
|
|
498
|
+
// -- write tools (design §8): thin wrappers over the working session ------
|
|
499
|
+
async start_changes(args) {
|
|
500
|
+
try {
|
|
501
|
+
if (!source)
|
|
502
|
+
throw new QueryError('GraphSource is required for start_changes');
|
|
503
|
+
const session = await startSession(source, {
|
|
504
|
+
branch: typeof args.branch === 'string' ? args.branch : undefined,
|
|
505
|
+
create: args.create === true,
|
|
506
|
+
...(typeof args.autosave === 'boolean' ? { autosave: args.autosave } : {}),
|
|
507
|
+
});
|
|
508
|
+
return formatResult({
|
|
509
|
+
branch: session.branch,
|
|
510
|
+
default_branch: session.defaultBranch,
|
|
511
|
+
base_sha: session.baseSha,
|
|
512
|
+
autosave: session.autosave,
|
|
513
|
+
}, args.format, getCompactKeys(args));
|
|
514
|
+
}
|
|
515
|
+
catch (err) {
|
|
516
|
+
return errorResult(err, args.format);
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
async apply_cluster(args) {
|
|
520
|
+
try {
|
|
521
|
+
const session = requireSession();
|
|
522
|
+
if (args.mode !== 'merge' && args.mode !== 'replace') {
|
|
523
|
+
throw new QueryError("mode must be 'merge' or 'replace'");
|
|
524
|
+
}
|
|
525
|
+
if (!isPlainObject(args.document)) {
|
|
526
|
+
throw new QueryError('document must be an object (cluster-style document)');
|
|
527
|
+
}
|
|
528
|
+
const result = await session.applyCluster(args.document, args.mode);
|
|
529
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
return errorResult(err, args.format);
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
async create_node(args) {
|
|
536
|
+
try {
|
|
537
|
+
const session = requireSession();
|
|
538
|
+
if (!isPlainObject(args.document)) {
|
|
539
|
+
throw new QueryError('document is required and must be an object');
|
|
540
|
+
}
|
|
541
|
+
const result = await session.createNode({
|
|
542
|
+
document: args.document,
|
|
543
|
+
parentId: typeof args.parent_id === 'string' ? args.parent_id : undefined,
|
|
544
|
+
section: typeof args.section === 'string' ? args.section : undefined,
|
|
545
|
+
name: typeof args.name === 'string' ? args.name : undefined,
|
|
546
|
+
});
|
|
547
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
548
|
+
}
|
|
549
|
+
catch (err) {
|
|
550
|
+
return errorResult(err, args.format);
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
async update_node(args) {
|
|
554
|
+
try {
|
|
555
|
+
const session = requireSession();
|
|
556
|
+
const result = await session.updateNode(requireString(args.id, 'id'), {
|
|
557
|
+
properties: isPlainObject(args.properties) ? args.properties : undefined,
|
|
558
|
+
state: args.state,
|
|
559
|
+
stability: args.stability,
|
|
560
|
+
});
|
|
561
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
562
|
+
}
|
|
563
|
+
catch (err) {
|
|
564
|
+
return errorResult(err, args.format);
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
async rename_node(args) {
|
|
568
|
+
try {
|
|
569
|
+
const session = requireSession();
|
|
570
|
+
const result = await session.renameNode(requireString(args.id, 'id'), requireString(args.new_name, 'new_name'), typeof args.record_trail === 'boolean' ? args.record_trail : undefined);
|
|
571
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
572
|
+
}
|
|
573
|
+
catch (err) {
|
|
574
|
+
return errorResult(err, args.format);
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
async delete_node(args) {
|
|
578
|
+
try {
|
|
579
|
+
const session = requireSession();
|
|
580
|
+
const result = await session.deleteNode(requireString(args.id, 'id'), {
|
|
581
|
+
purge: args.purge === true,
|
|
582
|
+
recordTrail: typeof args.record_trail === 'boolean' ? args.record_trail : undefined,
|
|
583
|
+
});
|
|
584
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
585
|
+
}
|
|
586
|
+
catch (err) {
|
|
587
|
+
return errorResult(err, args.format);
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
async create_edge(args) {
|
|
591
|
+
try {
|
|
592
|
+
const session = requireSession();
|
|
593
|
+
const result = await session.createEdge({
|
|
594
|
+
from: requireString(args.from, 'from'),
|
|
595
|
+
to: requireString(args.to, 'to'),
|
|
596
|
+
type: requireString(args.type, 'type'),
|
|
597
|
+
state: args.state,
|
|
598
|
+
stability: args.stability,
|
|
599
|
+
notes: typeof args.notes === 'string' ? args.notes : undefined,
|
|
600
|
+
properties: isPlainObject(args.properties) ? args.properties : undefined,
|
|
601
|
+
});
|
|
602
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
return errorResult(err, args.format);
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
async update_edge(args) {
|
|
609
|
+
try {
|
|
610
|
+
const session = requireSession();
|
|
611
|
+
const result = await session.updateEdge(requireString(args.id, 'id'), {
|
|
612
|
+
state: args.state,
|
|
613
|
+
stability: args.stability,
|
|
614
|
+
notes: args.notes === null ? null : typeof args.notes === 'string' ? args.notes : undefined,
|
|
615
|
+
properties: isPlainObject(args.properties) ? args.properties : undefined,
|
|
616
|
+
});
|
|
617
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
618
|
+
}
|
|
619
|
+
catch (err) {
|
|
620
|
+
return errorResult(err, args.format);
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
async delete_edge(args) {
|
|
624
|
+
try {
|
|
625
|
+
const session = requireSession();
|
|
626
|
+
const result = await session.deleteEdge(requireString(args.id, 'id'));
|
|
627
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
628
|
+
}
|
|
629
|
+
catch (err) {
|
|
630
|
+
return errorResult(err, args.format);
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
pending_changes(args) {
|
|
634
|
+
try {
|
|
635
|
+
const session = requireSession();
|
|
636
|
+
return formatResult(session.pendingChanges(), args.format, getCompactKeys(args));
|
|
637
|
+
}
|
|
638
|
+
catch (err) {
|
|
639
|
+
return errorResult(err, args.format);
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
async discard_changes(args) {
|
|
643
|
+
try {
|
|
644
|
+
const session = requireSession();
|
|
645
|
+
const branch = session.branch;
|
|
646
|
+
session.discard();
|
|
647
|
+
if (session.autosave && session.branch === session.defaultBranch && source) {
|
|
648
|
+
const fresh = await loadGraph({ source, ref: session.defaultBranch, strict: false });
|
|
649
|
+
cache?.invalidate();
|
|
650
|
+
replaceGraph(graph, fresh);
|
|
651
|
+
}
|
|
652
|
+
return formatResult({ discarded: true, branch }, args.format, getCompactKeys(args));
|
|
653
|
+
}
|
|
654
|
+
catch (err) {
|
|
655
|
+
return errorResult(err, args.format);
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
async commit_changes(args) {
|
|
659
|
+
try {
|
|
660
|
+
const session = requireSession();
|
|
661
|
+
const result = await session.commitChanges(typeof args.message === 'string' ? args.message : undefined);
|
|
662
|
+
// Committed content invalidates branch-scoped caches; when the session
|
|
663
|
+
// was on the default branch, refresh the base graph in place so
|
|
664
|
+
// post-session reads see the committed state.
|
|
665
|
+
cache?.invalidate();
|
|
666
|
+
if (result.committed && session.branch === session.defaultBranch) {
|
|
667
|
+
replaceGraph(graph, session.graph);
|
|
668
|
+
}
|
|
669
|
+
return formatResult(result, args.format, getCompactKeys(args));
|
|
670
|
+
}
|
|
671
|
+
catch (err) {
|
|
672
|
+
return errorResult(err, args.format);
|
|
673
|
+
}
|
|
674
|
+
},
|
|
481
675
|
};
|
|
482
676
|
}
|
|
677
|
+
function requireString(value, name) {
|
|
678
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
679
|
+
throw new QueryError(`${name} is required`);
|
|
680
|
+
}
|
|
681
|
+
return value;
|
|
682
|
+
}
|
|
683
|
+
function isPlainObject(value) {
|
|
684
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
685
|
+
}
|
|
483
686
|
async function withBranchGraph(source, branchRef, fn, cache) {
|
|
484
687
|
try {
|
|
688
|
+
// While a working session is open, branch-scoped reads of the session's
|
|
689
|
+
// branch serve the working graph (design §7: reads see the working state).
|
|
690
|
+
const session = getActiveSession();
|
|
691
|
+
if (session && !session.isClosed() && session.branch === branchRef) {
|
|
692
|
+
return await fn({ ref: branchRef, isDefault: branchRef === session.defaultBranch, graph: session.graph });
|
|
693
|
+
}
|
|
485
694
|
if (!source)
|
|
486
695
|
throw new QueryError('GraphSource is required when branch is provided');
|
|
487
696
|
const multi = cache ? await cache.get() : await loadMultiGraph({ source });
|
|
@@ -524,7 +733,27 @@ function formatResult(value, format, compact = false) {
|
|
|
524
733
|
function getCompactKeys(args) {
|
|
525
734
|
return args.compact_keys === true || args.compactKeys === true;
|
|
526
735
|
}
|
|
527
|
-
function errorResult(err) {
|
|
736
|
+
function errorResult(err, format) {
|
|
737
|
+
// Validation failures return the linter's diagnostic format (severity,
|
|
738
|
+
// message, nodeId) so agents can self-correct (design §8).
|
|
739
|
+
if (err instanceof MutationError) {
|
|
740
|
+
const payload = {
|
|
741
|
+
error: err.message,
|
|
742
|
+
diagnostics: err.diagnostics.map(d => ({
|
|
743
|
+
severity: d.severity,
|
|
744
|
+
message: d.message,
|
|
745
|
+
...(d.nodeId !== undefined ? { nodeId: d.nodeId } : {}),
|
|
746
|
+
})),
|
|
747
|
+
};
|
|
748
|
+
let text;
|
|
749
|
+
try {
|
|
750
|
+
text = getSerializer(format).serialize(payload);
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
text = getSerializer(undefined).serialize(payload);
|
|
754
|
+
}
|
|
755
|
+
return { content: [{ type: 'text', text }], isError: true };
|
|
756
|
+
}
|
|
528
757
|
const message = err instanceof QueryError ? err.message : String(err);
|
|
529
758
|
return { content: [{ type: 'text', text: message }], isError: true };
|
|
530
759
|
}
|
|
@@ -759,7 +988,7 @@ export function getMcpToolDefinitions() {
|
|
|
759
988
|
},
|
|
760
989
|
{
|
|
761
990
|
name: 'diff_branch',
|
|
762
|
-
description: 'Diff a branch against the default branch.',
|
|
991
|
+
description: 'Diff a branch against the default branch. Rename-aware: branch IDs are resolved through the default branch\'s rename trail before matching, so a branch still holding an old name overlays onto the renamed node instead of appearing as add+remove. The result\'s warnings field flags branches that modify a node under a retired name ("edits a retired name") — rebase the branch or apply the rename.',
|
|
763
992
|
inputSchema: {
|
|
764
993
|
type: 'object',
|
|
765
994
|
required: ['branch'],
|
|
@@ -770,6 +999,179 @@ export function getMcpToolDefinitions() {
|
|
|
770
999
|
},
|
|
771
1000
|
},
|
|
772
1001
|
},
|
|
1002
|
+
{
|
|
1003
|
+
name: 'start_changes',
|
|
1004
|
+
description: 'Open a working session for graph mutations. All other write tools require an open session; while a session is open, read tools reflect the working (uncommitted) state. Mutations stay in the session until commit_changes; discard_changes aborts. autosave defaults OFF for both file and git sources — prefer leaving it off unless you explicitly want per-mutation checkpoints. When autosave is ON, file sources write through to disk immediately and git sources land a "corum-wip:" checkpoint commit per mutation; commit_changes squashes the WIP run into a single commit when no external commit interleaved. Git default branches are read-only for writes: pass a writable branch explicitly or use create: true to fork one from the default branch head. Starting while a session with pending changes is open is an error — commit_changes or discard_changes first; with no pending changes the old session is reset cleanly.',
|
|
1005
|
+
inputSchema: {
|
|
1006
|
+
type: 'object',
|
|
1007
|
+
properties: {
|
|
1008
|
+
branch: { type: 'string', description: 'Branch to load and commit to. Defaults to the source\'s default branch.' },
|
|
1009
|
+
create: { type: 'boolean', description: 'Fork a new branch from the default branch head (git sources only). Default false.' },
|
|
1010
|
+
autosave: { type: 'boolean', description: 'Override the autosave default (OFF by default. When ON: file sources write through immediately; git sources create WIP checkpoint commits).' },
|
|
1011
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1012
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1013
|
+
},
|
|
1014
|
+
},
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
name: 'apply_cluster',
|
|
1018
|
+
description: 'Upsert a cluster-style nested document — the same shape as cluster YAML: root node fields (id, template, properties, state/stability) plus owned sections keyed by child local name, with child properties flattened at the top level of each child. Requires an open session (start_changes).\n\nmode "merge": updates only what the document mentions — absent children and absent owned sections are left untouched (a null property value clears that key).\n\nmode "replace": WARNING — the document becomes AUTHORITATIVE for every owned section of the root\'s template. Children absent from the document are DELETED, and an ABSENT owned section means an EMPTY section: ALL of its children are DELETED (soft delete with state removed when the node exists on the default branch, hard purge otherwise). Only use replace with the complete intended contents of the cluster.\n\nA changed child key is NEVER treated as a rename: it is delete+add, and the response carries a possible-rename warning when a replace deletes and creates children with the same template under the same parent. To rename, use rename_node — it is the only rename path. Sections the template does not declare as owned are never touched.',
|
|
1019
|
+
inputSchema: {
|
|
1020
|
+
type: 'object',
|
|
1021
|
+
required: ['document', 'mode'],
|
|
1022
|
+
properties: {
|
|
1023
|
+
document: { type: 'object', description: 'Cluster-style document (root node plus owned sections with named children).' },
|
|
1024
|
+
mode: { type: 'string', enum: ['merge', 'replace'], description: 'merge: update what is present, leave the rest. replace: document is authoritative for owned sections — absent children/sections are DELETED.' },
|
|
1025
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1026
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
name: 'create_node',
|
|
1032
|
+
description: 'Create a root cluster (omit parent_id; document requires id and template) or an owned child under an existing parent (pass parent_id, section, and name; document holds the child body with properties flattened at the top level). Nested owned children in the document are created in the same call and structural edges (has-field, has-value) generate automatically. Defaults: state "proposed", stability "unstable". Requires an open session (start_changes).',
|
|
1033
|
+
inputSchema: {
|
|
1034
|
+
type: 'object',
|
|
1035
|
+
required: ['document'],
|
|
1036
|
+
properties: {
|
|
1037
|
+
document: { type: 'object', description: 'Cluster-style document. Roots: { id, template, properties?, ...ownedSections }. Owned children: the child body (properties flattened, optional nested owned sections).' },
|
|
1038
|
+
parent_id: { type: 'string', description: 'Owning parent node ID — omit to create a root cluster.' },
|
|
1039
|
+
section: { type: 'string', description: 'Owned section under the parent (e.g. "fields", "schemas"); required with parent_id.' },
|
|
1040
|
+
name: { type: 'string', description: 'Local name for the new owned child; required with parent_id.' },
|
|
1041
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1042
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1043
|
+
},
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
name: 'update_node',
|
|
1048
|
+
description: 'Patch a node\'s properties, state, or stability. properties is a patch: only the keys given are changed, and a null value clears that key. Cannot change the node\'s name — that is rename_node (names are identity, never a property edit). Requires an open session (start_changes).',
|
|
1049
|
+
inputSchema: {
|
|
1050
|
+
type: 'object',
|
|
1051
|
+
required: ['id'],
|
|
1052
|
+
properties: {
|
|
1053
|
+
id: { type: 'string', description: 'Fully qualified node ID' },
|
|
1054
|
+
properties: { type: 'object', description: 'Property patch — null clears a key.' },
|
|
1055
|
+
state: { type: 'string', enum: [...STATE_VALUES], description: 'New lifecycle state.' },
|
|
1056
|
+
stability: { type: 'string', enum: [...STABILITY_VALUES], description: 'New stability.' },
|
|
1057
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1058
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1059
|
+
},
|
|
1060
|
+
},
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
name: 'rename_node',
|
|
1064
|
+
description: 'Rename a node (replace the last segment of its ID with new_name). Descendant IDs, parentId fields, and every edge endpoint are rewritten automatically; renaming a cluster root also moves its file at commit. Trail: by default, a rename records corum.identity.previousIds plus a renamed-from edge iff the node exists on the default branch head (i.e. the old name is shared history); record_trail forces (true) or suppresses (false) the trail. This is the ONLY rename path — apply_cluster and imports never infer renames. Requires an open session (start_changes).',
|
|
1065
|
+
inputSchema: {
|
|
1066
|
+
type: 'object',
|
|
1067
|
+
required: ['id', 'new_name'],
|
|
1068
|
+
properties: {
|
|
1069
|
+
id: { type: 'string', description: 'Fully qualified node ID to rename' },
|
|
1070
|
+
new_name: { type: 'string', description: 'New last segment (ID grammar: [A-Za-z0-9_-], no dots).' },
|
|
1071
|
+
record_trail: { type: 'boolean', description: 'Override the trail threshold: true forces recording corum.identity.previousIds + renamed-from; false suppresses it.' },
|
|
1072
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1073
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1074
|
+
},
|
|
1075
|
+
},
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
name: 'delete_node',
|
|
1079
|
+
description: 'Delete a node and its owned subtree. Two tiers: soft delete sets state "removed" on the subtree (nodes stay in YAML and remain queryable); hard delete removes the subtree and every edge touching it. Default tier: soft when the node exists on the default branch head (shared history), hard otherwise (pure design work leaves no tombstones). purge: true always hard-deletes; record_trail overrides the threshold (true forces soft, false forces hard). Requires an open session (start_changes).',
|
|
1080
|
+
inputSchema: {
|
|
1081
|
+
type: 'object',
|
|
1082
|
+
required: ['id'],
|
|
1083
|
+
properties: {
|
|
1084
|
+
id: { type: 'string', description: 'Fully qualified node ID to delete' },
|
|
1085
|
+
purge: { type: 'boolean', description: 'Force hard delete of the subtree and all touching edges. Default false.' },
|
|
1086
|
+
record_trail: { type: 'boolean', description: 'Override the soft/hard threshold: true forces soft delete, false forces hard delete.' },
|
|
1087
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1088
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
{
|
|
1093
|
+
name: 'create_edge',
|
|
1094
|
+
description: 'Create an explicit edge between two nodes. Validated against endpoint existence and the pack edge-type vocabulary; edge-type constraint violations are returned as warnings. Defaults: state "proposed", stability "unstable". Requires an open session (start_changes).',
|
|
1095
|
+
inputSchema: {
|
|
1096
|
+
type: 'object',
|
|
1097
|
+
required: ['from', 'to', 'type'],
|
|
1098
|
+
properties: {
|
|
1099
|
+
from: { type: 'string', description: 'Source node ID' },
|
|
1100
|
+
to: { type: 'string', description: 'Target node ID' },
|
|
1101
|
+
type: { type: 'string', description: 'Edge type (see get_graph_metadata valid_edge_types).' },
|
|
1102
|
+
state: { type: 'string', enum: [...STATE_VALUES], description: 'Lifecycle state. Default "proposed".' },
|
|
1103
|
+
stability: { type: 'string', enum: [...STABILITY_VALUES], description: 'Stability. Default "unstable".' },
|
|
1104
|
+
notes: { type: 'string', description: 'Free-text notes on the edge.' },
|
|
1105
|
+
properties: { type: 'object', description: 'Edge properties (validated against the pack edge-type schema).' },
|
|
1106
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1107
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1108
|
+
},
|
|
1109
|
+
},
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
name: 'update_edge',
|
|
1113
|
+
description: 'Patch an explicit edge\'s state, stability, notes, or properties. Endpoints and type are IMMUTABLE — delete_edge and create_edge instead. notes: null clears the notes; a null property value clears that key. Requires an open session (start_changes).',
|
|
1114
|
+
inputSchema: {
|
|
1115
|
+
type: 'object',
|
|
1116
|
+
required: ['id'],
|
|
1117
|
+
properties: {
|
|
1118
|
+
id: { type: 'string', description: 'Edge ID ({from}__{type}__{to})' },
|
|
1119
|
+
state: { type: 'string', enum: [...STATE_VALUES], description: 'New lifecycle state.' },
|
|
1120
|
+
stability: { type: 'string', enum: [...STABILITY_VALUES], description: 'New stability.' },
|
|
1121
|
+
notes: { description: 'New notes; null clears them.' },
|
|
1122
|
+
properties: { type: 'object', description: 'Property patch — null clears a key.' },
|
|
1123
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1124
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1125
|
+
},
|
|
1126
|
+
},
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
name: 'delete_edge',
|
|
1130
|
+
description: 'Delete an edge. Always a hard removal — edges carry no subtree. To soft-remove a relationship instead, use update_edge with state "removed". Requires an open session (start_changes).',
|
|
1131
|
+
inputSchema: {
|
|
1132
|
+
type: 'object',
|
|
1133
|
+
required: ['id'],
|
|
1134
|
+
properties: {
|
|
1135
|
+
id: { type: 'string', description: 'Edge ID ({from}__{type}__{to})' },
|
|
1136
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1137
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1138
|
+
},
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
name: 'pending_changes',
|
|
1143
|
+
description: 'Show the open session\'s change journal and a summary diff (added/modified/removed node and edge counts) of the working graph against the session base. Requires an open session (start_changes).',
|
|
1144
|
+
inputSchema: {
|
|
1145
|
+
type: 'object',
|
|
1146
|
+
properties: {
|
|
1147
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1148
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1149
|
+
},
|
|
1150
|
+
},
|
|
1151
|
+
},
|
|
1152
|
+
{
|
|
1153
|
+
name: 'discard_changes',
|
|
1154
|
+
description: 'Abort the working session without committing. With the default autosave OFF, this drops the in-memory session changes. Note: if autosave was turned ON for a file source, mutations already written to disk are NOT rolled back. Requires an open session (start_changes).',
|
|
1155
|
+
inputSchema: {
|
|
1156
|
+
type: 'object',
|
|
1157
|
+
properties: {
|
|
1158
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1159
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1160
|
+
},
|
|
1161
|
+
},
|
|
1162
|
+
},
|
|
1163
|
+
{
|
|
1164
|
+
name: 'commit_changes',
|
|
1165
|
+
description: 'Lint, serialise, and commit the working graph, then close the session. The full linter runs first: error diagnostics BLOCK the commit (the session stays open to fix and retry); warnings ride along. Default message summarises the journal. Git autosave sessions squash their "corum-wip:" checkpoint run into a single commit when no external commit interleaved (otherwise the final commit lands on top and checkpoints are preserved); file-source autosave sessions have already persisted each mutation, so commit_changes just closes the session. Fails if the branch head moved externally since session start.',
|
|
1166
|
+
inputSchema: {
|
|
1167
|
+
type: 'object',
|
|
1168
|
+
properties: {
|
|
1169
|
+
message: { type: 'string', description: 'Commit message. Default: a summary of the session journal.' },
|
|
1170
|
+
format: { type: 'string', enum: ['yaml', 'json', 'toon'], description: 'Output format. Defaults to yaml.' },
|
|
1171
|
+
compact_keys: { type: 'boolean', description: 'Use compact graph keys in the selected output format.' },
|
|
1172
|
+
},
|
|
1173
|
+
},
|
|
1174
|
+
},
|
|
773
1175
|
];
|
|
774
1176
|
}
|
|
775
1177
|
export async function startMcpServer(options = {}) {
|
|
@@ -865,6 +1267,30 @@ export async function startMcpServer(options = {}) {
|
|
|
865
1267
|
return await handlers.list_branches(args);
|
|
866
1268
|
case 'diff_branch':
|
|
867
1269
|
return await handlers.diff_branch(args);
|
|
1270
|
+
case 'start_changes':
|
|
1271
|
+
return await handlers.start_changes(args);
|
|
1272
|
+
case 'apply_cluster':
|
|
1273
|
+
return await handlers.apply_cluster(args);
|
|
1274
|
+
case 'create_node':
|
|
1275
|
+
return await handlers.create_node(args);
|
|
1276
|
+
case 'update_node':
|
|
1277
|
+
return await handlers.update_node(args);
|
|
1278
|
+
case 'rename_node':
|
|
1279
|
+
return await handlers.rename_node(args);
|
|
1280
|
+
case 'delete_node':
|
|
1281
|
+
return await handlers.delete_node(args);
|
|
1282
|
+
case 'create_edge':
|
|
1283
|
+
return await handlers.create_edge(args);
|
|
1284
|
+
case 'update_edge':
|
|
1285
|
+
return await handlers.update_edge(args);
|
|
1286
|
+
case 'delete_edge':
|
|
1287
|
+
return await handlers.delete_edge(args);
|
|
1288
|
+
case 'pending_changes':
|
|
1289
|
+
return await handlers.pending_changes(args);
|
|
1290
|
+
case 'discard_changes':
|
|
1291
|
+
return await handlers.discard_changes(args);
|
|
1292
|
+
case 'commit_changes':
|
|
1293
|
+
return await handlers.commit_changes(args);
|
|
868
1294
|
default:
|
|
869
1295
|
return { content: [{ type: 'text', text: `Unknown tool: ${request.params.name}` }], isError: true };
|
|
870
1296
|
}
|