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/cli.d.ts +2 -0
- package/dist/cli.js +1549 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1147 -0
- package/package.json +35 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
|
|
29
|
+
// src/tools.ts
|
|
30
|
+
function ok(data) {
|
|
31
|
+
return {
|
|
32
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function err(message) {
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text: JSON.stringify({ error: message }) }],
|
|
38
|
+
isError: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function handleTool(client2, name, args) {
|
|
42
|
+
try {
|
|
43
|
+
switch (name) {
|
|
44
|
+
case "mindgraph_session":
|
|
45
|
+
return await handleSession(client2, args);
|
|
46
|
+
case "mindgraph_journal":
|
|
47
|
+
return await handleJournal(client2, args);
|
|
48
|
+
case "mindgraph_capture":
|
|
49
|
+
return await handleCapture(client2, args);
|
|
50
|
+
case "mindgraph_argue":
|
|
51
|
+
return await handleArgue(client2, args);
|
|
52
|
+
case "mindgraph_inquire":
|
|
53
|
+
return await handleInquire(client2, args);
|
|
54
|
+
case "mindgraph_commit":
|
|
55
|
+
return await handleCommit(client2, args);
|
|
56
|
+
case "mindgraph_decide":
|
|
57
|
+
return await handleDecide(client2, args);
|
|
58
|
+
case "mindgraph_action":
|
|
59
|
+
return await handleAction(client2, args);
|
|
60
|
+
case "mindgraph_plan":
|
|
61
|
+
return await handlePlan(client2, args);
|
|
62
|
+
case "mindgraph_retrieve":
|
|
63
|
+
return await handleRetrieve(client2, args);
|
|
64
|
+
case "mindgraph_ingest":
|
|
65
|
+
return await handleIngest(client2, args);
|
|
66
|
+
default:
|
|
67
|
+
return err(`Unknown tool: ${name}`);
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
71
|
+
return err(message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function handleSession(client2, args) {
|
|
75
|
+
const { action, label, session_uid, summary, props, agent_id } = args;
|
|
76
|
+
switch (action) {
|
|
77
|
+
case "open": {
|
|
78
|
+
if (!label) return err("label is required for open");
|
|
79
|
+
const result = await client2.session({
|
|
80
|
+
action: "open",
|
|
81
|
+
label,
|
|
82
|
+
summary,
|
|
83
|
+
props,
|
|
84
|
+
agent_id
|
|
85
|
+
});
|
|
86
|
+
return ok(result);
|
|
87
|
+
}
|
|
88
|
+
case "trace": {
|
|
89
|
+
if (!session_uid) return err("session_uid is required for trace");
|
|
90
|
+
if (!label) return err("label is required for trace");
|
|
91
|
+
const result = await client2.session({
|
|
92
|
+
action: "trace",
|
|
93
|
+
label,
|
|
94
|
+
session_uid,
|
|
95
|
+
props,
|
|
96
|
+
agent_id
|
|
97
|
+
});
|
|
98
|
+
return ok(result);
|
|
99
|
+
}
|
|
100
|
+
case "close": {
|
|
101
|
+
if (!session_uid) return err("session_uid is required for close");
|
|
102
|
+
const result = await client2.session({
|
|
103
|
+
action: "close",
|
|
104
|
+
session_uid,
|
|
105
|
+
summary,
|
|
106
|
+
agent_id
|
|
107
|
+
});
|
|
108
|
+
return ok(result);
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
return err(`Unknown session action: ${action}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function handleJournal(client2, args) {
|
|
115
|
+
const { label, content, mood, tags, session_uid, agent_id } = args;
|
|
116
|
+
const props = { content };
|
|
117
|
+
if (mood) props.mood = mood;
|
|
118
|
+
if (tags) props.tags = tags;
|
|
119
|
+
const result = await client2.journal(
|
|
120
|
+
label,
|
|
121
|
+
props,
|
|
122
|
+
{ session_uid, agent_id }
|
|
123
|
+
);
|
|
124
|
+
return ok(result);
|
|
125
|
+
}
|
|
126
|
+
async function handleCapture(client2, args) {
|
|
127
|
+
const {
|
|
128
|
+
action,
|
|
129
|
+
label,
|
|
130
|
+
summary,
|
|
131
|
+
entity_type,
|
|
132
|
+
source_uid,
|
|
133
|
+
confidence,
|
|
134
|
+
salience,
|
|
135
|
+
props,
|
|
136
|
+
agent_id
|
|
137
|
+
} = args;
|
|
138
|
+
switch (action) {
|
|
139
|
+
case "entity": {
|
|
140
|
+
const type = entity_type || "concept";
|
|
141
|
+
const entityProps = { ...props };
|
|
142
|
+
if (summary) entityProps.description = summary;
|
|
143
|
+
switch (type) {
|
|
144
|
+
case "person":
|
|
145
|
+
return ok(await client2.findOrCreatePerson(label, entityProps, agent_id));
|
|
146
|
+
case "organization":
|
|
147
|
+
return ok(await client2.findOrCreateOrganization(label, entityProps, agent_id));
|
|
148
|
+
case "nation":
|
|
149
|
+
return ok(await client2.findOrCreateNation(label, entityProps, agent_id));
|
|
150
|
+
case "event":
|
|
151
|
+
return ok(await client2.findOrCreateEvent(label, entityProps, agent_id));
|
|
152
|
+
case "place":
|
|
153
|
+
return ok(await client2.findOrCreatePlace(label, entityProps, agent_id));
|
|
154
|
+
case "concept":
|
|
155
|
+
default:
|
|
156
|
+
return ok(await client2.findOrCreateConcept(label, entityProps, agent_id));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
case "observation":
|
|
160
|
+
return ok(
|
|
161
|
+
await client2.capture({
|
|
162
|
+
action: "observation",
|
|
163
|
+
label,
|
|
164
|
+
summary,
|
|
165
|
+
confidence,
|
|
166
|
+
salience,
|
|
167
|
+
props,
|
|
168
|
+
agent_id
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
case "source":
|
|
172
|
+
return ok(
|
|
173
|
+
await client2.capture({
|
|
174
|
+
action: "source",
|
|
175
|
+
label,
|
|
176
|
+
summary,
|
|
177
|
+
confidence,
|
|
178
|
+
salience,
|
|
179
|
+
props,
|
|
180
|
+
agent_id
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
case "snippet":
|
|
184
|
+
return ok(
|
|
185
|
+
await client2.capture({
|
|
186
|
+
action: "snippet",
|
|
187
|
+
label,
|
|
188
|
+
summary,
|
|
189
|
+
source_uid,
|
|
190
|
+
confidence,
|
|
191
|
+
salience,
|
|
192
|
+
props,
|
|
193
|
+
agent_id
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
case "concept":
|
|
197
|
+
return ok(
|
|
198
|
+
await client2.structure({
|
|
199
|
+
action: "concept",
|
|
200
|
+
label,
|
|
201
|
+
summary,
|
|
202
|
+
confidence,
|
|
203
|
+
salience,
|
|
204
|
+
props,
|
|
205
|
+
agent_id
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
default:
|
|
209
|
+
return err(`Unknown capture action: ${action}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function handleArgue(client2, args) {
|
|
213
|
+
const { claim, evidence, warrant, argument, agent_id } = args;
|
|
214
|
+
const result = await client2.argue({
|
|
215
|
+
claim,
|
|
216
|
+
evidence,
|
|
217
|
+
warrant,
|
|
218
|
+
argument,
|
|
219
|
+
agent_id
|
|
220
|
+
});
|
|
221
|
+
return ok(result);
|
|
222
|
+
}
|
|
223
|
+
async function handleInquire(client2, args) {
|
|
224
|
+
const { action, label, summary, confidence, salience, props, agent_id } = args;
|
|
225
|
+
const result = await client2.inquire({
|
|
226
|
+
action,
|
|
227
|
+
label,
|
|
228
|
+
summary,
|
|
229
|
+
confidence,
|
|
230
|
+
salience,
|
|
231
|
+
props,
|
|
232
|
+
agent_id
|
|
233
|
+
});
|
|
234
|
+
return ok(result);
|
|
235
|
+
}
|
|
236
|
+
async function handleCommit(client2, args) {
|
|
237
|
+
const { action, label, summary, parent_uid, confidence, salience, props, agent_id } = args;
|
|
238
|
+
const result = await client2.commit({
|
|
239
|
+
action,
|
|
240
|
+
label,
|
|
241
|
+
summary,
|
|
242
|
+
parent_uid,
|
|
243
|
+
confidence,
|
|
244
|
+
salience,
|
|
245
|
+
props,
|
|
246
|
+
agent_id
|
|
247
|
+
});
|
|
248
|
+
return ok(result);
|
|
249
|
+
}
|
|
250
|
+
async function handleDecide(client2, args) {
|
|
251
|
+
const { action, label, summary, decision_uid, chosen_option_uid, props, agent_id } = args;
|
|
252
|
+
switch (action) {
|
|
253
|
+
case "open_decision":
|
|
254
|
+
if (!label) return err("label is required for open_decision");
|
|
255
|
+
return ok(await client2.openDecision(label, { summary, props, agent_id }));
|
|
256
|
+
case "add_option":
|
|
257
|
+
if (!decision_uid) return err("decision_uid is required");
|
|
258
|
+
if (!label) return err("label is required for add_option");
|
|
259
|
+
return ok(
|
|
260
|
+
await client2.addOption(decision_uid, label, { summary, props, agent_id })
|
|
261
|
+
);
|
|
262
|
+
case "add_constraint":
|
|
263
|
+
if (!decision_uid) return err("decision_uid is required");
|
|
264
|
+
return ok(
|
|
265
|
+
await client2.deliberate({
|
|
266
|
+
action: "add_constraint",
|
|
267
|
+
label,
|
|
268
|
+
decision_uid,
|
|
269
|
+
summary,
|
|
270
|
+
props,
|
|
271
|
+
agent_id
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
case "resolve":
|
|
275
|
+
if (!decision_uid) return err("decision_uid is required");
|
|
276
|
+
if (!chosen_option_uid) return err("chosen_option_uid is required");
|
|
277
|
+
return ok(
|
|
278
|
+
await client2.resolveDecision(decision_uid, chosen_option_uid, {
|
|
279
|
+
summary,
|
|
280
|
+
agent_id
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
case "get_open":
|
|
284
|
+
return ok(await client2.getOpenDecisions());
|
|
285
|
+
default:
|
|
286
|
+
return err(`Unknown decide action: ${action}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function handleAction(client2, args) {
|
|
290
|
+
const { action, label, summary, target_uid, props, agent_id } = args;
|
|
291
|
+
switch (action) {
|
|
292
|
+
case "create_flow":
|
|
293
|
+
case "add_step":
|
|
294
|
+
case "add_affordance":
|
|
295
|
+
case "add_control":
|
|
296
|
+
return ok(
|
|
297
|
+
await client2.procedure({
|
|
298
|
+
action,
|
|
299
|
+
label,
|
|
300
|
+
summary,
|
|
301
|
+
target_uid,
|
|
302
|
+
props,
|
|
303
|
+
agent_id
|
|
304
|
+
})
|
|
305
|
+
);
|
|
306
|
+
case "assess_risk":
|
|
307
|
+
return ok(
|
|
308
|
+
await client2.risk({
|
|
309
|
+
action: "assess",
|
|
310
|
+
label,
|
|
311
|
+
summary,
|
|
312
|
+
target_uid,
|
|
313
|
+
props,
|
|
314
|
+
agent_id
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
case "get_assessments":
|
|
318
|
+
return ok(
|
|
319
|
+
await client2.risk({
|
|
320
|
+
action: "get_assessments",
|
|
321
|
+
target_uid,
|
|
322
|
+
agent_id
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
default:
|
|
326
|
+
return err(`Unknown action: ${action}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function handlePlan(client2, args) {
|
|
330
|
+
const { action, label, summary, plan_uid, task_uid, status, props, agent_id } = args;
|
|
331
|
+
switch (action) {
|
|
332
|
+
case "create_task":
|
|
333
|
+
case "create_plan":
|
|
334
|
+
case "add_step":
|
|
335
|
+
case "update_status":
|
|
336
|
+
case "get_plan":
|
|
337
|
+
return ok(
|
|
338
|
+
await client2.plan({
|
|
339
|
+
action,
|
|
340
|
+
label,
|
|
341
|
+
summary,
|
|
342
|
+
plan_uid,
|
|
343
|
+
task_uid,
|
|
344
|
+
status,
|
|
345
|
+
props,
|
|
346
|
+
agent_id
|
|
347
|
+
})
|
|
348
|
+
);
|
|
349
|
+
case "start_execution":
|
|
350
|
+
return ok(
|
|
351
|
+
await client2.execution({
|
|
352
|
+
action: "start",
|
|
353
|
+
task_uid,
|
|
354
|
+
agent_id
|
|
355
|
+
})
|
|
356
|
+
);
|
|
357
|
+
case "complete_execution":
|
|
358
|
+
return ok(
|
|
359
|
+
await client2.execution({
|
|
360
|
+
action: "complete",
|
|
361
|
+
task_uid,
|
|
362
|
+
agent_id
|
|
363
|
+
})
|
|
364
|
+
);
|
|
365
|
+
case "fail_execution":
|
|
366
|
+
return ok(
|
|
367
|
+
await client2.execution({
|
|
368
|
+
action: "fail",
|
|
369
|
+
task_uid,
|
|
370
|
+
agent_id
|
|
371
|
+
})
|
|
372
|
+
);
|
|
373
|
+
case "create_policy":
|
|
374
|
+
return ok(
|
|
375
|
+
await client2.governance({
|
|
376
|
+
action: "create_policy",
|
|
377
|
+
label,
|
|
378
|
+
summary,
|
|
379
|
+
props,
|
|
380
|
+
agent_id
|
|
381
|
+
})
|
|
382
|
+
);
|
|
383
|
+
case "request_approval":
|
|
384
|
+
return ok(
|
|
385
|
+
await client2.governance({
|
|
386
|
+
action: "request_approval",
|
|
387
|
+
label,
|
|
388
|
+
summary,
|
|
389
|
+
props,
|
|
390
|
+
agent_id
|
|
391
|
+
})
|
|
392
|
+
);
|
|
393
|
+
case "resolve_approval":
|
|
394
|
+
return ok(
|
|
395
|
+
await client2.governance({
|
|
396
|
+
action: "resolve_approval",
|
|
397
|
+
task_uid,
|
|
398
|
+
props,
|
|
399
|
+
agent_id
|
|
400
|
+
})
|
|
401
|
+
);
|
|
402
|
+
case "get_pending":
|
|
403
|
+
return ok(
|
|
404
|
+
await client2.governance({
|
|
405
|
+
action: "get_pending",
|
|
406
|
+
agent_id
|
|
407
|
+
})
|
|
408
|
+
);
|
|
409
|
+
default:
|
|
410
|
+
return err(`Unknown plan action: ${action}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async function handleRetrieve(client2, args) {
|
|
414
|
+
const { action, query, layer, limit, node_type, agent_id } = args;
|
|
415
|
+
switch (action) {
|
|
416
|
+
case "context":
|
|
417
|
+
if (!query) return err("query is required for context retrieval");
|
|
418
|
+
return ok(await client2.retrieveContext({ query, k: limit }));
|
|
419
|
+
case "hybrid":
|
|
420
|
+
if (!query) return err("query is required for hybrid search");
|
|
421
|
+
return ok(
|
|
422
|
+
await client2.hybridSearch(query, {
|
|
423
|
+
k: limit,
|
|
424
|
+
node_types: node_type ? [node_type] : void 0
|
|
425
|
+
})
|
|
426
|
+
);
|
|
427
|
+
case "semantic":
|
|
428
|
+
if (!query) return err("query is required for semantic search");
|
|
429
|
+
return ok(
|
|
430
|
+
await client2.retrieve({
|
|
431
|
+
action: "semantic",
|
|
432
|
+
query,
|
|
433
|
+
limit,
|
|
434
|
+
node_type,
|
|
435
|
+
agent_id
|
|
436
|
+
})
|
|
437
|
+
);
|
|
438
|
+
case "text":
|
|
439
|
+
if (!query) return err("query is required for text search");
|
|
440
|
+
return ok(await client2.search(query, { limit, node_type }));
|
|
441
|
+
case "active_goals":
|
|
442
|
+
return ok(await client2.getGoals());
|
|
443
|
+
case "open_questions":
|
|
444
|
+
return ok(await client2.getOpenQuestions());
|
|
445
|
+
case "weak_claims":
|
|
446
|
+
return ok(await client2.getWeakClaims());
|
|
447
|
+
case "pending_approvals":
|
|
448
|
+
return ok(await client2.getPendingApprovals());
|
|
449
|
+
case "unresolved_contradictions":
|
|
450
|
+
return ok(await client2.getContradictions());
|
|
451
|
+
case "layer":
|
|
452
|
+
if (!layer) return err("layer is required for layer retrieval");
|
|
453
|
+
return ok(
|
|
454
|
+
await client2.retrieve({
|
|
455
|
+
action: "layer",
|
|
456
|
+
layer,
|
|
457
|
+
limit,
|
|
458
|
+
agent_id
|
|
459
|
+
})
|
|
460
|
+
);
|
|
461
|
+
case "recent":
|
|
462
|
+
return ok(
|
|
463
|
+
await client2.retrieve({
|
|
464
|
+
action: "recent",
|
|
465
|
+
limit,
|
|
466
|
+
node_type,
|
|
467
|
+
agent_id
|
|
468
|
+
})
|
|
469
|
+
);
|
|
470
|
+
default:
|
|
471
|
+
return err(`Unknown retrieve action: ${action}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async function handleIngest(client2, args) {
|
|
475
|
+
const { action, content, title, source, layers, chunk_size, chunk_overlap, job_id, agent_id } = args;
|
|
476
|
+
switch (action) {
|
|
477
|
+
case "chunk":
|
|
478
|
+
if (!content) return err("content is required for chunk ingestion");
|
|
479
|
+
return ok(
|
|
480
|
+
await client2.ingestChunk({
|
|
481
|
+
content,
|
|
482
|
+
title,
|
|
483
|
+
source,
|
|
484
|
+
layers,
|
|
485
|
+
agent_id
|
|
486
|
+
})
|
|
487
|
+
);
|
|
488
|
+
case "document":
|
|
489
|
+
if (!content) return err("content is required for document ingestion");
|
|
490
|
+
return ok(
|
|
491
|
+
await client2.ingestDocument({
|
|
492
|
+
content,
|
|
493
|
+
title,
|
|
494
|
+
source,
|
|
495
|
+
layers,
|
|
496
|
+
chunk_size,
|
|
497
|
+
chunk_overlap,
|
|
498
|
+
agent_id
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
case "session":
|
|
502
|
+
if (!content) return err("content is required for session ingestion");
|
|
503
|
+
return ok(
|
|
504
|
+
await client2.ingestSession({
|
|
505
|
+
content,
|
|
506
|
+
title,
|
|
507
|
+
source,
|
|
508
|
+
layers,
|
|
509
|
+
agent_id
|
|
510
|
+
})
|
|
511
|
+
);
|
|
512
|
+
case "job_status":
|
|
513
|
+
if (job_id) {
|
|
514
|
+
return ok(await client2.getJob(job_id));
|
|
515
|
+
}
|
|
516
|
+
return ok(await client2.listJobs());
|
|
517
|
+
default:
|
|
518
|
+
return err(`Unknown ingest action: ${action}`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
var TOOLS;
|
|
522
|
+
var init_tools = __esm({
|
|
523
|
+
"src/tools.ts"() {
|
|
524
|
+
"use strict";
|
|
525
|
+
TOOLS = [
|
|
526
|
+
{
|
|
527
|
+
name: "mindgraph_session",
|
|
528
|
+
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.",
|
|
529
|
+
inputSchema: {
|
|
530
|
+
type: "object",
|
|
531
|
+
properties: {
|
|
532
|
+
action: {
|
|
533
|
+
type: "string",
|
|
534
|
+
enum: ["open", "trace", "close"],
|
|
535
|
+
description: "Session lifecycle action"
|
|
536
|
+
},
|
|
537
|
+
label: {
|
|
538
|
+
type: "string",
|
|
539
|
+
description: "Session or trace label (required for open/trace)"
|
|
540
|
+
},
|
|
541
|
+
session_uid: {
|
|
542
|
+
type: "string",
|
|
543
|
+
description: "Session UID (required for trace/close)"
|
|
544
|
+
},
|
|
545
|
+
summary: {
|
|
546
|
+
type: "string",
|
|
547
|
+
description: "Session summary (used on close)"
|
|
548
|
+
},
|
|
549
|
+
props: {
|
|
550
|
+
type: "object",
|
|
551
|
+
description: "Additional properties"
|
|
552
|
+
},
|
|
553
|
+
agent_id: {
|
|
554
|
+
type: "string",
|
|
555
|
+
description: "Agent identity for multi-agent systems"
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
required: ["action"]
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
name: "mindgraph_journal",
|
|
563
|
+
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.",
|
|
564
|
+
inputSchema: {
|
|
565
|
+
type: "object",
|
|
566
|
+
properties: {
|
|
567
|
+
label: {
|
|
568
|
+
type: "string",
|
|
569
|
+
description: "Brief title for the journal entry"
|
|
570
|
+
},
|
|
571
|
+
content: {
|
|
572
|
+
type: "string",
|
|
573
|
+
description: "The journal content/body text"
|
|
574
|
+
},
|
|
575
|
+
mood: {
|
|
576
|
+
type: "string",
|
|
577
|
+
description: "Emotional tone or mood tag"
|
|
578
|
+
},
|
|
579
|
+
tags: {
|
|
580
|
+
type: "array",
|
|
581
|
+
items: { type: "string" },
|
|
582
|
+
description: "Categorization tags"
|
|
583
|
+
},
|
|
584
|
+
session_uid: {
|
|
585
|
+
type: "string",
|
|
586
|
+
description: "Link to an active session"
|
|
587
|
+
},
|
|
588
|
+
agent_id: {
|
|
589
|
+
type: "string",
|
|
590
|
+
description: "Agent identity"
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
required: ["label", "content"]
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: "mindgraph_capture",
|
|
598
|
+
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.",
|
|
599
|
+
inputSchema: {
|
|
600
|
+
type: "object",
|
|
601
|
+
properties: {
|
|
602
|
+
action: {
|
|
603
|
+
type: "string",
|
|
604
|
+
enum: ["entity", "observation", "source", "snippet", "concept"],
|
|
605
|
+
description: "Type of reality to capture"
|
|
606
|
+
},
|
|
607
|
+
label: {
|
|
608
|
+
type: "string",
|
|
609
|
+
description: "Name or title"
|
|
610
|
+
},
|
|
611
|
+
summary: {
|
|
612
|
+
type: "string",
|
|
613
|
+
description: "Description or summary text"
|
|
614
|
+
},
|
|
615
|
+
entity_type: {
|
|
616
|
+
type: "string",
|
|
617
|
+
enum: [
|
|
618
|
+
"person",
|
|
619
|
+
"organization",
|
|
620
|
+
"place",
|
|
621
|
+
"event",
|
|
622
|
+
"nation",
|
|
623
|
+
"concept"
|
|
624
|
+
],
|
|
625
|
+
description: "Entity subtype (only for action=entity)"
|
|
626
|
+
},
|
|
627
|
+
source_uid: {
|
|
628
|
+
type: "string",
|
|
629
|
+
description: "Source node UID (for snippets)"
|
|
630
|
+
},
|
|
631
|
+
confidence: {
|
|
632
|
+
type: "number",
|
|
633
|
+
minimum: 0,
|
|
634
|
+
maximum: 1,
|
|
635
|
+
description: "Confidence score (0-1)"
|
|
636
|
+
},
|
|
637
|
+
salience: {
|
|
638
|
+
type: "number",
|
|
639
|
+
minimum: 0,
|
|
640
|
+
maximum: 1,
|
|
641
|
+
description: "Importance/salience score (0-1)"
|
|
642
|
+
},
|
|
643
|
+
props: {
|
|
644
|
+
type: "object",
|
|
645
|
+
description: "Type-specific properties (e.g. birth_date for person, coordinates for place)"
|
|
646
|
+
},
|
|
647
|
+
agent_id: {
|
|
648
|
+
type: "string",
|
|
649
|
+
description: "Agent identity"
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
required: ["action", "label"]
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
name: "mindgraph_argue",
|
|
657
|
+
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.",
|
|
658
|
+
inputSchema: {
|
|
659
|
+
type: "object",
|
|
660
|
+
properties: {
|
|
661
|
+
claim: {
|
|
662
|
+
type: "object",
|
|
663
|
+
properties: {
|
|
664
|
+
label: { type: "string", description: "Claim statement" },
|
|
665
|
+
content: { type: "string", description: "Detailed claim content" },
|
|
666
|
+
confidence: {
|
|
667
|
+
type: "number",
|
|
668
|
+
minimum: 0,
|
|
669
|
+
maximum: 1,
|
|
670
|
+
description: "How likely this claim is true (0-1)"
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
required: ["label"],
|
|
674
|
+
description: "The central claim being argued"
|
|
675
|
+
},
|
|
676
|
+
evidence: {
|
|
677
|
+
type: "array",
|
|
678
|
+
items: {
|
|
679
|
+
type: "object",
|
|
680
|
+
properties: {
|
|
681
|
+
label: { type: "string" },
|
|
682
|
+
description: { type: "string" }
|
|
683
|
+
},
|
|
684
|
+
required: ["label"]
|
|
685
|
+
},
|
|
686
|
+
description: "Supporting evidence items"
|
|
687
|
+
},
|
|
688
|
+
warrant: {
|
|
689
|
+
type: "object",
|
|
690
|
+
properties: {
|
|
691
|
+
label: { type: "string" },
|
|
692
|
+
content: { type: "string" }
|
|
693
|
+
},
|
|
694
|
+
description: "Logical warrant connecting evidence to claim"
|
|
695
|
+
},
|
|
696
|
+
argument: {
|
|
697
|
+
type: "object",
|
|
698
|
+
properties: {
|
|
699
|
+
label: { type: "string" }
|
|
700
|
+
},
|
|
701
|
+
description: "Top-level argument container"
|
|
702
|
+
},
|
|
703
|
+
agent_id: {
|
|
704
|
+
type: "string",
|
|
705
|
+
description: "Agent identity"
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
required: ["claim"]
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
name: "mindgraph_inquire",
|
|
713
|
+
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.",
|
|
714
|
+
inputSchema: {
|
|
715
|
+
type: "object",
|
|
716
|
+
properties: {
|
|
717
|
+
action: {
|
|
718
|
+
type: "string",
|
|
719
|
+
enum: [
|
|
720
|
+
"question",
|
|
721
|
+
"open_question",
|
|
722
|
+
"hypothesis",
|
|
723
|
+
"theory",
|
|
724
|
+
"paradigm",
|
|
725
|
+
"anomaly",
|
|
726
|
+
"assumption"
|
|
727
|
+
],
|
|
728
|
+
description: "Type of epistemic inquiry"
|
|
729
|
+
},
|
|
730
|
+
label: {
|
|
731
|
+
type: "string",
|
|
732
|
+
description: "The question, hypothesis, or theory statement"
|
|
733
|
+
},
|
|
734
|
+
summary: {
|
|
735
|
+
type: "string",
|
|
736
|
+
description: "Expanded description or context"
|
|
737
|
+
},
|
|
738
|
+
confidence: {
|
|
739
|
+
type: "number",
|
|
740
|
+
minimum: 0,
|
|
741
|
+
maximum: 1,
|
|
742
|
+
description: "Confidence level (0-1)"
|
|
743
|
+
},
|
|
744
|
+
salience: {
|
|
745
|
+
type: "number",
|
|
746
|
+
minimum: 0,
|
|
747
|
+
maximum: 1,
|
|
748
|
+
description: "Importance score (0-1)"
|
|
749
|
+
},
|
|
750
|
+
props: {
|
|
751
|
+
type: "object",
|
|
752
|
+
description: "Type-specific properties"
|
|
753
|
+
},
|
|
754
|
+
agent_id: {
|
|
755
|
+
type: "string",
|
|
756
|
+
description: "Agent identity"
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
required: ["action", "label"]
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
name: "mindgraph_commit",
|
|
764
|
+
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.",
|
|
765
|
+
inputSchema: {
|
|
766
|
+
type: "object",
|
|
767
|
+
properties: {
|
|
768
|
+
action: {
|
|
769
|
+
type: "string",
|
|
770
|
+
enum: ["goal", "project", "milestone"],
|
|
771
|
+
description: "Type of commitment"
|
|
772
|
+
},
|
|
773
|
+
label: {
|
|
774
|
+
type: "string",
|
|
775
|
+
description: "Name of the goal, project, or milestone"
|
|
776
|
+
},
|
|
777
|
+
summary: {
|
|
778
|
+
type: "string",
|
|
779
|
+
description: "Description and success criteria"
|
|
780
|
+
},
|
|
781
|
+
parent_uid: {
|
|
782
|
+
type: "string",
|
|
783
|
+
description: "Parent goal/project UID to link under"
|
|
784
|
+
},
|
|
785
|
+
confidence: {
|
|
786
|
+
type: "number",
|
|
787
|
+
minimum: 0,
|
|
788
|
+
maximum: 1
|
|
789
|
+
},
|
|
790
|
+
salience: {
|
|
791
|
+
type: "number",
|
|
792
|
+
minimum: 0,
|
|
793
|
+
maximum: 1
|
|
794
|
+
},
|
|
795
|
+
props: {
|
|
796
|
+
type: "object",
|
|
797
|
+
description: "Type-specific properties (e.g. status, priority, deadline, horizon for goals)"
|
|
798
|
+
},
|
|
799
|
+
agent_id: {
|
|
800
|
+
type: "string",
|
|
801
|
+
description: "Agent identity"
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
required: ["action", "label"]
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
name: "mindgraph_decide",
|
|
809
|
+
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.",
|
|
810
|
+
inputSchema: {
|
|
811
|
+
type: "object",
|
|
812
|
+
properties: {
|
|
813
|
+
action: {
|
|
814
|
+
type: "string",
|
|
815
|
+
enum: ["open_decision", "add_option", "add_constraint", "resolve", "get_open"],
|
|
816
|
+
description: "Decision lifecycle action"
|
|
817
|
+
},
|
|
818
|
+
label: {
|
|
819
|
+
type: "string",
|
|
820
|
+
description: "Decision, option, or constraint label"
|
|
821
|
+
},
|
|
822
|
+
summary: {
|
|
823
|
+
type: "string",
|
|
824
|
+
description: "Description or rationale"
|
|
825
|
+
},
|
|
826
|
+
decision_uid: {
|
|
827
|
+
type: "string",
|
|
828
|
+
description: "Decision UID (for add_option, add_constraint, resolve)"
|
|
829
|
+
},
|
|
830
|
+
chosen_option_uid: {
|
|
831
|
+
type: "string",
|
|
832
|
+
description: "UID of the chosen option (for resolve)"
|
|
833
|
+
},
|
|
834
|
+
props: {
|
|
835
|
+
type: "object",
|
|
836
|
+
description: "Additional properties"
|
|
837
|
+
},
|
|
838
|
+
agent_id: {
|
|
839
|
+
type: "string",
|
|
840
|
+
description: "Agent identity"
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
required: ["action"]
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
name: "mindgraph_action",
|
|
848
|
+
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.",
|
|
849
|
+
inputSchema: {
|
|
850
|
+
type: "object",
|
|
851
|
+
properties: {
|
|
852
|
+
action: {
|
|
853
|
+
type: "string",
|
|
854
|
+
enum: [
|
|
855
|
+
"create_flow",
|
|
856
|
+
"add_step",
|
|
857
|
+
"add_affordance",
|
|
858
|
+
"add_control",
|
|
859
|
+
"assess_risk",
|
|
860
|
+
"get_assessments"
|
|
861
|
+
],
|
|
862
|
+
description: "Action layer operation"
|
|
863
|
+
},
|
|
864
|
+
label: {
|
|
865
|
+
type: "string",
|
|
866
|
+
description: "Flow, step, affordance, control, or risk label"
|
|
867
|
+
},
|
|
868
|
+
summary: {
|
|
869
|
+
type: "string",
|
|
870
|
+
description: "Description"
|
|
871
|
+
},
|
|
872
|
+
target_uid: {
|
|
873
|
+
type: "string",
|
|
874
|
+
description: "Parent flow/step UID or target node for risk assessment"
|
|
875
|
+
},
|
|
876
|
+
props: {
|
|
877
|
+
type: "object",
|
|
878
|
+
description: "Type-specific properties (e.g. likelihood, impact, mitigation for risks)"
|
|
879
|
+
},
|
|
880
|
+
agent_id: {
|
|
881
|
+
type: "string",
|
|
882
|
+
description: "Agent identity"
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
required: ["action"]
|
|
886
|
+
}
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
name: "mindgraph_plan",
|
|
890
|
+
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.",
|
|
891
|
+
inputSchema: {
|
|
892
|
+
type: "object",
|
|
893
|
+
properties: {
|
|
894
|
+
action: {
|
|
895
|
+
type: "string",
|
|
896
|
+
enum: [
|
|
897
|
+
"create_task",
|
|
898
|
+
"create_plan",
|
|
899
|
+
"add_step",
|
|
900
|
+
"update_status",
|
|
901
|
+
"get_plan",
|
|
902
|
+
"start_execution",
|
|
903
|
+
"complete_execution",
|
|
904
|
+
"fail_execution",
|
|
905
|
+
"create_policy",
|
|
906
|
+
"request_approval",
|
|
907
|
+
"resolve_approval",
|
|
908
|
+
"get_pending"
|
|
909
|
+
],
|
|
910
|
+
description: "Agent layer operation"
|
|
911
|
+
},
|
|
912
|
+
label: {
|
|
913
|
+
type: "string",
|
|
914
|
+
description: "Task, plan, step, or policy label"
|
|
915
|
+
},
|
|
916
|
+
summary: {
|
|
917
|
+
type: "string",
|
|
918
|
+
description: "Description"
|
|
919
|
+
},
|
|
920
|
+
plan_uid: {
|
|
921
|
+
type: "string",
|
|
922
|
+
description: "Plan UID (for add_step, get_plan)"
|
|
923
|
+
},
|
|
924
|
+
task_uid: {
|
|
925
|
+
type: "string",
|
|
926
|
+
description: "Task/step UID (for update_status, execution actions)"
|
|
927
|
+
},
|
|
928
|
+
status: {
|
|
929
|
+
type: "string",
|
|
930
|
+
description: "New status value (for update_status)"
|
|
931
|
+
},
|
|
932
|
+
props: {
|
|
933
|
+
type: "object",
|
|
934
|
+
description: "Additional properties"
|
|
935
|
+
},
|
|
936
|
+
agent_id: {
|
|
937
|
+
type: "string",
|
|
938
|
+
description: "Agent identity"
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
required: ["action"]
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
name: "mindgraph_retrieve",
|
|
946
|
+
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.",
|
|
947
|
+
inputSchema: {
|
|
948
|
+
type: "object",
|
|
949
|
+
properties: {
|
|
950
|
+
action: {
|
|
951
|
+
type: "string",
|
|
952
|
+
enum: [
|
|
953
|
+
"hybrid",
|
|
954
|
+
"semantic",
|
|
955
|
+
"text",
|
|
956
|
+
"context",
|
|
957
|
+
"active_goals",
|
|
958
|
+
"open_questions",
|
|
959
|
+
"weak_claims",
|
|
960
|
+
"pending_approvals",
|
|
961
|
+
"unresolved_contradictions",
|
|
962
|
+
"layer",
|
|
963
|
+
"recent"
|
|
964
|
+
],
|
|
965
|
+
description: "Retrieval strategy"
|
|
966
|
+
},
|
|
967
|
+
query: {
|
|
968
|
+
type: "string",
|
|
969
|
+
description: "Search query (for hybrid, semantic, text, context)"
|
|
970
|
+
},
|
|
971
|
+
layer: {
|
|
972
|
+
type: "string",
|
|
973
|
+
enum: [
|
|
974
|
+
"reality",
|
|
975
|
+
"epistemic",
|
|
976
|
+
"intent",
|
|
977
|
+
"action",
|
|
978
|
+
"memory",
|
|
979
|
+
"agent"
|
|
980
|
+
],
|
|
981
|
+
description: "Layer filter (for layer action)"
|
|
982
|
+
},
|
|
983
|
+
limit: {
|
|
984
|
+
type: "number",
|
|
985
|
+
description: "Max results to return (default: 10)"
|
|
986
|
+
},
|
|
987
|
+
node_type: {
|
|
988
|
+
type: "string",
|
|
989
|
+
description: "Filter by node type"
|
|
990
|
+
},
|
|
991
|
+
agent_id: {
|
|
992
|
+
type: "string",
|
|
993
|
+
description: "Agent identity"
|
|
994
|
+
}
|
|
995
|
+
},
|
|
996
|
+
required: ["action"]
|
|
997
|
+
}
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
name: "mindgraph_ingest",
|
|
1001
|
+
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.",
|
|
1002
|
+
inputSchema: {
|
|
1003
|
+
type: "object",
|
|
1004
|
+
properties: {
|
|
1005
|
+
action: {
|
|
1006
|
+
type: "string",
|
|
1007
|
+
enum: ["chunk", "document", "session", "job_status"],
|
|
1008
|
+
description: "Ingestion action"
|
|
1009
|
+
},
|
|
1010
|
+
content: {
|
|
1011
|
+
type: "string",
|
|
1012
|
+
description: "Text content to ingest (for chunk/document/session)"
|
|
1013
|
+
},
|
|
1014
|
+
title: {
|
|
1015
|
+
type: "string",
|
|
1016
|
+
description: "Document or session title"
|
|
1017
|
+
},
|
|
1018
|
+
source: {
|
|
1019
|
+
type: "string",
|
|
1020
|
+
description: "Source URL or reference"
|
|
1021
|
+
},
|
|
1022
|
+
layers: {
|
|
1023
|
+
type: "array",
|
|
1024
|
+
items: {
|
|
1025
|
+
type: "string",
|
|
1026
|
+
enum: [
|
|
1027
|
+
"reality",
|
|
1028
|
+
"epistemic",
|
|
1029
|
+
"intent",
|
|
1030
|
+
"action",
|
|
1031
|
+
"memory",
|
|
1032
|
+
"agent"
|
|
1033
|
+
]
|
|
1034
|
+
},
|
|
1035
|
+
description: "Cognitive layers to extract (defaults vary by action)"
|
|
1036
|
+
},
|
|
1037
|
+
chunk_size: {
|
|
1038
|
+
type: "number",
|
|
1039
|
+
description: "Characters per chunk for document ingestion (default: 4000)"
|
|
1040
|
+
},
|
|
1041
|
+
chunk_overlap: {
|
|
1042
|
+
type: "number",
|
|
1043
|
+
description: "Overlap between chunks (default: 200)"
|
|
1044
|
+
},
|
|
1045
|
+
job_id: {
|
|
1046
|
+
type: "string",
|
|
1047
|
+
description: "Job ID to check status (for job_status action)"
|
|
1048
|
+
},
|
|
1049
|
+
agent_id: {
|
|
1050
|
+
type: "string",
|
|
1051
|
+
description: "Agent identity"
|
|
1052
|
+
}
|
|
1053
|
+
},
|
|
1054
|
+
required: ["action"]
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
];
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
// src/index.ts
|
|
1062
|
+
var src_exports = {};
|
|
1063
|
+
async function main() {
|
|
1064
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
1065
|
+
await server.connect(transport);
|
|
1066
|
+
console.error("MindGraph MCP server running on stdio");
|
|
1067
|
+
}
|
|
1068
|
+
var import_server, import_stdio, import_types, import_mindgraph, API_KEY, BASE_URL, AGENT_ID, client, server;
|
|
1069
|
+
var init_src = __esm({
|
|
1070
|
+
"src/index.ts"() {
|
|
1071
|
+
"use strict";
|
|
1072
|
+
import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
1073
|
+
import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
1074
|
+
import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
1075
|
+
import_mindgraph = require("mindgraph");
|
|
1076
|
+
init_tools();
|
|
1077
|
+
API_KEY = process.env.MINDGRAPH_API_KEY;
|
|
1078
|
+
BASE_URL = process.env.MINDGRAPH_BASE_URL || "https://api.mindgraph.cloud";
|
|
1079
|
+
AGENT_ID = process.env.MINDGRAPH_AGENT_ID || "mcp";
|
|
1080
|
+
if (!API_KEY) {
|
|
1081
|
+
console.error(
|
|
1082
|
+
"Error: MINDGRAPH_API_KEY environment variable is required.\nGet your API key at https://mindgraph.cloud/dashboard/keys"
|
|
1083
|
+
);
|
|
1084
|
+
process.exit(1);
|
|
1085
|
+
}
|
|
1086
|
+
client = new import_mindgraph.MindGraph({
|
|
1087
|
+
baseUrl: BASE_URL,
|
|
1088
|
+
apiKey: API_KEY
|
|
1089
|
+
});
|
|
1090
|
+
server = new import_server.Server(
|
|
1091
|
+
{
|
|
1092
|
+
name: "mindgraph",
|
|
1093
|
+
version: "0.1.0"
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
capabilities: {
|
|
1097
|
+
tools: {},
|
|
1098
|
+
resources: {}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
1103
|
+
return { tools: TOOLS };
|
|
1104
|
+
});
|
|
1105
|
+
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
1106
|
+
const { name, arguments: args } = request.params;
|
|
1107
|
+
const toolArgs = { ...args || {} };
|
|
1108
|
+
if (!toolArgs.agent_id) {
|
|
1109
|
+
toolArgs.agent_id = AGENT_ID;
|
|
1110
|
+
}
|
|
1111
|
+
return handleTool(client, name, toolArgs);
|
|
1112
|
+
});
|
|
1113
|
+
server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
|
|
1114
|
+
return {
|
|
1115
|
+
resources: [
|
|
1116
|
+
{
|
|
1117
|
+
uri: "mindgraph://stats",
|
|
1118
|
+
name: "Graph Statistics",
|
|
1119
|
+
description: "Current knowledge graph statistics: node counts, edge counts, and layer distribution",
|
|
1120
|
+
mimeType: "application/json"
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
uri: "mindgraph://goals",
|
|
1124
|
+
name: "Active Goals",
|
|
1125
|
+
description: "All active goals in the knowledge graph",
|
|
1126
|
+
mimeType: "application/json"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
uri: "mindgraph://questions",
|
|
1130
|
+
name: "Open Questions",
|
|
1131
|
+
description: "All open questions in the knowledge graph",
|
|
1132
|
+
mimeType: "application/json"
|
|
1133
|
+
}
|
|
1134
|
+
]
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
server.setRequestHandler(import_types.ReadResourceRequestSchema, async (request) => {
|
|
1138
|
+
const { uri } = request.params;
|
|
1139
|
+
switch (uri) {
|
|
1140
|
+
case "mindgraph://stats": {
|
|
1141
|
+
const stats = await client.stats();
|
|
1142
|
+
return {
|
|
1143
|
+
contents: [
|
|
1144
|
+
{
|
|
1145
|
+
uri,
|
|
1146
|
+
mimeType: "application/json",
|
|
1147
|
+
text: JSON.stringify(stats, null, 2)
|
|
1148
|
+
}
|
|
1149
|
+
]
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
case "mindgraph://goals": {
|
|
1153
|
+
const goals = await client.getGoals();
|
|
1154
|
+
return {
|
|
1155
|
+
contents: [
|
|
1156
|
+
{
|
|
1157
|
+
uri,
|
|
1158
|
+
mimeType: "application/json",
|
|
1159
|
+
text: JSON.stringify(goals, null, 2)
|
|
1160
|
+
}
|
|
1161
|
+
]
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
case "mindgraph://questions": {
|
|
1165
|
+
const questions = await client.getOpenQuestions();
|
|
1166
|
+
return {
|
|
1167
|
+
contents: [
|
|
1168
|
+
{
|
|
1169
|
+
uri,
|
|
1170
|
+
mimeType: "application/json",
|
|
1171
|
+
text: JSON.stringify(questions, null, 2)
|
|
1172
|
+
}
|
|
1173
|
+
]
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
default:
|
|
1177
|
+
throw new Error(`Unknown resource: ${uri}`);
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
main().catch((error) => {
|
|
1181
|
+
console.error("Fatal error:", error);
|
|
1182
|
+
process.exit(1);
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
// src/cli.ts
|
|
1188
|
+
var fs = __toESM(require("fs"));
|
|
1189
|
+
var path = __toESM(require("path"));
|
|
1190
|
+
var os = __toESM(require("os"));
|
|
1191
|
+
var crypto = __toESM(require("crypto"));
|
|
1192
|
+
var import_child_process = require("child_process");
|
|
1193
|
+
function getClaudeDesktopConfigPath() {
|
|
1194
|
+
switch (process.platform) {
|
|
1195
|
+
case "darwin":
|
|
1196
|
+
return path.join(
|
|
1197
|
+
os.homedir(),
|
|
1198
|
+
"Library",
|
|
1199
|
+
"Application Support",
|
|
1200
|
+
"Claude",
|
|
1201
|
+
"claude_desktop_config.json"
|
|
1202
|
+
);
|
|
1203
|
+
case "win32":
|
|
1204
|
+
return path.join(
|
|
1205
|
+
process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"),
|
|
1206
|
+
"Claude",
|
|
1207
|
+
"claude_desktop_config.json"
|
|
1208
|
+
);
|
|
1209
|
+
case "linux":
|
|
1210
|
+
return path.join(
|
|
1211
|
+
os.homedir(),
|
|
1212
|
+
".config",
|
|
1213
|
+
"Claude",
|
|
1214
|
+
"claude_desktop_config.json"
|
|
1215
|
+
);
|
|
1216
|
+
default:
|
|
1217
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function readJsonFile(filePath) {
|
|
1221
|
+
if (!fs.existsSync(filePath)) return {};
|
|
1222
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
1223
|
+
return JSON.parse(content);
|
|
1224
|
+
}
|
|
1225
|
+
function writeJsonFile(filePath, data) {
|
|
1226
|
+
const dir = path.dirname(filePath);
|
|
1227
|
+
if (!fs.existsSync(dir)) {
|
|
1228
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1229
|
+
}
|
|
1230
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n");
|
|
1231
|
+
}
|
|
1232
|
+
function getMcpServerEntry(apiKey, baseUrl) {
|
|
1233
|
+
const env = { MINDGRAPH_API_KEY: apiKey };
|
|
1234
|
+
if (baseUrl) env.MINDGRAPH_BASE_URL = baseUrl;
|
|
1235
|
+
return {
|
|
1236
|
+
command: "npx",
|
|
1237
|
+
args: ["-y", "mindgraph-mcp"],
|
|
1238
|
+
env
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
function installClaudeDesktop(apiKey, baseUrl) {
|
|
1242
|
+
const configPath = getClaudeDesktopConfigPath();
|
|
1243
|
+
console.log(`Claude Desktop config: ${configPath}`);
|
|
1244
|
+
const config = readJsonFile(configPath);
|
|
1245
|
+
if (!config.mcpServers) {
|
|
1246
|
+
config.mcpServers = {};
|
|
1247
|
+
}
|
|
1248
|
+
const servers = config.mcpServers;
|
|
1249
|
+
const isUpdate = "mindgraph" in servers;
|
|
1250
|
+
servers.mindgraph = getMcpServerEntry(apiKey, baseUrl);
|
|
1251
|
+
writeJsonFile(configPath, config);
|
|
1252
|
+
if (isUpdate) {
|
|
1253
|
+
console.log("Updated MindGraph MCP server in Claude Desktop config.");
|
|
1254
|
+
} else {
|
|
1255
|
+
console.log("Added MindGraph MCP server to Claude Desktop config.");
|
|
1256
|
+
}
|
|
1257
|
+
console.log("Restart Claude Desktop to activate.");
|
|
1258
|
+
}
|
|
1259
|
+
function installClaudeCode(apiKey, baseUrl) {
|
|
1260
|
+
const envArgs = [`--env`, `MINDGRAPH_API_KEY=${apiKey}`];
|
|
1261
|
+
if (baseUrl) {
|
|
1262
|
+
envArgs.push("--env", `MINDGRAPH_BASE_URL=${baseUrl}`);
|
|
1263
|
+
}
|
|
1264
|
+
try {
|
|
1265
|
+
(0, import_child_process.execSync)(
|
|
1266
|
+
[
|
|
1267
|
+
"claude",
|
|
1268
|
+
"mcp",
|
|
1269
|
+
"add",
|
|
1270
|
+
"mindgraph",
|
|
1271
|
+
...envArgs,
|
|
1272
|
+
"--",
|
|
1273
|
+
"npx",
|
|
1274
|
+
"-y",
|
|
1275
|
+
"mindgraph-mcp"
|
|
1276
|
+
].join(" "),
|
|
1277
|
+
{ stdio: "inherit" }
|
|
1278
|
+
);
|
|
1279
|
+
console.log("Added MindGraph MCP server to Claude Code.");
|
|
1280
|
+
} catch {
|
|
1281
|
+
console.error(
|
|
1282
|
+
"Failed to run 'claude mcp add'. Is Claude Code CLI installed?"
|
|
1283
|
+
);
|
|
1284
|
+
console.error("Install it from: https://claude.ai/code");
|
|
1285
|
+
process.exit(1);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function uninstallClaudeDesktop() {
|
|
1289
|
+
const configPath = getClaudeDesktopConfigPath();
|
|
1290
|
+
if (!fs.existsSync(configPath)) {
|
|
1291
|
+
console.log("Claude Desktop config not found. Nothing to remove.");
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
const config = readJsonFile(configPath);
|
|
1295
|
+
const servers = config.mcpServers;
|
|
1296
|
+
if (!servers || !("mindgraph" in servers)) {
|
|
1297
|
+
console.log("MindGraph not found in Claude Desktop config.");
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
delete servers.mindgraph;
|
|
1301
|
+
writeJsonFile(configPath, config);
|
|
1302
|
+
console.log("Removed MindGraph from Claude Desktop config.");
|
|
1303
|
+
console.log("Restart Claude Desktop to apply.");
|
|
1304
|
+
}
|
|
1305
|
+
function uninstallClaudeCode() {
|
|
1306
|
+
try {
|
|
1307
|
+
(0, import_child_process.execSync)("claude mcp remove mindgraph", { stdio: "inherit" });
|
|
1308
|
+
console.log("Removed MindGraph MCP server from Claude Code.");
|
|
1309
|
+
} catch {
|
|
1310
|
+
console.error("Failed to run 'claude mcp remove'.");
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
function printStatus() {
|
|
1314
|
+
const desktopPath = getClaudeDesktopConfigPath();
|
|
1315
|
+
if (fs.existsSync(desktopPath)) {
|
|
1316
|
+
const config = readJsonFile(desktopPath);
|
|
1317
|
+
const servers = config.mcpServers;
|
|
1318
|
+
if (servers && "mindgraph" in servers) {
|
|
1319
|
+
console.log("Claude Desktop: installed");
|
|
1320
|
+
} else {
|
|
1321
|
+
console.log("Claude Desktop: not installed");
|
|
1322
|
+
}
|
|
1323
|
+
} else {
|
|
1324
|
+
console.log("Claude Desktop: config not found");
|
|
1325
|
+
}
|
|
1326
|
+
console.log(
|
|
1327
|
+
`MINDGRAPH_API_KEY: ${process.env.MINDGRAPH_API_KEY ? "set" : "not set"}`
|
|
1328
|
+
);
|
|
1329
|
+
console.log(
|
|
1330
|
+
`MINDGRAPH_BASE_URL: ${process.env.MINDGRAPH_BASE_URL || "https://api.mindgraph.cloud (default)"}`
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
function printUsage() {
|
|
1334
|
+
console.log(`
|
|
1335
|
+
mindgraph-mcp \u2014 MCP server for MindGraph knowledge graphs
|
|
1336
|
+
|
|
1337
|
+
USAGE:
|
|
1338
|
+
mindgraph-mcp Start the MCP server (stdio transport)
|
|
1339
|
+
mindgraph-mcp init Interactive setup for Claude Desktop
|
|
1340
|
+
mindgraph-mcp install Install into Claude Desktop config
|
|
1341
|
+
mindgraph-mcp install-code Install into Claude Code
|
|
1342
|
+
mindgraph-mcp uninstall Remove from Claude Desktop config
|
|
1343
|
+
mindgraph-mcp uninstall-code Remove from Claude Code
|
|
1344
|
+
mindgraph-mcp status Show installation status
|
|
1345
|
+
|
|
1346
|
+
OPTIONS:
|
|
1347
|
+
--api-key <key> MindGraph API key (or set MINDGRAPH_API_KEY env var)
|
|
1348
|
+
--base-url <url> Custom API base URL (default: https://api.mindgraph.cloud)
|
|
1349
|
+
--help, -h Show this help message
|
|
1350
|
+
|
|
1351
|
+
EXAMPLES:
|
|
1352
|
+
# Interactive setup
|
|
1353
|
+
npx mindgraph-mcp init
|
|
1354
|
+
|
|
1355
|
+
# Install with API key
|
|
1356
|
+
npx mindgraph-mcp install --api-key mg_your_key_here
|
|
1357
|
+
|
|
1358
|
+
# Install into Claude Code
|
|
1359
|
+
npx mindgraph-mcp install-code --api-key mg_your_key_here
|
|
1360
|
+
|
|
1361
|
+
Get your API key at: https://mindgraph.cloud/dashboard/keys
|
|
1362
|
+
`);
|
|
1363
|
+
}
|
|
1364
|
+
function parseArgs(argv) {
|
|
1365
|
+
const args = argv.slice(2);
|
|
1366
|
+
let command = "serve";
|
|
1367
|
+
let apiKey = process.env.MINDGRAPH_API_KEY;
|
|
1368
|
+
let baseUrl = process.env.MINDGRAPH_BASE_URL;
|
|
1369
|
+
for (let i = 0; i < args.length; i++) {
|
|
1370
|
+
const arg = args[i];
|
|
1371
|
+
switch (arg) {
|
|
1372
|
+
case "--api-key":
|
|
1373
|
+
apiKey = args[++i];
|
|
1374
|
+
break;
|
|
1375
|
+
case "--base-url":
|
|
1376
|
+
baseUrl = args[++i];
|
|
1377
|
+
break;
|
|
1378
|
+
case "--help":
|
|
1379
|
+
case "-h":
|
|
1380
|
+
command = "help";
|
|
1381
|
+
break;
|
|
1382
|
+
default:
|
|
1383
|
+
if (!arg.startsWith("-")) {
|
|
1384
|
+
command = arg;
|
|
1385
|
+
}
|
|
1386
|
+
break;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return { command, apiKey, baseUrl };
|
|
1390
|
+
}
|
|
1391
|
+
var DASHBOARD_URL = process.env.MINDGRAPH_DASHBOARD_URL || "https://mindgraph.cloud";
|
|
1392
|
+
var POLL_INTERVAL = 2e3;
|
|
1393
|
+
var POLL_TIMEOUT = 10 * 60 * 1e3;
|
|
1394
|
+
function generateCode() {
|
|
1395
|
+
return crypto.randomBytes(32).toString("hex");
|
|
1396
|
+
}
|
|
1397
|
+
function openBrowser(url) {
|
|
1398
|
+
try {
|
|
1399
|
+
switch (process.platform) {
|
|
1400
|
+
case "darwin":
|
|
1401
|
+
(0, import_child_process.execSync)(`open "${url}"`);
|
|
1402
|
+
break;
|
|
1403
|
+
case "win32":
|
|
1404
|
+
(0, import_child_process.execSync)(`start "" "${url}"`);
|
|
1405
|
+
break;
|
|
1406
|
+
case "linux":
|
|
1407
|
+
(0, import_child_process.execSync)(`xdg-open "${url}"`);
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
} catch {
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
async function pollForKey(code) {
|
|
1414
|
+
const pollUrl = `${DASHBOARD_URL}/api/connect?code=${code}`;
|
|
1415
|
+
const deadline = Date.now() + POLL_TIMEOUT;
|
|
1416
|
+
while (Date.now() < deadline) {
|
|
1417
|
+
try {
|
|
1418
|
+
const res = await fetch(pollUrl);
|
|
1419
|
+
const data = await res.json();
|
|
1420
|
+
if (data.status === "authorized" && data.api_key) {
|
|
1421
|
+
return data.api_key;
|
|
1422
|
+
}
|
|
1423
|
+
if (data.status === "expired") {
|
|
1424
|
+
throw new Error("Session expired. Please try again.");
|
|
1425
|
+
}
|
|
1426
|
+
if (data.status === "claimed") {
|
|
1427
|
+
throw new Error("Session already used. Please try again.");
|
|
1428
|
+
}
|
|
1429
|
+
} catch (e) {
|
|
1430
|
+
if (e instanceof Error && e.message.includes("Session")) throw e;
|
|
1431
|
+
}
|
|
1432
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
1433
|
+
}
|
|
1434
|
+
throw new Error("Timed out waiting for authorization.");
|
|
1435
|
+
}
|
|
1436
|
+
async function interactiveInit(baseUrl) {
|
|
1437
|
+
const readline = await import("readline");
|
|
1438
|
+
const rl = readline.createInterface({
|
|
1439
|
+
input: process.stdin,
|
|
1440
|
+
output: process.stdout
|
|
1441
|
+
});
|
|
1442
|
+
const ask = (q) => new Promise((resolve) => rl.question(q, resolve));
|
|
1443
|
+
console.log("\nMindGraph MCP Server Setup\n");
|
|
1444
|
+
console.log(" 1. Sign in via browser (recommended)");
|
|
1445
|
+
console.log(" 2. Enter API key manually");
|
|
1446
|
+
console.log("");
|
|
1447
|
+
const method = await ask("Choice (1/2): ");
|
|
1448
|
+
let apiKey;
|
|
1449
|
+
if (method.trim() === "2") {
|
|
1450
|
+
apiKey = await ask(
|
|
1451
|
+
"\nEnter your MindGraph API key (from mindgraph.cloud/dashboard/keys): "
|
|
1452
|
+
);
|
|
1453
|
+
if (!apiKey || !apiKey.startsWith("mg_")) {
|
|
1454
|
+
console.error('Invalid API key. Keys start with "mg_".');
|
|
1455
|
+
rl.close();
|
|
1456
|
+
process.exit(1);
|
|
1457
|
+
}
|
|
1458
|
+
} else {
|
|
1459
|
+
const code = generateCode();
|
|
1460
|
+
const authUrl = `${DASHBOARD_URL}/dashboard/connect?code=${code}`;
|
|
1461
|
+
console.log("\nOpening browser to authorize...\n");
|
|
1462
|
+
console.log(` ${authUrl}
|
|
1463
|
+
`);
|
|
1464
|
+
console.log("If the browser didn't open, copy the URL above and paste it in your browser.");
|
|
1465
|
+
console.log("Waiting for authorization...\n");
|
|
1466
|
+
openBrowser(authUrl);
|
|
1467
|
+
try {
|
|
1468
|
+
apiKey = await pollForKey(code);
|
|
1469
|
+
console.log("Authorization received!\n");
|
|
1470
|
+
} catch (e) {
|
|
1471
|
+
console.error(e instanceof Error ? e.message : "Authorization failed.");
|
|
1472
|
+
rl.close();
|
|
1473
|
+
process.exit(1);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
console.log("Where do you want to install?\n");
|
|
1477
|
+
console.log(" 1. Claude Desktop");
|
|
1478
|
+
console.log(" 2. Claude Code");
|
|
1479
|
+
console.log(" 3. Both");
|
|
1480
|
+
console.log("");
|
|
1481
|
+
const choice = await ask("Choice (1/2/3): ");
|
|
1482
|
+
rl.close();
|
|
1483
|
+
switch (choice.trim()) {
|
|
1484
|
+
case "1":
|
|
1485
|
+
installClaudeDesktop(apiKey, baseUrl);
|
|
1486
|
+
break;
|
|
1487
|
+
case "2":
|
|
1488
|
+
installClaudeCode(apiKey, baseUrl);
|
|
1489
|
+
break;
|
|
1490
|
+
case "3":
|
|
1491
|
+
installClaudeDesktop(apiKey, baseUrl);
|
|
1492
|
+
installClaudeCode(apiKey, baseUrl);
|
|
1493
|
+
break;
|
|
1494
|
+
default:
|
|
1495
|
+
console.error("Invalid choice.");
|
|
1496
|
+
process.exit(1);
|
|
1497
|
+
}
|
|
1498
|
+
console.log("\nDone! Your knowledge graph is now connected.");
|
|
1499
|
+
}
|
|
1500
|
+
async function main2() {
|
|
1501
|
+
const { command, apiKey, baseUrl } = parseArgs(process.argv);
|
|
1502
|
+
switch (command) {
|
|
1503
|
+
case "help":
|
|
1504
|
+
printUsage();
|
|
1505
|
+
break;
|
|
1506
|
+
case "init":
|
|
1507
|
+
await interactiveInit(baseUrl);
|
|
1508
|
+
break;
|
|
1509
|
+
case "install":
|
|
1510
|
+
if (!apiKey) {
|
|
1511
|
+
console.error(
|
|
1512
|
+
"API key required. Use --api-key or set MINDGRAPH_API_KEY."
|
|
1513
|
+
);
|
|
1514
|
+
process.exit(1);
|
|
1515
|
+
}
|
|
1516
|
+
installClaudeDesktop(apiKey, baseUrl);
|
|
1517
|
+
break;
|
|
1518
|
+
case "install-code":
|
|
1519
|
+
if (!apiKey) {
|
|
1520
|
+
console.error(
|
|
1521
|
+
"API key required. Use --api-key or set MINDGRAPH_API_KEY."
|
|
1522
|
+
);
|
|
1523
|
+
process.exit(1);
|
|
1524
|
+
}
|
|
1525
|
+
installClaudeCode(apiKey, baseUrl);
|
|
1526
|
+
break;
|
|
1527
|
+
case "uninstall":
|
|
1528
|
+
uninstallClaudeDesktop();
|
|
1529
|
+
break;
|
|
1530
|
+
case "uninstall-code":
|
|
1531
|
+
uninstallClaudeCode();
|
|
1532
|
+
break;
|
|
1533
|
+
case "status":
|
|
1534
|
+
printStatus();
|
|
1535
|
+
break;
|
|
1536
|
+
case "serve": {
|
|
1537
|
+
await Promise.resolve().then(() => (init_src(), src_exports));
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
default:
|
|
1541
|
+
console.error(`Unknown command: ${command}`);
|
|
1542
|
+
printUsage();
|
|
1543
|
+
process.exit(1);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
main2().catch((error) => {
|
|
1547
|
+
console.error("Error:", error.message || error);
|
|
1548
|
+
process.exit(1);
|
|
1549
|
+
});
|