@lanonasis/cli 3.1.13 → 3.3.15

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.
@@ -0,0 +1,911 @@
1
+ "use strict";
2
+ /**
3
+ * Lanonasis MCP Server Implementation
4
+ * Provides MCP protocol access to Lanonasis MaaS functionality
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __generator = (this && this.__generator) || function (thisArg, body) {
16
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
17
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
+ function verb(n) { return function (v) { return step([n, v]); }; }
19
+ function step(op) {
20
+ if (f) throw new TypeError("Generator is already executing.");
21
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
+ if (y = 0, t) op = [op[0] & 2, t.value];
24
+ switch (op[0]) {
25
+ case 0: case 1: t = op; break;
26
+ case 4: _.label++; return { value: op[1], done: false };
27
+ case 5: _.label++; y = op[1]; op = [0]; continue;
28
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
+ default:
30
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
+ if (t[2]) _.ops.pop();
35
+ _.trys.pop(); continue;
36
+ }
37
+ op = body.call(thisArg, _);
38
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
+ }
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.LanonasisMCPServer = void 0;
44
+ var index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
45
+ var stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
46
+ var config_js_1 = require("../../utils/config.js");
47
+ var api_js_1 = require("../../utils/api.js");
48
+ var chalk_1 = require("chalk");
49
+ var LanonasisMCPServer = /** @class */ (function () {
50
+ function LanonasisMCPServer(options) {
51
+ if (options === void 0) { options = {}; }
52
+ this.transport = null;
53
+ this.options = options;
54
+ // Initialize server with metadata
55
+ this.server = new index_js_1.Server({
56
+ name: options.name || "lanonasis-maas-server",
57
+ version: options.version || "3.0.1"
58
+ }, {
59
+ capabilities: {
60
+ tools: {},
61
+ resources: {},
62
+ prompts: {}
63
+ }
64
+ });
65
+ // Initialize config and API client
66
+ this.config = new config_js_1.CLIConfig();
67
+ this.apiClient = new api_js_1.APIClient();
68
+ // Note: registerTools is now async and called in initialize()
69
+ // Setup error handling
70
+ this.setupErrorHandling();
71
+ }
72
+ /**
73
+ * Initialize the server
74
+ */
75
+ LanonasisMCPServer.prototype.initialize = function () {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var apiUrl, token;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ // Initialize configuration
82
+ return [4 /*yield*/, this.config.init()];
83
+ case 1:
84
+ // Initialize configuration
85
+ _a.sent();
86
+ if (!this.options.apiUrl) return [3 /*break*/, 3];
87
+ return [4 /*yield*/, this.config.setApiUrl(this.options.apiUrl)];
88
+ case 2:
89
+ _a.sent();
90
+ _a.label = 3;
91
+ case 3:
92
+ if (!this.options.token) return [3 /*break*/, 5];
93
+ return [4 /*yield*/, this.config.setToken(this.options.token)];
94
+ case 4:
95
+ _a.sent();
96
+ _a.label = 5;
97
+ case 5:
98
+ apiUrl = this.config.getApiUrl();
99
+ token = this.config.getToken();
100
+ if (apiUrl) {
101
+ this.apiClient = new api_js_1.APIClient();
102
+ // APIClient will use the config internally
103
+ }
104
+ // Register tools, resources, and prompts after config is loaded
105
+ return [4 /*yield*/, this.registerTools()];
106
+ case 6:
107
+ // Register tools, resources, and prompts after config is loaded
108
+ _a.sent();
109
+ return [4 /*yield*/, this.registerResources()];
110
+ case 7:
111
+ _a.sent();
112
+ return [4 /*yield*/, this.registerPrompts()];
113
+ case 8:
114
+ _a.sent();
115
+ if (this.options.verbose) {
116
+ console.log(chalk_1.default.cyan('🚀 Lanonasis MCP Server initialized'));
117
+ console.log(chalk_1.default.gray("API URL: ".concat(apiUrl)));
118
+ console.log(chalk_1.default.gray("Authenticated: ".concat(token ? 'Yes' : 'No')));
119
+ }
120
+ return [2 /*return*/];
121
+ }
122
+ });
123
+ });
124
+ };
125
+ /**
126
+ * Register MCP tools
127
+ */
128
+ LanonasisMCPServer.prototype.registerTools = function () {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var _a, ListToolsRequestSchema, CallToolRequestSchema;
131
+ var _this = this;
132
+ return __generator(this, function (_b) {
133
+ switch (_b.label) {
134
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require('@modelcontextprotocol/sdk/types.js'); })];
135
+ case 1:
136
+ _a = _b.sent(), ListToolsRequestSchema = _a.ListToolsRequestSchema, CallToolRequestSchema = _a.CallToolRequestSchema;
137
+ // List available tools
138
+ this.server.setRequestHandler(ListToolsRequestSchema, function () { return __awaiter(_this, void 0, void 0, function () {
139
+ return __generator(this, function (_a) {
140
+ return [2 /*return*/, ({
141
+ tools: [
142
+ // Memory tools
143
+ {
144
+ name: 'memory_create',
145
+ description: 'Create a new memory entry',
146
+ inputSchema: {
147
+ type: 'object',
148
+ properties: {
149
+ title: {
150
+ type: 'string',
151
+ description: 'Memory title'
152
+ },
153
+ content: {
154
+ type: 'string',
155
+ description: 'Memory content'
156
+ },
157
+ memory_type: {
158
+ type: 'string',
159
+ enum: ['context', 'reference', 'note'],
160
+ default: 'context',
161
+ description: 'Type of memory'
162
+ },
163
+ tags: {
164
+ type: 'array',
165
+ items: { type: 'string' },
166
+ description: 'Optional tags for the memory'
167
+ }
168
+ },
169
+ required: ['title', 'content']
170
+ }
171
+ },
172
+ {
173
+ name: 'memory_search',
174
+ description: 'Search memories using semantic search',
175
+ inputSchema: {
176
+ type: 'object',
177
+ properties: {
178
+ query: {
179
+ type: 'string',
180
+ description: 'Search query'
181
+ },
182
+ limit: {
183
+ type: 'number',
184
+ default: 10,
185
+ description: 'Maximum number of results'
186
+ },
187
+ threshold: {
188
+ type: 'number',
189
+ minimum: 0,
190
+ maximum: 1,
191
+ default: 0.7,
192
+ description: 'Similarity threshold'
193
+ }
194
+ },
195
+ required: ['query']
196
+ }
197
+ },
198
+ {
199
+ name: 'memory_list',
200
+ description: 'List all memory entries',
201
+ inputSchema: {
202
+ type: 'object',
203
+ properties: {
204
+ limit: {
205
+ type: 'number',
206
+ default: 20,
207
+ description: 'Maximum number of results'
208
+ },
209
+ offset: {
210
+ type: 'number',
211
+ default: 0,
212
+ description: 'Pagination offset'
213
+ },
214
+ topic_id: {
215
+ type: 'string',
216
+ description: 'Filter by topic ID'
217
+ }
218
+ }
219
+ }
220
+ },
221
+ {
222
+ name: 'memory_get',
223
+ description: 'Get a specific memory by ID',
224
+ inputSchema: {
225
+ type: 'object',
226
+ properties: {
227
+ memory_id: {
228
+ type: 'string',
229
+ description: 'Memory ID'
230
+ }
231
+ },
232
+ required: ['memory_id']
233
+ }
234
+ },
235
+ {
236
+ name: 'memory_update',
237
+ description: 'Update an existing memory',
238
+ inputSchema: {
239
+ type: 'object',
240
+ properties: {
241
+ memory_id: {
242
+ type: 'string',
243
+ description: 'Memory ID'
244
+ },
245
+ title: {
246
+ type: 'string',
247
+ description: 'New title (optional)'
248
+ },
249
+ content: {
250
+ type: 'string',
251
+ description: 'New content (optional)'
252
+ },
253
+ tags: {
254
+ type: 'array',
255
+ items: { type: 'string' },
256
+ description: 'New tags (optional)'
257
+ }
258
+ },
259
+ required: ['memory_id']
260
+ }
261
+ },
262
+ {
263
+ name: 'memory_delete',
264
+ description: 'Delete a memory',
265
+ inputSchema: {
266
+ type: 'object',
267
+ properties: {
268
+ memory_id: {
269
+ type: 'string',
270
+ description: 'Memory ID'
271
+ }
272
+ },
273
+ required: ['memory_id']
274
+ }
275
+ },
276
+ // Topic tools
277
+ {
278
+ name: 'topic_create',
279
+ description: 'Create a new topic',
280
+ inputSchema: {
281
+ type: 'object',
282
+ properties: {
283
+ name: {
284
+ type: 'string',
285
+ description: 'Topic name'
286
+ },
287
+ description: {
288
+ type: 'string',
289
+ description: 'Topic description'
290
+ }
291
+ },
292
+ required: ['name']
293
+ }
294
+ },
295
+ {
296
+ name: 'topic_list',
297
+ description: 'List all topics',
298
+ inputSchema: {
299
+ type: 'object',
300
+ properties: {
301
+ limit: {
302
+ type: 'number',
303
+ default: 20
304
+ }
305
+ }
306
+ }
307
+ },
308
+ // API Key tools
309
+ {
310
+ name: 'apikey_create',
311
+ description: 'Create a new API key',
312
+ inputSchema: {
313
+ type: 'object',
314
+ properties: {
315
+ name: {
316
+ type: 'string',
317
+ description: 'API key name'
318
+ },
319
+ permissions: {
320
+ type: 'array',
321
+ items: {
322
+ type: 'string',
323
+ enum: ['read', 'write', 'delete']
324
+ },
325
+ default: ['read']
326
+ }
327
+ },
328
+ required: ['name']
329
+ }
330
+ },
331
+ {
332
+ name: 'apikey_list',
333
+ description: 'List all API keys',
334
+ inputSchema: {
335
+ type: 'object',
336
+ properties: {}
337
+ }
338
+ },
339
+ // System tools
340
+ {
341
+ name: 'system_health',
342
+ description: 'Check system health status',
343
+ inputSchema: {
344
+ type: 'object',
345
+ properties: {
346
+ verbose: {
347
+ type: 'boolean',
348
+ default: false,
349
+ description: 'Include detailed diagnostics'
350
+ }
351
+ }
352
+ }
353
+ },
354
+ {
355
+ name: 'system_config',
356
+ description: 'Get or update system configuration',
357
+ inputSchema: {
358
+ type: 'object',
359
+ properties: {
360
+ action: {
361
+ type: 'string',
362
+ enum: ['get', 'set'],
363
+ default: 'get'
364
+ },
365
+ key: {
366
+ type: 'string',
367
+ description: 'Configuration key'
368
+ },
369
+ value: {
370
+ type: 'string',
371
+ description: 'Configuration value (for set action)'
372
+ }
373
+ }
374
+ }
375
+ }
376
+ ]
377
+ })];
378
+ });
379
+ }); });
380
+ // Tool call handler (CallToolRequestSchema already imported above)
381
+ this.server.setRequestHandler(CallToolRequestSchema, function (request) { return __awaiter(_this, void 0, void 0, function () {
382
+ var _a, name, args, result, error_1;
383
+ return __generator(this, function (_b) {
384
+ switch (_b.label) {
385
+ case 0:
386
+ _a = request.params, name = _a.name, args = _a.arguments;
387
+ _b.label = 1;
388
+ case 1:
389
+ _b.trys.push([1, 3, , 4]);
390
+ return [4 /*yield*/, this.handleToolCall(name, args)];
391
+ case 2:
392
+ result = _b.sent();
393
+ return [2 /*return*/, {
394
+ content: [
395
+ {
396
+ type: 'text',
397
+ text: JSON.stringify(result, null, 2)
398
+ }
399
+ ]
400
+ }];
401
+ case 3:
402
+ error_1 = _b.sent();
403
+ return [2 /*return*/, {
404
+ content: [
405
+ {
406
+ type: 'text',
407
+ text: "Error: ".concat(error_1 instanceof Error ? error_1.message : 'Unknown error')
408
+ }
409
+ ],
410
+ isError: true
411
+ }];
412
+ case 4: return [2 /*return*/];
413
+ }
414
+ });
415
+ }); });
416
+ return [2 /*return*/];
417
+ }
418
+ });
419
+ });
420
+ };
421
+ /**
422
+ * Register MCP resources
423
+ */
424
+ LanonasisMCPServer.prototype.registerResources = function () {
425
+ return __awaiter(this, void 0, void 0, function () {
426
+ var _a, ListResourcesRequestSchema, ReadResourceRequestSchema;
427
+ var _this = this;
428
+ return __generator(this, function (_b) {
429
+ switch (_b.label) {
430
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require('@modelcontextprotocol/sdk/types.js'); })];
431
+ case 1:
432
+ _a = _b.sent(), ListResourcesRequestSchema = _a.ListResourcesRequestSchema, ReadResourceRequestSchema = _a.ReadResourceRequestSchema;
433
+ this.server.setRequestHandler(ListResourcesRequestSchema, function () { return __awaiter(_this, void 0, void 0, function () {
434
+ return __generator(this, function (_a) {
435
+ return [2 /*return*/, ({
436
+ resources: [
437
+ {
438
+ uri: 'memory://recent',
439
+ name: 'Recent Memories',
440
+ description: 'List of recently created or updated memories',
441
+ mimeType: 'application/json'
442
+ },
443
+ {
444
+ uri: 'memory://search',
445
+ name: 'Memory Search',
446
+ description: 'Search interface for memories',
447
+ mimeType: 'application/json'
448
+ },
449
+ {
450
+ uri: 'config://current',
451
+ name: 'Current Configuration',
452
+ description: 'Current CLI configuration settings',
453
+ mimeType: 'application/json'
454
+ },
455
+ {
456
+ uri: 'stats://usage',
457
+ name: 'Usage Statistics',
458
+ description: 'Memory usage and API statistics',
459
+ mimeType: 'application/json'
460
+ }
461
+ ]
462
+ })];
463
+ });
464
+ }); });
465
+ this.server.setRequestHandler(ReadResourceRequestSchema, function (request) { return __awaiter(_this, void 0, void 0, function () {
466
+ var uri, content, error_2;
467
+ return __generator(this, function (_a) {
468
+ switch (_a.label) {
469
+ case 0:
470
+ uri = request.params.uri;
471
+ _a.label = 1;
472
+ case 1:
473
+ _a.trys.push([1, 3, , 4]);
474
+ return [4 /*yield*/, this.handleResourceRead(uri)];
475
+ case 2:
476
+ content = _a.sent();
477
+ return [2 /*return*/, {
478
+ contents: [
479
+ {
480
+ uri: uri,
481
+ mimeType: 'application/json',
482
+ text: JSON.stringify(content, null, 2)
483
+ }
484
+ ]
485
+ }];
486
+ case 3:
487
+ error_2 = _a.sent();
488
+ throw new Error("Failed to read resource ".concat(uri, ": ").concat(error_2));
489
+ case 4: return [2 /*return*/];
490
+ }
491
+ });
492
+ }); });
493
+ return [2 /*return*/];
494
+ }
495
+ });
496
+ });
497
+ };
498
+ /**
499
+ * Register MCP prompts
500
+ */
501
+ LanonasisMCPServer.prototype.registerPrompts = function () {
502
+ return __awaiter(this, void 0, void 0, function () {
503
+ var _a, ListPromptsRequestSchema, GetPromptRequestSchema;
504
+ var _this = this;
505
+ return __generator(this, function (_b) {
506
+ switch (_b.label) {
507
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require('@modelcontextprotocol/sdk/types.js'); })];
508
+ case 1:
509
+ _a = _b.sent(), ListPromptsRequestSchema = _a.ListPromptsRequestSchema, GetPromptRequestSchema = _a.GetPromptRequestSchema;
510
+ this.server.setRequestHandler(ListPromptsRequestSchema, function () { return __awaiter(_this, void 0, void 0, function () {
511
+ return __generator(this, function (_a) {
512
+ return [2 /*return*/, ({
513
+ prompts: [
514
+ {
515
+ name: 'create_memory',
516
+ description: 'Interactive prompt to create a new memory',
517
+ arguments: [
518
+ {
519
+ name: 'title',
520
+ description: 'Initial title for the memory',
521
+ required: false
522
+ }
523
+ ]
524
+ },
525
+ {
526
+ name: 'search_memories',
527
+ description: 'Interactive prompt to search memories',
528
+ arguments: [
529
+ {
530
+ name: 'query',
531
+ description: 'Initial search query',
532
+ required: false
533
+ }
534
+ ]
535
+ },
536
+ {
537
+ name: 'organize_memories',
538
+ description: 'Interactive prompt to organize memories into topics',
539
+ arguments: []
540
+ }
541
+ ]
542
+ })];
543
+ });
544
+ }); });
545
+ this.server.setRequestHandler(GetPromptRequestSchema, function (request) { return __awaiter(_this, void 0, void 0, function () {
546
+ var _a, name, args, prompts, prompt;
547
+ return __generator(this, function (_b) {
548
+ _a = request.params, name = _a.name, args = _a.arguments;
549
+ prompts = {
550
+ create_memory: {
551
+ description: 'Create a new memory entry',
552
+ messages: [
553
+ {
554
+ role: 'user',
555
+ content: {
556
+ type: 'text',
557
+ text: "Please provide the following information for the new memory:\n \nTitle: ".concat((args === null || args === void 0 ? void 0 : args.title) || '[Enter a descriptive title]', "\nContent: [Enter the memory content]\nType: [context/reference/note]\nTags: [Optional comma-separated tags]")
558
+ }
559
+ }
560
+ ]
561
+ },
562
+ search_memories: {
563
+ description: 'Search through your memories',
564
+ messages: [
565
+ {
566
+ role: 'user',
567
+ content: {
568
+ type: 'text',
569
+ text: "What would you like to search for in your memories?\n \nQuery: ".concat((args === null || args === void 0 ? void 0 : args.query) || '[Enter search terms]', "\nLimit: [Number of results, default 10]\nThreshold: [Similarity threshold 0-1, default 0.7]")
570
+ }
571
+ }
572
+ ]
573
+ },
574
+ organize_memories: {
575
+ description: 'Organize memories into topics',
576
+ messages: [
577
+ {
578
+ role: 'user',
579
+ content: {
580
+ type: 'text',
581
+ text: "Let's organize your memories into topics.\n \nWould you like to:\n1. Create a new topic\n2. Move memories to existing topics\n3. Review uncategorized memories\n4. Merge similar topics\n\nPlease choose an option (1-4):"
582
+ }
583
+ }
584
+ ]
585
+ }
586
+ };
587
+ prompt = prompts[name];
588
+ if (!prompt) {
589
+ throw new Error("Unknown prompt: ".concat(name));
590
+ }
591
+ return [2 /*return*/, prompt];
592
+ });
593
+ }); });
594
+ return [2 /*return*/];
595
+ }
596
+ });
597
+ });
598
+ };
599
+ /**
600
+ * Handle tool calls
601
+ */
602
+ LanonasisMCPServer.prototype.handleToolCall = function (name, args) {
603
+ return __awaiter(this, void 0, void 0, function () {
604
+ var _a;
605
+ return __generator(this, function (_b) {
606
+ switch (_b.label) {
607
+ case 0:
608
+ if (!!this.apiClient) return [3 /*break*/, 2];
609
+ return [4 /*yield*/, this.initialize()];
610
+ case 1:
611
+ _b.sent();
612
+ _b.label = 2;
613
+ case 2:
614
+ _a = name;
615
+ switch (_a) {
616
+ case 'memory_create': return [3 /*break*/, 3];
617
+ case 'memory_search': return [3 /*break*/, 5];
618
+ case 'memory_list': return [3 /*break*/, 7];
619
+ case 'memory_get': return [3 /*break*/, 9];
620
+ case 'memory_update': return [3 /*break*/, 11];
621
+ case 'memory_delete': return [3 /*break*/, 13];
622
+ case 'topic_create': return [3 /*break*/, 15];
623
+ case 'topic_list': return [3 /*break*/, 17];
624
+ case 'apikey_create': return [3 /*break*/, 19];
625
+ case 'apikey_list': return [3 /*break*/, 20];
626
+ case 'system_health': return [3 /*break*/, 21];
627
+ case 'system_config': return [3 /*break*/, 23];
628
+ }
629
+ return [3 /*break*/, 25];
630
+ case 3: return [4 /*yield*/, this.apiClient.createMemory(args)];
631
+ case 4: return [2 /*return*/, _b.sent()];
632
+ case 5: return [4 /*yield*/, this.apiClient.searchMemories(args.query, {
633
+ limit: args.limit,
634
+ threshold: args.threshold
635
+ })];
636
+ case 6: return [2 /*return*/, _b.sent()];
637
+ case 7: return [4 /*yield*/, this.apiClient.getMemories({
638
+ limit: args.limit,
639
+ offset: args.offset,
640
+ topic_id: args.topic_id
641
+ })];
642
+ case 8: return [2 /*return*/, _b.sent()];
643
+ case 9: return [4 /*yield*/, this.apiClient.getMemory(args.memory_id)];
644
+ case 10: return [2 /*return*/, _b.sent()];
645
+ case 11: return [4 /*yield*/, this.apiClient.updateMemory(args.memory_id, args)];
646
+ case 12: return [2 /*return*/, _b.sent()];
647
+ case 13: return [4 /*yield*/, this.apiClient.deleteMemory(args.memory_id)];
648
+ case 14: return [2 /*return*/, _b.sent()];
649
+ case 15: return [4 /*yield*/, this.apiClient.createTopic(args)];
650
+ case 16: return [2 /*return*/, _b.sent()];
651
+ case 17: return [4 /*yield*/, this.apiClient.getTopics()];
652
+ case 18: return [2 /*return*/, _b.sent()];
653
+ case 19:
654
+ // API keys not directly supported in current APIClient
655
+ return [2 /*return*/, { error: 'API key creation not yet implemented' }];
656
+ case 20:
657
+ // API keys not directly supported in current APIClient
658
+ return [2 /*return*/, { error: 'API key listing not yet implemented' }];
659
+ case 21: return [4 /*yield*/, this.handleSystemHealth(args.verbose)];
660
+ case 22: return [2 /*return*/, _b.sent()];
661
+ case 23: return [4 /*yield*/, this.handleSystemConfig(args)];
662
+ case 24: return [2 /*return*/, _b.sent()];
663
+ case 25: throw new Error("Unknown tool: ".concat(name));
664
+ }
665
+ });
666
+ });
667
+ };
668
+ /**
669
+ * Handle resource reads
670
+ */
671
+ LanonasisMCPServer.prototype.handleResourceRead = function (uri) {
672
+ return __awaiter(this, void 0, void 0, function () {
673
+ var _a, protocol, path, _b;
674
+ var _c;
675
+ return __generator(this, function (_d) {
676
+ switch (_d.label) {
677
+ case 0:
678
+ _a = uri.split('://'), protocol = _a[0], path = _a[1];
679
+ _b = protocol;
680
+ switch (_b) {
681
+ case 'memory': return [3 /*break*/, 1];
682
+ case 'config': return [3 /*break*/, 5];
683
+ case 'stats': return [3 /*break*/, 10];
684
+ }
685
+ return [3 /*break*/, 11];
686
+ case 1:
687
+ if (!(path === 'recent')) return [3 /*break*/, 3];
688
+ return [4 /*yield*/, this.apiClient.getMemories({ limit: 10 })];
689
+ case 2: return [2 /*return*/, _d.sent()];
690
+ case 3:
691
+ if (path === 'search') {
692
+ return [2 /*return*/, {
693
+ message: 'Use memory_search tool to search memories',
694
+ example: { query: 'your search query', limit: 10 }
695
+ }];
696
+ }
697
+ _d.label = 4;
698
+ case 4: return [3 /*break*/, 11];
699
+ case 5:
700
+ if (!(path === 'current')) return [3 /*break*/, 9];
701
+ return [4 /*yield*/, this.config.init()];
702
+ case 6:
703
+ _d.sent();
704
+ _c = {
705
+ apiUrl: this.config.getApiUrl()
706
+ };
707
+ return [4 /*yield*/, this.config.isAuthenticated()];
708
+ case 7:
709
+ _c.authenticated = _d.sent();
710
+ return [4 /*yield*/, this.config.getCurrentUser()];
711
+ case 8: return [2 /*return*/, (_c.user = _d.sent(),
712
+ _c)];
713
+ case 9: return [3 /*break*/, 11];
714
+ case 10:
715
+ if (path === 'usage') {
716
+ // TODO: Implement actual stats collection
717
+ return [2 /*return*/, {
718
+ totalMemories: 0,
719
+ totalTopics: 0,
720
+ apiCallsToday: 0,
721
+ lastSync: new Date().toISOString()
722
+ }];
723
+ }
724
+ return [3 /*break*/, 11];
725
+ case 11: throw new Error("Unknown resource: ".concat(uri));
726
+ }
727
+ });
728
+ });
729
+ };
730
+ /**
731
+ * Handle system health check
732
+ */
733
+ LanonasisMCPServer.prototype.handleSystemHealth = function (verbose) {
734
+ return __awaiter(this, void 0, void 0, function () {
735
+ var health, _a, apiHealth, error_3;
736
+ var _b;
737
+ return __generator(this, function (_c) {
738
+ switch (_c.label) {
739
+ case 0:
740
+ health = {
741
+ status: 'healthy',
742
+ server: this.options.name || 'lanonasis-maas-server',
743
+ version: this.options.version || '3.0.1',
744
+ timestamp: new Date().toISOString()
745
+ };
746
+ if (!verbose) return [3 /*break*/, 5];
747
+ _a = health;
748
+ _b = {
749
+ url: this.config.getApiUrl()
750
+ };
751
+ return [4 /*yield*/, this.config.isAuthenticated()];
752
+ case 1:
753
+ _a.api = (_b.authenticated = _c.sent(),
754
+ _b);
755
+ _c.label = 2;
756
+ case 2:
757
+ _c.trys.push([2, 4, , 5]);
758
+ return [4 /*yield*/, this.apiClient.getHealth()];
759
+ case 3:
760
+ apiHealth = _c.sent();
761
+ health.api.status = apiHealth.status;
762
+ health.api.version = apiHealth.version;
763
+ return [3 /*break*/, 5];
764
+ case 4:
765
+ error_3 = _c.sent();
766
+ health.api.status = 'error';
767
+ health.api.error = error_3 instanceof Error ? error_3.message : 'Unknown error';
768
+ return [3 /*break*/, 5];
769
+ case 5: return [2 /*return*/, health];
770
+ }
771
+ });
772
+ });
773
+ };
774
+ /**
775
+ * Handle system configuration
776
+ */
777
+ LanonasisMCPServer.prototype.handleSystemConfig = function (args) {
778
+ return __awaiter(this, void 0, void 0, function () {
779
+ var _a;
780
+ return __generator(this, function (_b) {
781
+ switch (_b.label) {
782
+ case 0:
783
+ if (!(args.action === 'get')) return [3 /*break*/, 4];
784
+ if (!args.key) return [3 /*break*/, 1];
785
+ return [2 /*return*/, (_a = {}, _a[args.key] = this.config.get(args.key), _a)];
786
+ case 1:
787
+ // Return all config
788
+ return [4 /*yield*/, this.config.init()];
789
+ case 2:
790
+ // Return all config
791
+ _b.sent();
792
+ return [2 /*return*/, {
793
+ apiUrl: this.config.getApiUrl(),
794
+ mcpServerUrl: this.config.get('mcpServerUrl'),
795
+ mcpUseRemote: this.config.get('mcpUseRemote')
796
+ }];
797
+ case 3: return [3 /*break*/, 6];
798
+ case 4:
799
+ if (!(args.action === 'set')) return [3 /*break*/, 6];
800
+ if (!args.key || !args.value) {
801
+ throw new Error('Key and value required for set action');
802
+ }
803
+ this.config.set(args.key, args.value);
804
+ return [4 /*yield*/, this.config.save()];
805
+ case 5:
806
+ _b.sent();
807
+ return [2 /*return*/, {
808
+ success: true,
809
+ message: "Set ".concat(args.key, " to ").concat(args.value)
810
+ }];
811
+ case 6: throw new Error('Invalid action');
812
+ }
813
+ });
814
+ });
815
+ };
816
+ /**
817
+ * Setup error handling
818
+ */
819
+ LanonasisMCPServer.prototype.setupErrorHandling = function () {
820
+ var _this = this;
821
+ process.on('SIGINT', function () { return __awaiter(_this, void 0, void 0, function () {
822
+ return __generator(this, function (_a) {
823
+ switch (_a.label) {
824
+ case 0:
825
+ console.log(chalk_1.default.yellow('\n⚠️ Shutting down MCP server...'));
826
+ return [4 /*yield*/, this.stop()];
827
+ case 1:
828
+ _a.sent();
829
+ process.exit(0);
830
+ return [2 /*return*/];
831
+ }
832
+ });
833
+ }); });
834
+ process.on('uncaughtException', function (error) {
835
+ console.error(chalk_1.default.red('Uncaught exception:'), error);
836
+ process.exit(1);
837
+ });
838
+ process.on('unhandledRejection', function (reason, promise) {
839
+ console.error(chalk_1.default.red('Unhandled rejection at:'), promise, 'reason:', reason);
840
+ });
841
+ };
842
+ /**
843
+ * Start the server
844
+ */
845
+ LanonasisMCPServer.prototype.start = function () {
846
+ return __awaiter(this, void 0, void 0, function () {
847
+ return __generator(this, function (_a) {
848
+ switch (_a.label) {
849
+ case 0: return [4 /*yield*/, this.initialize()];
850
+ case 1:
851
+ _a.sent();
852
+ // Create and connect transport
853
+ this.transport = new stdio_js_1.StdioServerTransport();
854
+ return [4 /*yield*/, this.server.connect(this.transport)];
855
+ case 2:
856
+ _a.sent();
857
+ if (this.options.verbose) {
858
+ console.log(chalk_1.default.green('✅ Lanonasis MCP Server started'));
859
+ console.log(chalk_1.default.gray('Waiting for client connections...'));
860
+ }
861
+ // Keep the process alive
862
+ process.stdin.resume();
863
+ return [2 /*return*/];
864
+ }
865
+ });
866
+ });
867
+ };
868
+ /**
869
+ * Stop the server
870
+ */
871
+ LanonasisMCPServer.prototype.stop = function () {
872
+ return __awaiter(this, void 0, void 0, function () {
873
+ return __generator(this, function (_a) {
874
+ switch (_a.label) {
875
+ case 0:
876
+ if (!this.transport) return [3 /*break*/, 2];
877
+ return [4 /*yield*/, this.server.close()];
878
+ case 1:
879
+ _a.sent();
880
+ this.transport = null;
881
+ _a.label = 2;
882
+ case 2:
883
+ if (this.options.verbose) {
884
+ console.log(chalk_1.default.gray('MCP Server stopped'));
885
+ }
886
+ return [2 /*return*/];
887
+ }
888
+ });
889
+ });
890
+ };
891
+ /**
892
+ * Get server instance (for testing)
893
+ */
894
+ LanonasisMCPServer.prototype.getServer = function () {
895
+ return this.server;
896
+ };
897
+ return LanonasisMCPServer;
898
+ }());
899
+ exports.LanonasisMCPServer = LanonasisMCPServer;
900
+ // CLI entry point
901
+ if (import.meta.url === "file://".concat(process.argv[1])) {
902
+ var server = new LanonasisMCPServer({
903
+ verbose: process.argv.includes('--verbose'),
904
+ apiUrl: process.env.LANONASIS_API_URL,
905
+ token: process.env.LANONASIS_TOKEN
906
+ });
907
+ server.start().catch(function (error) {
908
+ console.error(chalk_1.default.red('Failed to start server:'), error);
909
+ process.exit(1);
910
+ });
911
+ }