@lanonasis/cli 2.0.7 → 3.0.1

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,378 @@
1
+ /**
2
+ * MCP Tool Schema Definitions
3
+ * Provides Zod-based validation for all MCP tools
4
+ */
5
+ import { z } from 'zod';
6
+ // Memory schemas
7
+ export const MemoryCreateSchema = z.object({
8
+ title: z.string()
9
+ .min(1, 'Title is required')
10
+ .max(200, 'Title must be less than 200 characters')
11
+ .describe("Memory title"),
12
+ content: z.string()
13
+ .min(1, 'Content is required')
14
+ .describe("Memory content"),
15
+ memory_type: z.enum(["context", "reference", "note"])
16
+ .default("context")
17
+ .describe("Type of memory"),
18
+ tags: z.array(z.string())
19
+ .optional()
20
+ .describe("Optional tags for categorization"),
21
+ topic_id: z.string()
22
+ .uuid()
23
+ .optional()
24
+ .describe("Optional topic ID for organization"),
25
+ metadata: z.record(z.any())
26
+ .optional()
27
+ .describe("Additional metadata")
28
+ });
29
+ export const MemorySearchSchema = z.object({
30
+ query: z.string()
31
+ .min(1, 'Search query is required')
32
+ .describe("Search query for semantic search"),
33
+ limit: z.number()
34
+ .int()
35
+ .positive()
36
+ .max(100)
37
+ .default(10)
38
+ .describe("Maximum number of results"),
39
+ threshold: z.number()
40
+ .min(0)
41
+ .max(1)
42
+ .default(0.7)
43
+ .describe("Similarity threshold (0-1)"),
44
+ topic_id: z.string()
45
+ .uuid()
46
+ .optional()
47
+ .describe("Filter by topic ID"),
48
+ tags: z.array(z.string())
49
+ .optional()
50
+ .describe("Filter by tags"),
51
+ memory_type: z.enum(["context", "reference", "note"])
52
+ .optional()
53
+ .describe("Filter by memory type")
54
+ });
55
+ export const MemoryUpdateSchema = z.object({
56
+ memory_id: z.string()
57
+ .uuid()
58
+ .describe("Memory ID to update"),
59
+ title: z.string()
60
+ .min(1)
61
+ .max(200)
62
+ .optional()
63
+ .describe("New title"),
64
+ content: z.string()
65
+ .min(1)
66
+ .optional()
67
+ .describe("New content"),
68
+ memory_type: z.enum(["context", "reference", "note"])
69
+ .optional()
70
+ .describe("New memory type"),
71
+ tags: z.array(z.string())
72
+ .optional()
73
+ .describe("New tags (replaces existing)"),
74
+ metadata: z.record(z.any())
75
+ .optional()
76
+ .describe("New metadata (merges with existing)")
77
+ });
78
+ export const MemoryDeleteSchema = z.object({
79
+ memory_id: z.string()
80
+ .uuid()
81
+ .describe("Memory ID to delete"),
82
+ confirm: z.boolean()
83
+ .default(false)
84
+ .describe("Confirmation flag for deletion")
85
+ });
86
+ export const MemoryListSchema = z.object({
87
+ limit: z.number()
88
+ .int()
89
+ .positive()
90
+ .max(100)
91
+ .default(20)
92
+ .describe("Maximum number of results"),
93
+ offset: z.number()
94
+ .int()
95
+ .min(0)
96
+ .default(0)
97
+ .describe("Pagination offset"),
98
+ topic_id: z.string()
99
+ .uuid()
100
+ .optional()
101
+ .describe("Filter by topic ID"),
102
+ tags: z.array(z.string())
103
+ .optional()
104
+ .describe("Filter by tags"),
105
+ memory_type: z.enum(["context", "reference", "note"])
106
+ .optional()
107
+ .describe("Filter by memory type"),
108
+ sort_by: z.enum(["created_at", "updated_at", "title"])
109
+ .default("created_at")
110
+ .describe("Sort field"),
111
+ order: z.enum(["asc", "desc"])
112
+ .default("desc")
113
+ .describe("Sort order")
114
+ });
115
+ // Topic schemas
116
+ export const TopicCreateSchema = z.object({
117
+ name: z.string()
118
+ .min(1, 'Topic name is required')
119
+ .max(100, 'Topic name must be less than 100 characters')
120
+ .describe("Topic name"),
121
+ description: z.string()
122
+ .max(500)
123
+ .optional()
124
+ .describe("Topic description"),
125
+ parent_id: z.string()
126
+ .uuid()
127
+ .optional()
128
+ .describe("Parent topic ID for nesting"),
129
+ color: z.string()
130
+ .regex(/^#[0-9A-Fa-f]{6}$/)
131
+ .optional()
132
+ .describe("Topic color in hex format"),
133
+ icon: z.string()
134
+ .optional()
135
+ .describe("Topic icon identifier")
136
+ });
137
+ export const TopicUpdateSchema = z.object({
138
+ topic_id: z.string()
139
+ .uuid()
140
+ .describe("Topic ID to update"),
141
+ name: z.string()
142
+ .min(1)
143
+ .max(100)
144
+ .optional()
145
+ .describe("New name"),
146
+ description: z.string()
147
+ .max(500)
148
+ .optional()
149
+ .describe("New description"),
150
+ parent_id: z.string()
151
+ .uuid()
152
+ .nullable()
153
+ .optional()
154
+ .describe("New parent topic ID"),
155
+ color: z.string()
156
+ .regex(/^#[0-9A-Fa-f]{6}$/)
157
+ .optional()
158
+ .describe("New color"),
159
+ icon: z.string()
160
+ .optional()
161
+ .describe("New icon")
162
+ });
163
+ export const TopicListSchema = z.object({
164
+ limit: z.number()
165
+ .int()
166
+ .positive()
167
+ .max(100)
168
+ .default(20)
169
+ .describe("Maximum number of results"),
170
+ parent_id: z.string()
171
+ .uuid()
172
+ .nullable()
173
+ .optional()
174
+ .describe("Filter by parent topic (null for root topics)"),
175
+ include_children: z.boolean()
176
+ .default(false)
177
+ .describe("Include child topics in results")
178
+ });
179
+ // API Key schemas
180
+ export const ApiKeyCreateSchema = z.object({
181
+ name: z.string()
182
+ .min(1, 'API key name is required')
183
+ .max(100, 'Name must be less than 100 characters')
184
+ .describe("API key name for identification"),
185
+ permissions: z.array(z.enum(["read", "write", "delete", "admin"]))
186
+ .default(["read"])
187
+ .describe("Permissions for the API key"),
188
+ expires_at: z.string()
189
+ .datetime()
190
+ .optional()
191
+ .describe("Optional expiration date (ISO 8601)")
192
+ });
193
+ export const ApiKeyRevokeSchema = z.object({
194
+ key_id: z.string()
195
+ .describe("API key ID to revoke"),
196
+ reason: z.string()
197
+ .optional()
198
+ .describe("Reason for revocation")
199
+ });
200
+ // System schemas
201
+ export const SystemHealthSchema = z.object({
202
+ verbose: z.boolean()
203
+ .default(false)
204
+ .describe("Include detailed diagnostics"),
205
+ include_dependencies: z.boolean()
206
+ .default(true)
207
+ .describe("Check dependency health"),
208
+ timeout: z.number()
209
+ .positive()
210
+ .default(5000)
211
+ .describe("Health check timeout in milliseconds")
212
+ });
213
+ export const SystemConfigSchema = z.object({
214
+ action: z.enum(["get", "set", "reset"])
215
+ .describe("Configuration action"),
216
+ key: z.string()
217
+ .optional()
218
+ .describe("Configuration key (required for set/get specific)"),
219
+ value: z.any()
220
+ .optional()
221
+ .describe("Configuration value (required for set)"),
222
+ scope: z.enum(["user", "global"])
223
+ .default("user")
224
+ .describe("Configuration scope")
225
+ });
226
+ // Advanced operation schemas
227
+ export const BulkOperationSchema = z.object({
228
+ operation: z.enum(["create", "update", "delete"])
229
+ .describe("Bulk operation type"),
230
+ entity_type: z.enum(["memory", "topic", "apikey"])
231
+ .describe("Entity type for bulk operation"),
232
+ items: z.array(z.record(z.any()))
233
+ .min(1)
234
+ .max(100)
235
+ .describe("Items for bulk operation"),
236
+ transaction: z.boolean()
237
+ .default(true)
238
+ .describe("Execute as transaction (all or nothing)")
239
+ });
240
+ export const ImportExportSchema = z.object({
241
+ action: z.enum(["import", "export"])
242
+ .describe("Import or export action"),
243
+ format: z.enum(["json", "csv", "markdown"])
244
+ .default("json")
245
+ .describe("Data format"),
246
+ entity_type: z.enum(["memory", "topic", "all"])
247
+ .default("all")
248
+ .describe("Entity type to import/export"),
249
+ file_path: z.string()
250
+ .optional()
251
+ .describe("File path for import/export"),
252
+ filters: z.record(z.any())
253
+ .optional()
254
+ .describe("Filters for export")
255
+ });
256
+ // Tool execution schema
257
+ export const ToolExecutionSchema = z.object({
258
+ tool_name: z.string()
259
+ .describe("Name of the tool to execute"),
260
+ arguments: z.record(z.any())
261
+ .describe("Tool arguments"),
262
+ timeout: z.number()
263
+ .positive()
264
+ .default(30000)
265
+ .describe("Execution timeout in milliseconds"),
266
+ retry_on_failure: z.boolean()
267
+ .default(false)
268
+ .describe("Retry on failure"),
269
+ max_retries: z.number()
270
+ .int()
271
+ .min(0)
272
+ .max(5)
273
+ .default(3)
274
+ .describe("Maximum retry attempts")
275
+ });
276
+ // Response schemas
277
+ export const SuccessResponseSchema = z.object({
278
+ success: z.boolean().default(true),
279
+ data: z.any(),
280
+ message: z.string().optional(),
281
+ metadata: z.object({
282
+ timestamp: z.string().datetime(),
283
+ duration_ms: z.number().optional(),
284
+ request_id: z.string().optional()
285
+ }).optional()
286
+ });
287
+ export const ErrorResponseSchema = z.object({
288
+ success: z.boolean().default(false),
289
+ error: z.object({
290
+ code: z.string(),
291
+ message: z.string(),
292
+ details: z.any().optional(),
293
+ stack: z.string().optional()
294
+ }),
295
+ metadata: z.object({
296
+ timestamp: z.string().datetime(),
297
+ request_id: z.string().optional()
298
+ }).optional()
299
+ });
300
+ // Validation helper
301
+ export class SchemaValidator {
302
+ /**
303
+ * Validate data against a schema
304
+ */
305
+ static validate(schema, data) {
306
+ try {
307
+ return schema.parse(data);
308
+ }
309
+ catch (error) {
310
+ if (error instanceof z.ZodError) {
311
+ throw new Error(`Validation error: ${error.errors
312
+ .map(e => `${e.path.join('.')}: ${e.message}`)
313
+ .join(', ')}`);
314
+ }
315
+ throw error;
316
+ }
317
+ }
318
+ /**
319
+ * Validate data and return result with errors
320
+ */
321
+ static safeParse(schema, data) {
322
+ const result = schema.safeParse(data);
323
+ if (result.success) {
324
+ return { success: true, data: result.data };
325
+ }
326
+ else {
327
+ return {
328
+ success: false,
329
+ errors: result.error.errors.map(e => `${e.path.join('.')}: ${e.message}`)
330
+ };
331
+ }
332
+ }
333
+ /**
334
+ * Get schema as JSON Schema for documentation
335
+ */
336
+ static toJsonSchema(schema) {
337
+ // This would require zodToJsonSchema package
338
+ // For now, return a simplified version
339
+ return {
340
+ type: 'object',
341
+ description: 'Schema definition',
342
+ // Additional implementation needed
343
+ };
344
+ }
345
+ }
346
+ // Export all schemas as a collection
347
+ export const MCPSchemas = {
348
+ memory: {
349
+ create: MemoryCreateSchema,
350
+ search: MemorySearchSchema,
351
+ update: MemoryUpdateSchema,
352
+ delete: MemoryDeleteSchema,
353
+ list: MemoryListSchema
354
+ },
355
+ topic: {
356
+ create: TopicCreateSchema,
357
+ update: TopicUpdateSchema,
358
+ list: TopicListSchema
359
+ },
360
+ apikey: {
361
+ create: ApiKeyCreateSchema,
362
+ revoke: ApiKeyRevokeSchema
363
+ },
364
+ system: {
365
+ health: SystemHealthSchema,
366
+ config: SystemConfigSchema
367
+ },
368
+ operations: {
369
+ bulk: BulkOperationSchema,
370
+ importExport: ImportExportSchema,
371
+ toolExecution: ToolExecutionSchema
372
+ },
373
+ responses: {
374
+ success: SuccessResponseSchema,
375
+ error: ErrorResponseSchema
376
+ }
377
+ };
378
+ export default MCPSchemas;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Lanonasis MCP Server Implementation
3
+ * Provides MCP protocol access to Lanonasis MaaS functionality
4
+ */
5
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
+ export interface LanonasisServerOptions {
7
+ name?: string;
8
+ version?: string;
9
+ verbose?: boolean;
10
+ apiUrl?: string;
11
+ token?: string;
12
+ }
13
+ export declare class LanonasisMCPServer {
14
+ private server;
15
+ private config;
16
+ private apiClient;
17
+ private transport;
18
+ private options;
19
+ constructor(options?: LanonasisServerOptions);
20
+ /**
21
+ * Initialize the server
22
+ */
23
+ initialize(): Promise<void>;
24
+ /**
25
+ * Register MCP tools
26
+ */
27
+ private registerTools;
28
+ /**
29
+ * Register MCP resources
30
+ */
31
+ private registerResources;
32
+ /**
33
+ * Register MCP prompts
34
+ */
35
+ private registerPrompts;
36
+ /**
37
+ * Handle tool calls
38
+ */
39
+ private handleToolCall;
40
+ /**
41
+ * Handle resource reads
42
+ */
43
+ private handleResourceRead;
44
+ /**
45
+ * Handle system health check
46
+ */
47
+ private handleSystemHealth;
48
+ /**
49
+ * Handle system configuration
50
+ */
51
+ private handleSystemConfig;
52
+ /**
53
+ * Setup error handling
54
+ */
55
+ private setupErrorHandling;
56
+ /**
57
+ * Start the server
58
+ */
59
+ start(): Promise<void>;
60
+ /**
61
+ * Stop the server
62
+ */
63
+ stop(): Promise<void>;
64
+ /**
65
+ * Get server instance (for testing)
66
+ */
67
+ getServer(): Server;
68
+ }