mindgraph-mcp 0.1.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/dist/index.js ADDED
@@ -0,0 +1,1147 @@
1
+ "use strict";
2
+
3
+ // src/index.ts
4
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
5
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
6
+ var import_types = require("@modelcontextprotocol/sdk/types.js");
7
+ var import_mindgraph = require("mindgraph");
8
+
9
+ // src/tools.ts
10
+ var TOOLS = [
11
+ {
12
+ name: "mindgraph_session",
13
+ description: "Open, trace, or close a memory session. Sessions group related interactions and enable context continuity. Open a session at the start of a conversation, trace key moments during it, and close it at the end to trigger distillation.",
14
+ inputSchema: {
15
+ type: "object",
16
+ properties: {
17
+ action: {
18
+ type: "string",
19
+ enum: ["open", "trace", "close"],
20
+ description: "Session lifecycle action"
21
+ },
22
+ label: {
23
+ type: "string",
24
+ description: "Session or trace label (required for open/trace)"
25
+ },
26
+ session_uid: {
27
+ type: "string",
28
+ description: "Session UID (required for trace/close)"
29
+ },
30
+ summary: {
31
+ type: "string",
32
+ description: "Session summary (used on close)"
33
+ },
34
+ props: {
35
+ type: "object",
36
+ description: "Additional properties"
37
+ },
38
+ agent_id: {
39
+ type: "string",
40
+ description: "Agent identity for multi-agent systems"
41
+ }
42
+ },
43
+ required: ["action"]
44
+ }
45
+ },
46
+ {
47
+ name: "mindgraph_journal",
48
+ description: "Low-friction capture of observations, notes, preferences, and reflections. Creates a Journal node in the Memory layer. Use this for quick thoughts, user preferences, mood tracking, and daily notes that don't fit a formal structure.",
49
+ inputSchema: {
50
+ type: "object",
51
+ properties: {
52
+ label: {
53
+ type: "string",
54
+ description: "Brief title for the journal entry"
55
+ },
56
+ content: {
57
+ type: "string",
58
+ description: "The journal content/body text"
59
+ },
60
+ mood: {
61
+ type: "string",
62
+ description: "Emotional tone or mood tag"
63
+ },
64
+ tags: {
65
+ type: "array",
66
+ items: { type: "string" },
67
+ description: "Categorization tags"
68
+ },
69
+ session_uid: {
70
+ type: "string",
71
+ description: "Link to an active session"
72
+ },
73
+ agent_id: {
74
+ type: "string",
75
+ description: "Agent identity"
76
+ }
77
+ },
78
+ required: ["label", "content"]
79
+ }
80
+ },
81
+ {
82
+ name: "mindgraph_capture",
83
+ description: "Capture entities, observations, concepts, sources, and snippets into the Reality layer with automatic deduplication. Use 'entity' for people, organizations, places, events, nations, or abstract concepts. Use 'observation' for factual observations. Use 'source' for documents or references. Use 'snippet' for direct quotes linked to a source.",
84
+ inputSchema: {
85
+ type: "object",
86
+ properties: {
87
+ action: {
88
+ type: "string",
89
+ enum: ["entity", "observation", "source", "snippet", "concept"],
90
+ description: "Type of reality to capture"
91
+ },
92
+ label: {
93
+ type: "string",
94
+ description: "Name or title"
95
+ },
96
+ summary: {
97
+ type: "string",
98
+ description: "Description or summary text"
99
+ },
100
+ entity_type: {
101
+ type: "string",
102
+ enum: [
103
+ "person",
104
+ "organization",
105
+ "place",
106
+ "event",
107
+ "nation",
108
+ "concept"
109
+ ],
110
+ description: "Entity subtype (only for action=entity)"
111
+ },
112
+ source_uid: {
113
+ type: "string",
114
+ description: "Source node UID (for snippets)"
115
+ },
116
+ confidence: {
117
+ type: "number",
118
+ minimum: 0,
119
+ maximum: 1,
120
+ description: "Confidence score (0-1)"
121
+ },
122
+ salience: {
123
+ type: "number",
124
+ minimum: 0,
125
+ maximum: 1,
126
+ description: "Importance/salience score (0-1)"
127
+ },
128
+ props: {
129
+ type: "object",
130
+ description: "Type-specific properties (e.g. birth_date for person, coordinates for place)"
131
+ },
132
+ agent_id: {
133
+ type: "string",
134
+ description: "Agent identity"
135
+ }
136
+ },
137
+ required: ["action", "label"]
138
+ }
139
+ },
140
+ {
141
+ name: "mindgraph_argue",
142
+ description: "Construct a structured argument with claims, evidence, warrants, and rebuttals. Creates interconnected Epistemic layer nodes. Use this when you need to record or evaluate a reasoned position with supporting evidence and logical connections.",
143
+ inputSchema: {
144
+ type: "object",
145
+ properties: {
146
+ claim: {
147
+ type: "object",
148
+ properties: {
149
+ label: { type: "string", description: "Claim statement" },
150
+ content: { type: "string", description: "Detailed claim content" },
151
+ confidence: {
152
+ type: "number",
153
+ minimum: 0,
154
+ maximum: 1,
155
+ description: "How likely this claim is true (0-1)"
156
+ }
157
+ },
158
+ required: ["label"],
159
+ description: "The central claim being argued"
160
+ },
161
+ evidence: {
162
+ type: "array",
163
+ items: {
164
+ type: "object",
165
+ properties: {
166
+ label: { type: "string" },
167
+ description: { type: "string" }
168
+ },
169
+ required: ["label"]
170
+ },
171
+ description: "Supporting evidence items"
172
+ },
173
+ warrant: {
174
+ type: "object",
175
+ properties: {
176
+ label: { type: "string" },
177
+ content: { type: "string" }
178
+ },
179
+ description: "Logical warrant connecting evidence to claim"
180
+ },
181
+ argument: {
182
+ type: "object",
183
+ properties: {
184
+ label: { type: "string" }
185
+ },
186
+ description: "Top-level argument container"
187
+ },
188
+ agent_id: {
189
+ type: "string",
190
+ description: "Agent identity"
191
+ }
192
+ },
193
+ required: ["claim"]
194
+ }
195
+ },
196
+ {
197
+ name: "mindgraph_inquire",
198
+ description: "Record questions, hypotheses, theories, anomalies, assumptions, and paradigms in the Epistemic layer. Use this to track open questions worth investigating, form testable hypotheses, flag anomalies that challenge existing understanding, or articulate theoretical frameworks.",
199
+ inputSchema: {
200
+ type: "object",
201
+ properties: {
202
+ action: {
203
+ type: "string",
204
+ enum: [
205
+ "question",
206
+ "open_question",
207
+ "hypothesis",
208
+ "theory",
209
+ "paradigm",
210
+ "anomaly",
211
+ "assumption"
212
+ ],
213
+ description: "Type of epistemic inquiry"
214
+ },
215
+ label: {
216
+ type: "string",
217
+ description: "The question, hypothesis, or theory statement"
218
+ },
219
+ summary: {
220
+ type: "string",
221
+ description: "Expanded description or context"
222
+ },
223
+ confidence: {
224
+ type: "number",
225
+ minimum: 0,
226
+ maximum: 1,
227
+ description: "Confidence level (0-1)"
228
+ },
229
+ salience: {
230
+ type: "number",
231
+ minimum: 0,
232
+ maximum: 1,
233
+ description: "Importance score (0-1)"
234
+ },
235
+ props: {
236
+ type: "object",
237
+ description: "Type-specific properties"
238
+ },
239
+ agent_id: {
240
+ type: "string",
241
+ description: "Agent identity"
242
+ }
243
+ },
244
+ required: ["action", "label"]
245
+ }
246
+ },
247
+ {
248
+ name: "mindgraph_commit",
249
+ description: "Create goals, projects, and milestones in the Intent layer. Use 'goal' for desired outcomes, 'project' for organized efforts toward goals, and 'milestone' for measurable checkpoints within projects.",
250
+ inputSchema: {
251
+ type: "object",
252
+ properties: {
253
+ action: {
254
+ type: "string",
255
+ enum: ["goal", "project", "milestone"],
256
+ description: "Type of commitment"
257
+ },
258
+ label: {
259
+ type: "string",
260
+ description: "Name of the goal, project, or milestone"
261
+ },
262
+ summary: {
263
+ type: "string",
264
+ description: "Description and success criteria"
265
+ },
266
+ parent_uid: {
267
+ type: "string",
268
+ description: "Parent goal/project UID to link under"
269
+ },
270
+ confidence: {
271
+ type: "number",
272
+ minimum: 0,
273
+ maximum: 1
274
+ },
275
+ salience: {
276
+ type: "number",
277
+ minimum: 0,
278
+ maximum: 1
279
+ },
280
+ props: {
281
+ type: "object",
282
+ description: "Type-specific properties (e.g. status, priority, deadline, horizon for goals)"
283
+ },
284
+ agent_id: {
285
+ type: "string",
286
+ description: "Agent identity"
287
+ }
288
+ },
289
+ required: ["action", "label"]
290
+ }
291
+ },
292
+ {
293
+ name: "mindgraph_decide",
294
+ description: "Manage decisions through their full lifecycle: open a decision, add options and constraints, then resolve by choosing an option. Use 'get_open' to list all unresolved decisions.",
295
+ inputSchema: {
296
+ type: "object",
297
+ properties: {
298
+ action: {
299
+ type: "string",
300
+ enum: ["open_decision", "add_option", "add_constraint", "resolve", "get_open"],
301
+ description: "Decision lifecycle action"
302
+ },
303
+ label: {
304
+ type: "string",
305
+ description: "Decision, option, or constraint label"
306
+ },
307
+ summary: {
308
+ type: "string",
309
+ description: "Description or rationale"
310
+ },
311
+ decision_uid: {
312
+ type: "string",
313
+ description: "Decision UID (for add_option, add_constraint, resolve)"
314
+ },
315
+ chosen_option_uid: {
316
+ type: "string",
317
+ description: "UID of the chosen option (for resolve)"
318
+ },
319
+ props: {
320
+ type: "object",
321
+ description: "Additional properties"
322
+ },
323
+ agent_id: {
324
+ type: "string",
325
+ description: "Agent identity"
326
+ }
327
+ },
328
+ required: ["action"]
329
+ }
330
+ },
331
+ {
332
+ name: "mindgraph_action",
333
+ description: "Record procedural knowledge (workflows, steps, affordances, controls) and risk assessments in the Action layer. Use this for SOPs, runbooks, capability mappings, and risk analysis.",
334
+ inputSchema: {
335
+ type: "object",
336
+ properties: {
337
+ action: {
338
+ type: "string",
339
+ enum: [
340
+ "create_flow",
341
+ "add_step",
342
+ "add_affordance",
343
+ "add_control",
344
+ "assess_risk",
345
+ "get_assessments"
346
+ ],
347
+ description: "Action layer operation"
348
+ },
349
+ label: {
350
+ type: "string",
351
+ description: "Flow, step, affordance, control, or risk label"
352
+ },
353
+ summary: {
354
+ type: "string",
355
+ description: "Description"
356
+ },
357
+ target_uid: {
358
+ type: "string",
359
+ description: "Parent flow/step UID or target node for risk assessment"
360
+ },
361
+ props: {
362
+ type: "object",
363
+ description: "Type-specific properties (e.g. likelihood, impact, mitigation for risks)"
364
+ },
365
+ agent_id: {
366
+ type: "string",
367
+ description: "Agent identity"
368
+ }
369
+ },
370
+ required: ["action"]
371
+ }
372
+ },
373
+ {
374
+ name: "mindgraph_plan",
375
+ description: "Create and manage plans, tasks, execution tracking, and governance policies in the Agent layer. Supports full task lifecycle from creation through completion, plan hierarchies, and approval workflows.",
376
+ inputSchema: {
377
+ type: "object",
378
+ properties: {
379
+ action: {
380
+ type: "string",
381
+ enum: [
382
+ "create_task",
383
+ "create_plan",
384
+ "add_step",
385
+ "update_status",
386
+ "get_plan",
387
+ "start_execution",
388
+ "complete_execution",
389
+ "fail_execution",
390
+ "create_policy",
391
+ "request_approval",
392
+ "resolve_approval",
393
+ "get_pending"
394
+ ],
395
+ description: "Agent layer operation"
396
+ },
397
+ label: {
398
+ type: "string",
399
+ description: "Task, plan, step, or policy label"
400
+ },
401
+ summary: {
402
+ type: "string",
403
+ description: "Description"
404
+ },
405
+ plan_uid: {
406
+ type: "string",
407
+ description: "Plan UID (for add_step, get_plan)"
408
+ },
409
+ task_uid: {
410
+ type: "string",
411
+ description: "Task/step UID (for update_status, execution actions)"
412
+ },
413
+ status: {
414
+ type: "string",
415
+ description: "New status value (for update_status)"
416
+ },
417
+ props: {
418
+ type: "object",
419
+ description: "Additional properties"
420
+ },
421
+ agent_id: {
422
+ type: "string",
423
+ description: "Agent identity"
424
+ }
425
+ },
426
+ required: ["action"]
427
+ }
428
+ },
429
+ {
430
+ name: "mindgraph_retrieve",
431
+ description: "Search and query the knowledge graph. Supports hybrid (text + semantic) search, active goals, open questions, weak claims, pending approvals, contradictions, layer-filtered retrieval, and rich context retrieval that follows graph edges from matching chunks.",
432
+ inputSchema: {
433
+ type: "object",
434
+ properties: {
435
+ action: {
436
+ type: "string",
437
+ enum: [
438
+ "hybrid",
439
+ "semantic",
440
+ "text",
441
+ "context",
442
+ "active_goals",
443
+ "open_questions",
444
+ "weak_claims",
445
+ "pending_approvals",
446
+ "unresolved_contradictions",
447
+ "layer",
448
+ "recent"
449
+ ],
450
+ description: "Retrieval strategy"
451
+ },
452
+ query: {
453
+ type: "string",
454
+ description: "Search query (for hybrid, semantic, text, context)"
455
+ },
456
+ layer: {
457
+ type: "string",
458
+ enum: [
459
+ "reality",
460
+ "epistemic",
461
+ "intent",
462
+ "action",
463
+ "memory",
464
+ "agent"
465
+ ],
466
+ description: "Layer filter (for layer action)"
467
+ },
468
+ limit: {
469
+ type: "number",
470
+ description: "Max results to return (default: 10)"
471
+ },
472
+ node_type: {
473
+ type: "string",
474
+ description: "Filter by node type"
475
+ },
476
+ agent_id: {
477
+ type: "string",
478
+ description: "Agent identity"
479
+ }
480
+ },
481
+ required: ["action"]
482
+ }
483
+ },
484
+ {
485
+ name: "mindgraph_ingest",
486
+ description: "Ingest long-form content into the knowledge graph. Supports single chunks (synchronous), full documents (async with job tracking), and session transcripts. The ingestion pipeline automatically extracts entities, claims, relationships, and structures across cognitive layers.",
487
+ inputSchema: {
488
+ type: "object",
489
+ properties: {
490
+ action: {
491
+ type: "string",
492
+ enum: ["chunk", "document", "session", "job_status"],
493
+ description: "Ingestion action"
494
+ },
495
+ content: {
496
+ type: "string",
497
+ description: "Text content to ingest (for chunk/document/session)"
498
+ },
499
+ title: {
500
+ type: "string",
501
+ description: "Document or session title"
502
+ },
503
+ source: {
504
+ type: "string",
505
+ description: "Source URL or reference"
506
+ },
507
+ layers: {
508
+ type: "array",
509
+ items: {
510
+ type: "string",
511
+ enum: [
512
+ "reality",
513
+ "epistemic",
514
+ "intent",
515
+ "action",
516
+ "memory",
517
+ "agent"
518
+ ]
519
+ },
520
+ description: "Cognitive layers to extract (defaults vary by action)"
521
+ },
522
+ chunk_size: {
523
+ type: "number",
524
+ description: "Characters per chunk for document ingestion (default: 4000)"
525
+ },
526
+ chunk_overlap: {
527
+ type: "number",
528
+ description: "Overlap between chunks (default: 200)"
529
+ },
530
+ job_id: {
531
+ type: "string",
532
+ description: "Job ID to check status (for job_status action)"
533
+ },
534
+ agent_id: {
535
+ type: "string",
536
+ description: "Agent identity"
537
+ }
538
+ },
539
+ required: ["action"]
540
+ }
541
+ }
542
+ ];
543
+ function ok(data) {
544
+ return {
545
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
546
+ };
547
+ }
548
+ function err(message) {
549
+ return {
550
+ content: [{ type: "text", text: JSON.stringify({ error: message }) }],
551
+ isError: true
552
+ };
553
+ }
554
+ async function handleTool(client2, name, args) {
555
+ try {
556
+ switch (name) {
557
+ case "mindgraph_session":
558
+ return await handleSession(client2, args);
559
+ case "mindgraph_journal":
560
+ return await handleJournal(client2, args);
561
+ case "mindgraph_capture":
562
+ return await handleCapture(client2, args);
563
+ case "mindgraph_argue":
564
+ return await handleArgue(client2, args);
565
+ case "mindgraph_inquire":
566
+ return await handleInquire(client2, args);
567
+ case "mindgraph_commit":
568
+ return await handleCommit(client2, args);
569
+ case "mindgraph_decide":
570
+ return await handleDecide(client2, args);
571
+ case "mindgraph_action":
572
+ return await handleAction(client2, args);
573
+ case "mindgraph_plan":
574
+ return await handlePlan(client2, args);
575
+ case "mindgraph_retrieve":
576
+ return await handleRetrieve(client2, args);
577
+ case "mindgraph_ingest":
578
+ return await handleIngest(client2, args);
579
+ default:
580
+ return err(`Unknown tool: ${name}`);
581
+ }
582
+ } catch (e) {
583
+ const message = e instanceof Error ? e.message : String(e);
584
+ return err(message);
585
+ }
586
+ }
587
+ async function handleSession(client2, args) {
588
+ const { action, label, session_uid, summary, props, agent_id } = args;
589
+ switch (action) {
590
+ case "open": {
591
+ if (!label) return err("label is required for open");
592
+ const result = await client2.session({
593
+ action: "open",
594
+ label,
595
+ summary,
596
+ props,
597
+ agent_id
598
+ });
599
+ return ok(result);
600
+ }
601
+ case "trace": {
602
+ if (!session_uid) return err("session_uid is required for trace");
603
+ if (!label) return err("label is required for trace");
604
+ const result = await client2.session({
605
+ action: "trace",
606
+ label,
607
+ session_uid,
608
+ props,
609
+ agent_id
610
+ });
611
+ return ok(result);
612
+ }
613
+ case "close": {
614
+ if (!session_uid) return err("session_uid is required for close");
615
+ const result = await client2.session({
616
+ action: "close",
617
+ session_uid,
618
+ summary,
619
+ agent_id
620
+ });
621
+ return ok(result);
622
+ }
623
+ default:
624
+ return err(`Unknown session action: ${action}`);
625
+ }
626
+ }
627
+ async function handleJournal(client2, args) {
628
+ const { label, content, mood, tags, session_uid, agent_id } = args;
629
+ const props = { content };
630
+ if (mood) props.mood = mood;
631
+ if (tags) props.tags = tags;
632
+ const result = await client2.journal(
633
+ label,
634
+ props,
635
+ { session_uid, agent_id }
636
+ );
637
+ return ok(result);
638
+ }
639
+ async function handleCapture(client2, args) {
640
+ const {
641
+ action,
642
+ label,
643
+ summary,
644
+ entity_type,
645
+ source_uid,
646
+ confidence,
647
+ salience,
648
+ props,
649
+ agent_id
650
+ } = args;
651
+ switch (action) {
652
+ case "entity": {
653
+ const type = entity_type || "concept";
654
+ const entityProps = { ...props };
655
+ if (summary) entityProps.description = summary;
656
+ switch (type) {
657
+ case "person":
658
+ return ok(await client2.findOrCreatePerson(label, entityProps, agent_id));
659
+ case "organization":
660
+ return ok(await client2.findOrCreateOrganization(label, entityProps, agent_id));
661
+ case "nation":
662
+ return ok(await client2.findOrCreateNation(label, entityProps, agent_id));
663
+ case "event":
664
+ return ok(await client2.findOrCreateEvent(label, entityProps, agent_id));
665
+ case "place":
666
+ return ok(await client2.findOrCreatePlace(label, entityProps, agent_id));
667
+ case "concept":
668
+ default:
669
+ return ok(await client2.findOrCreateConcept(label, entityProps, agent_id));
670
+ }
671
+ }
672
+ case "observation":
673
+ return ok(
674
+ await client2.capture({
675
+ action: "observation",
676
+ label,
677
+ summary,
678
+ confidence,
679
+ salience,
680
+ props,
681
+ agent_id
682
+ })
683
+ );
684
+ case "source":
685
+ return ok(
686
+ await client2.capture({
687
+ action: "source",
688
+ label,
689
+ summary,
690
+ confidence,
691
+ salience,
692
+ props,
693
+ agent_id
694
+ })
695
+ );
696
+ case "snippet":
697
+ return ok(
698
+ await client2.capture({
699
+ action: "snippet",
700
+ label,
701
+ summary,
702
+ source_uid,
703
+ confidence,
704
+ salience,
705
+ props,
706
+ agent_id
707
+ })
708
+ );
709
+ case "concept":
710
+ return ok(
711
+ await client2.structure({
712
+ action: "concept",
713
+ label,
714
+ summary,
715
+ confidence,
716
+ salience,
717
+ props,
718
+ agent_id
719
+ })
720
+ );
721
+ default:
722
+ return err(`Unknown capture action: ${action}`);
723
+ }
724
+ }
725
+ async function handleArgue(client2, args) {
726
+ const { claim, evidence, warrant, argument, agent_id } = args;
727
+ const result = await client2.argue({
728
+ claim,
729
+ evidence,
730
+ warrant,
731
+ argument,
732
+ agent_id
733
+ });
734
+ return ok(result);
735
+ }
736
+ async function handleInquire(client2, args) {
737
+ const { action, label, summary, confidence, salience, props, agent_id } = args;
738
+ const result = await client2.inquire({
739
+ action,
740
+ label,
741
+ summary,
742
+ confidence,
743
+ salience,
744
+ props,
745
+ agent_id
746
+ });
747
+ return ok(result);
748
+ }
749
+ async function handleCommit(client2, args) {
750
+ const { action, label, summary, parent_uid, confidence, salience, props, agent_id } = args;
751
+ const result = await client2.commit({
752
+ action,
753
+ label,
754
+ summary,
755
+ parent_uid,
756
+ confidence,
757
+ salience,
758
+ props,
759
+ agent_id
760
+ });
761
+ return ok(result);
762
+ }
763
+ async function handleDecide(client2, args) {
764
+ const { action, label, summary, decision_uid, chosen_option_uid, props, agent_id } = args;
765
+ switch (action) {
766
+ case "open_decision":
767
+ if (!label) return err("label is required for open_decision");
768
+ return ok(await client2.openDecision(label, { summary, props, agent_id }));
769
+ case "add_option":
770
+ if (!decision_uid) return err("decision_uid is required");
771
+ if (!label) return err("label is required for add_option");
772
+ return ok(
773
+ await client2.addOption(decision_uid, label, { summary, props, agent_id })
774
+ );
775
+ case "add_constraint":
776
+ if (!decision_uid) return err("decision_uid is required");
777
+ return ok(
778
+ await client2.deliberate({
779
+ action: "add_constraint",
780
+ label,
781
+ decision_uid,
782
+ summary,
783
+ props,
784
+ agent_id
785
+ })
786
+ );
787
+ case "resolve":
788
+ if (!decision_uid) return err("decision_uid is required");
789
+ if (!chosen_option_uid) return err("chosen_option_uid is required");
790
+ return ok(
791
+ await client2.resolveDecision(decision_uid, chosen_option_uid, {
792
+ summary,
793
+ agent_id
794
+ })
795
+ );
796
+ case "get_open":
797
+ return ok(await client2.getOpenDecisions());
798
+ default:
799
+ return err(`Unknown decide action: ${action}`);
800
+ }
801
+ }
802
+ async function handleAction(client2, args) {
803
+ const { action, label, summary, target_uid, props, agent_id } = args;
804
+ switch (action) {
805
+ case "create_flow":
806
+ case "add_step":
807
+ case "add_affordance":
808
+ case "add_control":
809
+ return ok(
810
+ await client2.procedure({
811
+ action,
812
+ label,
813
+ summary,
814
+ target_uid,
815
+ props,
816
+ agent_id
817
+ })
818
+ );
819
+ case "assess_risk":
820
+ return ok(
821
+ await client2.risk({
822
+ action: "assess",
823
+ label,
824
+ summary,
825
+ target_uid,
826
+ props,
827
+ agent_id
828
+ })
829
+ );
830
+ case "get_assessments":
831
+ return ok(
832
+ await client2.risk({
833
+ action: "get_assessments",
834
+ target_uid,
835
+ agent_id
836
+ })
837
+ );
838
+ default:
839
+ return err(`Unknown action: ${action}`);
840
+ }
841
+ }
842
+ async function handlePlan(client2, args) {
843
+ const { action, label, summary, plan_uid, task_uid, status, props, agent_id } = args;
844
+ switch (action) {
845
+ case "create_task":
846
+ case "create_plan":
847
+ case "add_step":
848
+ case "update_status":
849
+ case "get_plan":
850
+ return ok(
851
+ await client2.plan({
852
+ action,
853
+ label,
854
+ summary,
855
+ plan_uid,
856
+ task_uid,
857
+ status,
858
+ props,
859
+ agent_id
860
+ })
861
+ );
862
+ case "start_execution":
863
+ return ok(
864
+ await client2.execution({
865
+ action: "start",
866
+ task_uid,
867
+ agent_id
868
+ })
869
+ );
870
+ case "complete_execution":
871
+ return ok(
872
+ await client2.execution({
873
+ action: "complete",
874
+ task_uid,
875
+ agent_id
876
+ })
877
+ );
878
+ case "fail_execution":
879
+ return ok(
880
+ await client2.execution({
881
+ action: "fail",
882
+ task_uid,
883
+ agent_id
884
+ })
885
+ );
886
+ case "create_policy":
887
+ return ok(
888
+ await client2.governance({
889
+ action: "create_policy",
890
+ label,
891
+ summary,
892
+ props,
893
+ agent_id
894
+ })
895
+ );
896
+ case "request_approval":
897
+ return ok(
898
+ await client2.governance({
899
+ action: "request_approval",
900
+ label,
901
+ summary,
902
+ props,
903
+ agent_id
904
+ })
905
+ );
906
+ case "resolve_approval":
907
+ return ok(
908
+ await client2.governance({
909
+ action: "resolve_approval",
910
+ task_uid,
911
+ props,
912
+ agent_id
913
+ })
914
+ );
915
+ case "get_pending":
916
+ return ok(
917
+ await client2.governance({
918
+ action: "get_pending",
919
+ agent_id
920
+ })
921
+ );
922
+ default:
923
+ return err(`Unknown plan action: ${action}`);
924
+ }
925
+ }
926
+ async function handleRetrieve(client2, args) {
927
+ const { action, query, layer, limit, node_type, agent_id } = args;
928
+ switch (action) {
929
+ case "context":
930
+ if (!query) return err("query is required for context retrieval");
931
+ return ok(await client2.retrieveContext({ query, k: limit }));
932
+ case "hybrid":
933
+ if (!query) return err("query is required for hybrid search");
934
+ return ok(
935
+ await client2.hybridSearch(query, {
936
+ k: limit,
937
+ node_types: node_type ? [node_type] : void 0
938
+ })
939
+ );
940
+ case "semantic":
941
+ if (!query) return err("query is required for semantic search");
942
+ return ok(
943
+ await client2.retrieve({
944
+ action: "semantic",
945
+ query,
946
+ limit,
947
+ node_type,
948
+ agent_id
949
+ })
950
+ );
951
+ case "text":
952
+ if (!query) return err("query is required for text search");
953
+ return ok(await client2.search(query, { limit, node_type }));
954
+ case "active_goals":
955
+ return ok(await client2.getGoals());
956
+ case "open_questions":
957
+ return ok(await client2.getOpenQuestions());
958
+ case "weak_claims":
959
+ return ok(await client2.getWeakClaims());
960
+ case "pending_approvals":
961
+ return ok(await client2.getPendingApprovals());
962
+ case "unresolved_contradictions":
963
+ return ok(await client2.getContradictions());
964
+ case "layer":
965
+ if (!layer) return err("layer is required for layer retrieval");
966
+ return ok(
967
+ await client2.retrieve({
968
+ action: "layer",
969
+ layer,
970
+ limit,
971
+ agent_id
972
+ })
973
+ );
974
+ case "recent":
975
+ return ok(
976
+ await client2.retrieve({
977
+ action: "recent",
978
+ limit,
979
+ node_type,
980
+ agent_id
981
+ })
982
+ );
983
+ default:
984
+ return err(`Unknown retrieve action: ${action}`);
985
+ }
986
+ }
987
+ async function handleIngest(client2, args) {
988
+ const { action, content, title, source, layers, chunk_size, chunk_overlap, job_id, agent_id } = args;
989
+ switch (action) {
990
+ case "chunk":
991
+ if (!content) return err("content is required for chunk ingestion");
992
+ return ok(
993
+ await client2.ingestChunk({
994
+ content,
995
+ title,
996
+ source,
997
+ layers,
998
+ agent_id
999
+ })
1000
+ );
1001
+ case "document":
1002
+ if (!content) return err("content is required for document ingestion");
1003
+ return ok(
1004
+ await client2.ingestDocument({
1005
+ content,
1006
+ title,
1007
+ source,
1008
+ layers,
1009
+ chunk_size,
1010
+ chunk_overlap,
1011
+ agent_id
1012
+ })
1013
+ );
1014
+ case "session":
1015
+ if (!content) return err("content is required for session ingestion");
1016
+ return ok(
1017
+ await client2.ingestSession({
1018
+ content,
1019
+ title,
1020
+ source,
1021
+ layers,
1022
+ agent_id
1023
+ })
1024
+ );
1025
+ case "job_status":
1026
+ if (job_id) {
1027
+ return ok(await client2.getJob(job_id));
1028
+ }
1029
+ return ok(await client2.listJobs());
1030
+ default:
1031
+ return err(`Unknown ingest action: ${action}`);
1032
+ }
1033
+ }
1034
+
1035
+ // src/index.ts
1036
+ var API_KEY = process.env.MINDGRAPH_API_KEY;
1037
+ var BASE_URL = process.env.MINDGRAPH_BASE_URL || "https://api.mindgraph.cloud";
1038
+ var AGENT_ID = process.env.MINDGRAPH_AGENT_ID || "mcp";
1039
+ if (!API_KEY) {
1040
+ console.error(
1041
+ "Error: MINDGRAPH_API_KEY environment variable is required.\nGet your API key at https://mindgraph.cloud/dashboard/keys"
1042
+ );
1043
+ process.exit(1);
1044
+ }
1045
+ var client = new import_mindgraph.MindGraph({
1046
+ baseUrl: BASE_URL,
1047
+ apiKey: API_KEY
1048
+ });
1049
+ var server = new import_server.Server(
1050
+ {
1051
+ name: "mindgraph",
1052
+ version: "0.1.0"
1053
+ },
1054
+ {
1055
+ capabilities: {
1056
+ tools: {},
1057
+ resources: {}
1058
+ }
1059
+ }
1060
+ );
1061
+ server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
1062
+ return { tools: TOOLS };
1063
+ });
1064
+ server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
1065
+ const { name, arguments: args } = request.params;
1066
+ const toolArgs = { ...args || {} };
1067
+ if (!toolArgs.agent_id) {
1068
+ toolArgs.agent_id = AGENT_ID;
1069
+ }
1070
+ return handleTool(client, name, toolArgs);
1071
+ });
1072
+ server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
1073
+ return {
1074
+ resources: [
1075
+ {
1076
+ uri: "mindgraph://stats",
1077
+ name: "Graph Statistics",
1078
+ description: "Current knowledge graph statistics: node counts, edge counts, and layer distribution",
1079
+ mimeType: "application/json"
1080
+ },
1081
+ {
1082
+ uri: "mindgraph://goals",
1083
+ name: "Active Goals",
1084
+ description: "All active goals in the knowledge graph",
1085
+ mimeType: "application/json"
1086
+ },
1087
+ {
1088
+ uri: "mindgraph://questions",
1089
+ name: "Open Questions",
1090
+ description: "All open questions in the knowledge graph",
1091
+ mimeType: "application/json"
1092
+ }
1093
+ ]
1094
+ };
1095
+ });
1096
+ server.setRequestHandler(import_types.ReadResourceRequestSchema, async (request) => {
1097
+ const { uri } = request.params;
1098
+ switch (uri) {
1099
+ case "mindgraph://stats": {
1100
+ const stats = await client.stats();
1101
+ return {
1102
+ contents: [
1103
+ {
1104
+ uri,
1105
+ mimeType: "application/json",
1106
+ text: JSON.stringify(stats, null, 2)
1107
+ }
1108
+ ]
1109
+ };
1110
+ }
1111
+ case "mindgraph://goals": {
1112
+ const goals = await client.getGoals();
1113
+ return {
1114
+ contents: [
1115
+ {
1116
+ uri,
1117
+ mimeType: "application/json",
1118
+ text: JSON.stringify(goals, null, 2)
1119
+ }
1120
+ ]
1121
+ };
1122
+ }
1123
+ case "mindgraph://questions": {
1124
+ const questions = await client.getOpenQuestions();
1125
+ return {
1126
+ contents: [
1127
+ {
1128
+ uri,
1129
+ mimeType: "application/json",
1130
+ text: JSON.stringify(questions, null, 2)
1131
+ }
1132
+ ]
1133
+ };
1134
+ }
1135
+ default:
1136
+ throw new Error(`Unknown resource: ${uri}`);
1137
+ }
1138
+ });
1139
+ async function main() {
1140
+ const transport = new import_stdio.StdioServerTransport();
1141
+ await server.connect(transport);
1142
+ console.error("MindGraph MCP server running on stdio");
1143
+ }
1144
+ main().catch((error) => {
1145
+ console.error("Fatal error:", error);
1146
+ process.exit(1);
1147
+ });