@g99/lightrag-mcp-server 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/index.js +598 -625
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,625 +1,598 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * LightRAG MCP Server - Complete Node.js Implementation
5
- *
6
- * Model Context Protocol server for LightRAG with 31 tools
7
- *
8
- * Author: Lalit Suryan
9
- * License: MIT
10
- */
11
-
12
- const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
13
- const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
14
- const {
15
- CallToolRequestSchema,
16
- ListToolsRequestSchema,
17
- } = require('@modelcontextprotocol/sdk/types.js');
18
- const axios = require('axios');
19
-
20
- // Environment configuration
21
- const LIGHTRAG_SERVER_URL = process.env.LIGHTRAG_SERVER_URL || 'http://localhost:9621';
22
- const LIGHTRAG_API_KEY = process.env.LIGHTRAG_API_KEY || '';
23
- const LIGHTRAG_WORKSPACE = process.env.LIGHTRAG_WORKSPACE || 'default';
24
-
25
- // Create HTTP client
26
- const httpClient = axios.create({
27
- baseURL: LIGHTRAG_SERVER_URL,
28
- headers: {
29
- 'Content-Type': 'application/json',
30
- ...(LIGHTRAG_API_KEY && { 'Authorization': `Bearer ${LIGHTRAG_API_KEY}` }),
31
- 'X-Workspace': LIGHTRAG_WORKSPACE
32
- },
33
- timeout: 30000
34
- });
35
-
36
- // Create MCP server
37
- const server = new Server(
38
- {
39
- name: '@g99/lightrag-mcp-server',
40
- version: '1.0.6',
41
- },
42
- {
43
- capabilities: {
44
- tools: {},
45
- },
46
- }
47
- );
48
-
49
- // All 31 Tool definitions (10 Document + 3 Query + 10 Knowledge Graph + 8 System)
50
- const tools = [
51
- // ===== DOCUMENT MANAGEMENT TOOLS (10) =====
52
- {
53
- name: 'insert_text',
54
- description: 'Insert a single text document into LightRAG',
55
- inputSchema: {
56
- type: 'object',
57
- properties: {
58
- text: { type: 'string', description: 'Text content to insert' },
59
- description: { type: 'string', description: 'Description of the text' }
60
- },
61
- required: ['text']
62
- }
63
- },
64
- {
65
- name: 'insert_texts',
66
- description: 'Insert multiple text documents into LightRAG in batch',
67
- inputSchema: {
68
- type: 'object',
69
- properties: {
70
- texts: {
71
- type: 'array',
72
- description: 'Array of text documents',
73
- items: {
74
- type: 'object',
75
- properties: {
76
- content: { type: 'string' },
77
- title: { type: 'string' },
78
- metadata: { type: 'object' }
79
- },
80
- required: ['content']
81
- }
82
- }
83
- },
84
- required: ['texts']
85
- }
86
- },
87
- {
88
- name: 'upload_document',
89
- description: 'Upload a document file to LightRAG',
90
- inputSchema: {
91
- type: 'object',
92
- properties: {
93
- file_path: { type: 'string', description: 'Path to the file' },
94
- chunk_size: { type: 'number', description: 'Custom chunk size' },
95
- chunk_overlap: { type: 'number', description: 'Overlap between chunks' }
96
- },
97
- required: ['file_path']
98
- }
99
- },
100
- {
101
- name: 'upload_documents',
102
- description: 'Upload multiple documents in batch',
103
- inputSchema: {
104
- type: 'object',
105
- properties: {
106
- file_paths: {
107
- type: 'array',
108
- items: { type: 'string' },
109
- description: 'Array of file paths'
110
- }
111
- },
112
- required: ['file_paths']
113
- }
114
- },
115
- {
116
- name: 'scan_documents',
117
- description: 'Scan for new documents in the configured directory',
118
- inputSchema: {
119
- type: 'object',
120
- properties: {}
121
- }
122
- },
123
- {
124
- name: 'get_documents',
125
- description: 'Retrieve all documents from LightRAG',
126
- inputSchema: {
127
- type: 'object',
128
- properties: {}
129
- }
130
- },
131
- {
132
- name: 'get_documents_paginated',
133
- description: 'Retrieve documents with pagination',
134
- inputSchema: {
135
- type: 'object',
136
- properties: {
137
- page: { type: 'number', description: 'Page number (1-based)' },
138
- page_size: { type: 'number', description: 'Items per page (1-100)' }
139
- },
140
- required: ['page', 'page_size']
141
- }
142
- },
143
- {
144
- name: 'delete_document',
145
- description: 'Delete a specific document by ID',
146
- inputSchema: {
147
- type: 'object',
148
- properties: {
149
- document_id: { type: 'string', description: 'ID of document to delete' }
150
- },
151
- required: ['document_id']
152
- }
153
- },
154
- {
155
- name: 'clear_documents',
156
- description: 'Clear all documents from LightRAG',
157
- inputSchema: {
158
- type: 'object',
159
- properties: {}
160
- }
161
- },
162
- {
163
- name: 'document_status',
164
- description: 'Get processing status for documents',
165
- inputSchema: {
166
- type: 'object',
167
- properties: {
168
- document_id: { type: 'string', description: 'Specific document ID' }
169
- }
170
- }
171
- },
172
-
173
- // ===== QUERY TOOLS (3) =====
174
- {
175
- name: 'query_text',
176
- description: 'Query LightRAG with text using various retrieval modes',
177
- inputSchema: {
178
- type: 'object',
179
- properties: {
180
- query: { type: 'string', description: 'Query text' },
181
- mode: {
182
- type: 'string',
183
- enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
184
- default: 'hybrid',
185
- description: 'Query mode'
186
- },
187
- only_need_context: { type: 'boolean', description: 'Return only context' },
188
- top_k: { type: 'number', description: 'Number of results' }
189
- },
190
- required: ['query']
191
- }
192
- },
193
- {
194
- name: 'query_text_stream',
195
- description: 'Stream query results from LightRAG in real-time',
196
- inputSchema: {
197
- type: 'object',
198
- properties: {
199
- query: { type: 'string', description: 'Query text' },
200
- mode: {
201
- type: 'string',
202
- enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
203
- default: 'hybrid'
204
- }
205
- },
206
- required: ['query']
207
- }
208
- },
209
- {
210
- name: 'query_with_citation',
211
- description: 'Query LightRAG and get results with source citations',
212
- inputSchema: {
213
- type: 'object',
214
- properties: {
215
- query: { type: 'string', description: 'Query text' },
216
- mode: {
217
- type: 'string',
218
- enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
219
- default: 'hybrid'
220
- }
221
- },
222
- required: ['query']
223
- }
224
- },
225
-
226
- // ===== KNOWLEDGE GRAPH TOOLS (10) =====
227
- {
228
- name: 'get_knowledge_graph',
229
- description: 'Retrieve the complete knowledge graph',
230
- inputSchema: {
231
- type: 'object',
232
- properties: {}
233
- }
234
- },
235
- {
236
- name: 'get_graph_structure',
237
- description: 'Get knowledge graph structure and statistics',
238
- inputSchema: {
239
- type: 'object',
240
- properties: {}
241
- }
242
- },
243
- {
244
- name: 'get_entities',
245
- description: 'Retrieve all entities from the knowledge graph',
246
- inputSchema: {
247
- type: 'object',
248
- properties: {
249
- limit: { type: 'number', description: 'Max entities to retrieve' }
250
- }
251
- }
252
- },
253
- {
254
- name: 'get_relations',
255
- description: 'Retrieve all relationships from the knowledge graph',
256
- inputSchema: {
257
- type: 'object',
258
- properties: {
259
- limit: { type: 'number', description: 'Max relations to retrieve' }
260
- }
261
- }
262
- },
263
- {
264
- name: 'check_entity_exists',
265
- description: 'Check if an entity exists in the knowledge graph',
266
- inputSchema: {
267
- type: 'object',
268
- properties: {
269
- entity_name: { type: 'string', description: 'Name of the entity' }
270
- },
271
- required: ['entity_name']
272
- }
273
- },
274
- {
275
- name: 'update_entity',
276
- description: 'Update properties of an entity',
277
- inputSchema: {
278
- type: 'object',
279
- properties: {
280
- entity_id: { type: 'string', description: 'Entity ID' },
281
- properties: { type: 'object', description: 'Properties to update' }
282
- },
283
- required: ['entity_id', 'properties']
284
- }
285
- },
286
- {
287
- name: 'delete_entity',
288
- description: 'Delete an entity from the knowledge graph',
289
- inputSchema: {
290
- type: 'object',
291
- properties: {
292
- entity_id: { type: 'string', description: 'Entity ID' }
293
- },
294
- required: ['entity_id']
295
- }
296
- },
297
- {
298
- name: 'delete_relation',
299
- description: 'Delete a relationship from the knowledge graph',
300
- inputSchema: {
301
- type: 'object',
302
- properties: {
303
- relation_id: { type: 'string', description: 'Relation ID' }
304
- },
305
- required: ['relation_id']
306
- }
307
- },
308
- {
309
- name: 'get_graph_labels',
310
- description: 'Get labels from the knowledge graph',
311
- inputSchema: {
312
- type: 'object',
313
- properties: {}
314
- }
315
- },
316
- {
317
- name: 'update_relation',
318
- description: 'Update properties of a relationship in the knowledge graph',
319
- inputSchema: {
320
- type: 'object',
321
- properties: {
322
- relation_id: { type: 'string', description: 'Relation ID' },
323
- properties: { type: 'object', description: 'Properties to update' }
324
- },
325
- required: ['relation_id', 'properties']
326
- }
327
- },
328
-
329
- // ===== SYSTEM MANAGEMENT TOOLS (8) =====
330
- {
331
- name: 'get_pipeline_status',
332
- description: 'Get the processing pipeline status from LightRAG',
333
- inputSchema: {
334
- type: 'object',
335
- properties: {}
336
- }
337
- },
338
- {
339
- name: 'get_track_status',
340
- description: 'Get track status by ID',
341
- inputSchema: {
342
- type: 'object',
343
- properties: {
344
- track_id: { type: 'string', description: 'ID of the track' }
345
- },
346
- required: ['track_id']
347
- }
348
- },
349
- {
350
- name: 'get_document_status_counts',
351
- description: 'Get document status counts',
352
- inputSchema: {
353
- type: 'object',
354
- properties: {}
355
- }
356
- },
357
- {
358
- name: 'get_health',
359
- description: 'Check LightRAG server health status',
360
- inputSchema: {
361
- type: 'object',
362
- properties: {}
363
- }
364
- },
365
- {
366
- name: 'get_status',
367
- description: 'Get detailed system status and statistics',
368
- inputSchema: {
369
- type: 'object',
370
- properties: {}
371
- }
372
- },
373
- {
374
- name: 'clear_cache',
375
- description: 'Clear LightRAG internal cache',
376
- inputSchema: {
377
- type: 'object',
378
- properties: {
379
- cache_type: { type: 'string', description: 'Type of cache to clear' }
380
- }
381
- }
382
- },
383
- {
384
- name: 'get_config',
385
- description: 'Get current LightRAG server configuration',
386
- inputSchema: {
387
- type: 'object',
388
- properties: {}
389
- }
390
- },
391
- {
392
- name: 'get_workspace_info',
393
- description: 'Get information about the current workspace',
394
- inputSchema: {
395
- type: 'object',
396
- properties: {}
397
- }
398
- }
399
- ];
400
-
401
- // List tools handler
402
- server.setRequestHandler(ListToolsRequestSchema, async () => {
403
- return { tools };
404
- });
405
-
406
- // Call tool handler with all 30+ implementations
407
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
408
- const { name, arguments: args } = request.params;
409
-
410
- try {
411
- let response;
412
-
413
- switch (name) {
414
- // DOCUMENT MANAGEMENT
415
- case 'insert_text':
416
- response = await httpClient.post('/documents/text', {
417
- text: args.text,
418
- description: args.description
419
- });
420
- break;
421
-
422
- case 'insert_texts':
423
- response = await httpClient.post('/documents/texts', {
424
- texts: args.texts
425
- });
426
- break;
427
-
428
- case 'upload_document':
429
- response = await httpClient.post('/documents/upload', {
430
- file_path: args.file_path,
431
- chunk_size: args.chunk_size,
432
- chunk_overlap: args.chunk_overlap
433
- });
434
- break;
435
-
436
- case 'upload_documents':
437
- response = await httpClient.post('/documents/upload/batch', {
438
- file_paths: args.file_paths
439
- });
440
- break;
441
-
442
- case 'scan_documents':
443
- response = await httpClient.post('/documents/scan');
444
- break;
445
-
446
- case 'get_documents':
447
- response = await httpClient.get('/documents');
448
- break;
449
-
450
- case 'get_documents_paginated':
451
- response = await httpClient.get('/documents/paginated', {
452
- params: { page: args.page, page_size: args.page_size }
453
- });
454
- break;
455
-
456
- case 'delete_document':
457
- response = await httpClient.delete(`/documents/${args.document_id}`);
458
- break;
459
-
460
- case 'clear_documents':
461
- response = await httpClient.delete('/documents');
462
- break;
463
-
464
- case 'document_status':
465
- if (args.document_id) {
466
- response = await httpClient.get(`/documents/${args.document_id}/status`);
467
- } else {
468
- response = await httpClient.get('/documents/status');
469
- }
470
- break;
471
-
472
- // QUERY OPERATIONS
473
- case 'query_text':
474
- response = await httpClient.post('/query', {
475
- query: args.query,
476
- mode: args.mode || 'hybrid',
477
- only_need_context: args.only_need_context || false,
478
- top_k: args.top_k || 60
479
- });
480
- break;
481
-
482
- case 'query_text_stream':
483
- response = await httpClient.post('/query', {
484
- query: args.query,
485
- mode: args.mode || 'hybrid',
486
- stream: true
487
- });
488
- break;
489
-
490
- case 'query_with_citation':
491
- response = await httpClient.post('/query', {
492
- query: args.query,
493
- mode: args.mode || 'hybrid',
494
- with_citation: true
495
- });
496
- break;
497
-
498
- // KNOWLEDGE GRAPH
499
- case 'get_knowledge_graph':
500
- response = await httpClient.get('/graph');
501
- break;
502
-
503
- case 'get_graph_structure':
504
- response = await httpClient.get('/graph/structure');
505
- break;
506
-
507
- case 'get_entities':
508
- response = await httpClient.get('/graph/entities', {
509
- params: args.limit ? { limit: args.limit } : {}
510
- });
511
- break;
512
-
513
- case 'get_relations':
514
- response = await httpClient.get('/graph/relations', {
515
- params: args.limit ? { limit: args.limit } : {}
516
- });
517
- break;
518
-
519
- case 'check_entity_exists':
520
- response = await httpClient.get('/graph/entity/exists', {
521
- params: { name: args.entity_name }
522
- });
523
- break;
524
-
525
- case 'update_entity':
526
- response = await httpClient.put(`/graph/entity/${args.entity_id}`, {
527
- properties: args.properties
528
- });
529
- break;
530
-
531
- case 'delete_entity':
532
- response = await httpClient.delete(`/graph/entity/${args.entity_id}`);
533
- break;
534
-
535
- case 'delete_relation':
536
- response = await httpClient.delete(`/graph/relation/${args.relation_id}`);
537
- break;
538
-
539
- case 'get_graph_labels':
540
- response = await httpClient.get('/graph/labels');
541
- break;
542
-
543
- case 'update_relation':
544
- response = await httpClient.put(`/graph/relation/${args.relation_id}`, {
545
- properties: args.properties
546
- });
547
- break;
548
-
549
- // SYSTEM MANAGEMENT
550
- case 'get_pipeline_status':
551
- response = await httpClient.get('/pipeline/status');
552
- break;
553
-
554
- case 'get_track_status':
555
- response = await httpClient.get(`/track/${args.track_id}/status`);
556
- break;
557
-
558
- case 'get_document_status_counts':
559
- response = await httpClient.get('/documents/status/counts');
560
- break;
561
-
562
- case 'get_health':
563
- response = await httpClient.get('/health');
564
- break;
565
-
566
- case 'get_status':
567
- response = await httpClient.get('/status');
568
- break;
569
-
570
- case 'clear_cache':
571
- response = await httpClient.post('/cache/clear', {
572
- cache_type: args.cache_type || 'all'
573
- });
574
- break;
575
-
576
- case 'get_config':
577
- response = await httpClient.get('/config');
578
- break;
579
-
580
- case 'get_workspace_info':
581
- response = await httpClient.get('/workspace/info');
582
- break;
583
-
584
- default:
585
- throw new Error(`Unknown tool: ${name}`);
586
- }
587
-
588
- return {
589
- content: [
590
- {
591
- type: 'text',
592
- text: JSON.stringify(response.data, null, 2)
593
- }
594
- ]
595
- };
596
- } catch (error) {
597
- return {
598
- content: [
599
- {
600
- type: 'text',
601
- text: `Error: ${error.message}\n${error.response?.data ? `\nServer error: ${JSON.stringify(error.response.data, null, 2)}` : ''}`
602
- }
603
- ],
604
- isError: true
605
- };
606
- }
607
- });
608
-
609
- // Start server
610
- async function main() {
611
- const transport = new StdioServerTransport();
612
- await server.connect(transport);
613
- console.error('╔════════════════════════════════════════════════════════╗');
614
- console.error('║ LightRAG MCP Server v1.0.6 - Started Successfully ║');
615
- console.error('╚════════════════════════════════════════════════════════╝');
616
- console.error(`Server: ${LIGHTRAG_SERVER_URL}`);
617
- console.error(`Workspace: ${LIGHTRAG_WORKSPACE}`);
618
- console.error(`Tools: 31 tools available (Most Complete!)`);
619
- console.error('Ready for connections...\n');
620
- }
621
-
622
- main().catch((error) => {
623
- console.error('Fatal error:', error);
624
- process.exit(1);
625
- });
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * LightRAG MCP Server - Complete Node.js Implementation
5
+ *
6
+ * Model Context Protocol server for LightRAG with 28 tools
7
+ *
8
+ * Author: Lalit Suryan
9
+ * License: MIT
10
+ */
11
+
12
+ const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
13
+ const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
14
+ const {
15
+ CallToolRequestSchema,
16
+ ListToolsRequestSchema,
17
+ } = require('@modelcontextprotocol/sdk/types.js');
18
+ const axios = require('axios');
19
+
20
+ // Environment configuration
21
+ const LIGHTRAG_SERVER_URL = process.env.LIGHTRAG_SERVER_URL || 'http://localhost:9621';
22
+ const LIGHTRAG_API_KEY = process.env.LIGHTRAG_API_KEY || '';
23
+ const LIGHTRAG_WORKSPACE = process.env.LIGHTRAG_WORKSPACE || 'default';
24
+
25
+ // Create HTTP client
26
+ const httpClient = axios.create({
27
+ baseURL: LIGHTRAG_SERVER_URL,
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ // Use X-API-Key header as per OpenAPI spec
31
+ ...(LIGHTRAG_API_KEY && { 'X-API-Key': LIGHTRAG_API_KEY }),
32
+ },
33
+ timeout: 30000
34
+ });
35
+
36
+ // Create MCP server
37
+ const server = new Server(
38
+ {
39
+ name: '@g99/lightrag-mcp-server',
40
+ version: '1.0.9',
41
+ },
42
+ {
43
+ capabilities: {
44
+ tools: {},
45
+ },
46
+ }
47
+ );
48
+
49
+ // All 28 Tool definitions (10 Document + 3 Query + 10 Knowledge Graph + 5 System)
50
+ const tools = [
51
+ // ===== DOCUMENT MANAGEMENT TOOLS (10) =====
52
+ {
53
+ name: 'insert_text',
54
+ description: 'Insert a single text document into LightRAG',
55
+ inputSchema: {
56
+ type: 'object',
57
+ properties: {
58
+ text: { type: 'string', description: 'Text content to insert' },
59
+ description: { type: 'string', description: 'Description of the text' }
60
+ },
61
+ required: ['text']
62
+ }
63
+ },
64
+ {
65
+ name: 'insert_texts',
66
+ description: 'Insert multiple text documents into LightRAG in batch',
67
+ inputSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ texts: {
71
+ type: 'array',
72
+ description: 'Array of text documents',
73
+ items: {
74
+ type: 'object',
75
+ properties: {
76
+ content: { type: 'string' },
77
+ title: { type: 'string' },
78
+ metadata: { type: 'object' }
79
+ },
80
+ required: ['content']
81
+ }
82
+ }
83
+ },
84
+ required: ['texts']
85
+ }
86
+ },
87
+ {
88
+ name: 'upload_document',
89
+ description: 'Upload a document file to LightRAG',
90
+ inputSchema: {
91
+ type: 'object',
92
+ properties: {
93
+ file_path: { type: 'string', description: 'Path to the file' },
94
+ chunk_size: { type: 'number', description: 'Custom chunk size' },
95
+ chunk_overlap: { type: 'number', description: 'Overlap between chunks' }
96
+ },
97
+ required: ['file_path']
98
+ }
99
+ },
100
+ {
101
+ name: 'upload_documents',
102
+ description: 'Upload multiple documents in batch',
103
+ inputSchema: {
104
+ type: 'object',
105
+ properties: {
106
+ file_paths: {
107
+ type: 'array',
108
+ items: { type: 'string' },
109
+ description: 'Array of file paths'
110
+ }
111
+ },
112
+ required: ['file_paths']
113
+ }
114
+ },
115
+ {
116
+ name: 'scan_documents',
117
+ description: 'Scan for new documents in the configured directory',
118
+ inputSchema: {
119
+ type: 'object',
120
+ properties: {}
121
+ }
122
+ },
123
+ {
124
+ name: 'get_documents',
125
+ description: 'Retrieve all documents from LightRAG',
126
+ inputSchema: {
127
+ type: 'object',
128
+ properties: {}
129
+ }
130
+ },
131
+ {
132
+ name: 'get_documents_paginated',
133
+ description: 'Retrieve documents with pagination',
134
+ inputSchema: {
135
+ type: 'object',
136
+ properties: {
137
+ page: { type: 'number', description: 'Page number (1-based)' },
138
+ page_size: { type: 'number', description: 'Items per page (1-100)' }
139
+ },
140
+ required: ['page', 'page_size']
141
+ }
142
+ },
143
+ {
144
+ name: 'delete_document',
145
+ description: 'Delete a specific document by ID',
146
+ inputSchema: {
147
+ type: 'object',
148
+ properties: {
149
+ document_id: { type: 'string', description: 'ID of document to delete' }
150
+ },
151
+ required: ['document_id']
152
+ }
153
+ },
154
+ {
155
+ name: 'clear_documents',
156
+ description: 'Clear all documents from LightRAG',
157
+ inputSchema: {
158
+ type: 'object',
159
+ properties: {}
160
+ }
161
+ },
162
+ {
163
+ name: 'document_status',
164
+ description: 'Get processing status for documents',
165
+ inputSchema: {
166
+ type: 'object',
167
+ properties: {
168
+ document_id: { type: 'string', description: 'Specific document ID' }
169
+ }
170
+ }
171
+ },
172
+
173
+ // ===== QUERY TOOLS (3) =====
174
+ {
175
+ name: 'query_text',
176
+ description: 'Query LightRAG with text using various retrieval modes',
177
+ inputSchema: {
178
+ type: 'object',
179
+ properties: {
180
+ query: { type: 'string', description: 'Query text' },
181
+ mode: {
182
+ type: 'string',
183
+ enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
184
+ default: 'hybrid',
185
+ description: 'Query mode'
186
+ },
187
+ only_need_context: { type: 'boolean', description: 'Return only context' },
188
+ top_k: { type: 'number', description: 'Number of results' }
189
+ },
190
+ required: ['query']
191
+ }
192
+ },
193
+ {
194
+ name: 'query_text_stream',
195
+ description: 'Stream query results from LightRAG in real-time',
196
+ inputSchema: {
197
+ type: 'object',
198
+ properties: {
199
+ query: { type: 'string', description: 'Query text' },
200
+ mode: {
201
+ type: 'string',
202
+ enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
203
+ default: 'hybrid'
204
+ }
205
+ },
206
+ required: ['query']
207
+ }
208
+ },
209
+ {
210
+ name: 'query_with_citation',
211
+ description: 'Query LightRAG and get results with source citations',
212
+ inputSchema: {
213
+ type: 'object',
214
+ properties: {
215
+ query: { type: 'string', description: 'Query text' },
216
+ mode: {
217
+ type: 'string',
218
+ enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
219
+ default: 'hybrid'
220
+ }
221
+ },
222
+ required: ['query']
223
+ }
224
+ },
225
+
226
+ // ===== KNOWLEDGE GRAPH TOOLS (10) =====
227
+ {
228
+ name: 'get_knowledge_graph',
229
+ description: 'Retrieve the complete knowledge graph',
230
+ inputSchema: {
231
+ type: 'object',
232
+ properties: {}
233
+ }
234
+ },
235
+ {
236
+ name: 'get_graph_structure',
237
+ description: 'Get knowledge graph structure and statistics',
238
+ inputSchema: {
239
+ type: 'object',
240
+ properties: {}
241
+ }
242
+ },
243
+ {
244
+ name: 'get_entities',
245
+ description: 'Retrieve all entities from the knowledge graph',
246
+ inputSchema: {
247
+ type: 'object',
248
+ properties: {
249
+ limit: { type: 'number', description: 'Max entities to retrieve' }
250
+ }
251
+ }
252
+ },
253
+ {
254
+ name: 'get_relations',
255
+ description: 'Retrieve all relationships from the knowledge graph',
256
+ inputSchema: {
257
+ type: 'object',
258
+ properties: {
259
+ limit: { type: 'number', description: 'Max relations to retrieve' }
260
+ }
261
+ }
262
+ },
263
+ {
264
+ name: 'check_entity_exists',
265
+ description: 'Check if an entity exists in the knowledge graph',
266
+ inputSchema: {
267
+ type: 'object',
268
+ properties: {
269
+ entity_name: { type: 'string', description: 'Name of the entity' }
270
+ },
271
+ required: ['entity_name']
272
+ }
273
+ },
274
+ {
275
+ name: 'update_entity',
276
+ description: 'Update properties of an entity',
277
+ inputSchema: {
278
+ type: 'object',
279
+ properties: {
280
+ entity_id: { type: 'string', description: 'Entity ID' },
281
+ properties: { type: 'object', description: 'Properties to update' }
282
+ },
283
+ required: ['entity_id', 'properties']
284
+ }
285
+ },
286
+ {
287
+ name: 'delete_entity',
288
+ description: 'Delete an entity from the knowledge graph',
289
+ inputSchema: {
290
+ type: 'object',
291
+ properties: {
292
+ entity_id: { type: 'string', description: 'Entity ID' }
293
+ },
294
+ required: ['entity_id']
295
+ }
296
+ },
297
+ {
298
+ name: 'delete_relation',
299
+ description: 'Delete a relationship from the knowledge graph',
300
+ inputSchema: {
301
+ type: 'object',
302
+ properties: {
303
+ source_entity: { type: 'string', description: 'Source entity name' },
304
+ target_entity: { type: 'string', description: 'Target entity name' }
305
+ },
306
+ required: ['source_entity', 'target_entity']
307
+ }
308
+ },
309
+ {
310
+ name: 'get_graph_labels',
311
+ description: 'Get labels from the knowledge graph',
312
+ inputSchema: {
313
+ type: 'object',
314
+ properties: {}
315
+ }
316
+ },
317
+ {
318
+ name: 'update_relation',
319
+ description: 'Update properties of a relationship in the knowledge graph',
320
+ inputSchema: {
321
+ type: 'object',
322
+ properties: {
323
+ source_id: { type: 'string', description: 'Source entity name' },
324
+ target_id: { type: 'string', description: 'Target entity name' },
325
+ properties: { type: 'object', description: 'Properties to update' }
326
+ },
327
+ required: ['source_id', 'target_id', 'properties']
328
+ }
329
+ },
330
+
331
+ // ===== SYSTEM MANAGEMENT TOOLS (5) =====
332
+ {
333
+ name: 'get_pipeline_status',
334
+ description: 'Get the processing pipeline status from LightRAG',
335
+ inputSchema: {
336
+ type: 'object',
337
+ properties: {}
338
+ }
339
+ },
340
+ {
341
+ name: 'get_track_status',
342
+ description: 'Get track status by ID',
343
+ inputSchema: {
344
+ type: 'object',
345
+ properties: {
346
+ track_id: { type: 'string', description: 'ID of the track' }
347
+ },
348
+ required: ['track_id']
349
+ }
350
+ },
351
+ {
352
+ name: 'get_document_status_counts',
353
+ description: 'Get document status counts',
354
+ inputSchema: {
355
+ type: 'object',
356
+ properties: {}
357
+ }
358
+ },
359
+ {
360
+ name: 'get_health',
361
+ description: 'Check LightRAG server health status',
362
+ inputSchema: {
363
+ type: 'object',
364
+ properties: {}
365
+ }
366
+ },
367
+ {
368
+ name: 'clear_cache',
369
+ description: 'Clear LightRAG internal cache',
370
+ inputSchema: {
371
+ type: 'object',
372
+ properties: {
373
+ cache_type: { type: 'string', description: 'Type of cache to clear' }
374
+ }
375
+ }
376
+ }
377
+ ];
378
+
379
+ // List tools handler
380
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
381
+ return { tools };
382
+ });
383
+
384
+ // Call tool handler with all 30+ implementations
385
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
386
+ const { name, arguments: args } = request.params;
387
+
388
+ try {
389
+ let response;
390
+
391
+ switch (name) {
392
+ // DOCUMENT MANAGEMENT
393
+ case 'insert_text':
394
+ response = await httpClient.post('/documents/text', {
395
+ text: args.text,
396
+ description: args.description
397
+ });
398
+ break;
399
+
400
+ case 'insert_texts':
401
+ response = await httpClient.post('/documents/texts', {
402
+ texts: args.texts
403
+ });
404
+ break;
405
+
406
+ case 'upload_document':
407
+ response = await httpClient.post('/documents/upload', {
408
+ file_path: args.file_path,
409
+ chunk_size: args.chunk_size,
410
+ chunk_overlap: args.chunk_overlap
411
+ });
412
+ break;
413
+
414
+ case 'upload_documents':
415
+ response = await httpClient.post('/documents/upload/batch', {
416
+ file_paths: args.file_paths
417
+ });
418
+ break;
419
+
420
+ case 'scan_documents':
421
+ response = await httpClient.post('/documents/scan');
422
+ break;
423
+
424
+ case 'get_documents':
425
+ response = await httpClient.get('/documents');
426
+ break;
427
+
428
+ case 'get_documents_paginated':
429
+ response = await httpClient.get('/documents/paginated', {
430
+ params: { page: args.page, page_size: args.page_size }
431
+ });
432
+ break;
433
+
434
+ case 'delete_document':
435
+ response = await httpClient.delete(`/documents/${args.document_id}`);
436
+ break;
437
+
438
+ case 'clear_documents':
439
+ response = await httpClient.delete('/documents');
440
+ break;
441
+
442
+ case 'document_status':
443
+ if (args.document_id) {
444
+ response = await httpClient.get(`/documents/${args.document_id}/status`);
445
+ } else {
446
+ response = await httpClient.get('/documents/status');
447
+ }
448
+ break;
449
+
450
+ // QUERY OPERATIONS
451
+ case 'query_text':
452
+ response = await httpClient.post('/query', {
453
+ query: args.query,
454
+ mode: args.mode || 'hybrid',
455
+ only_need_context: args.only_need_context || false,
456
+ top_k: args.top_k || 60
457
+ });
458
+ break;
459
+
460
+ case 'query_text_stream':
461
+ response = await httpClient.post('/query', {
462
+ query: args.query,
463
+ mode: args.mode || 'hybrid',
464
+ stream: true
465
+ });
466
+ break;
467
+
468
+ case 'query_with_citation':
469
+ response = await httpClient.post('/query', {
470
+ query: args.query,
471
+ mode: args.mode || 'hybrid',
472
+ with_citation: true
473
+ });
474
+ break;
475
+
476
+ // KNOWLEDGE GRAPH
477
+ case 'get_knowledge_graph':
478
+ response = await httpClient.get('/graph');
479
+ break;
480
+
481
+ case 'get_graph_structure':
482
+ response = await httpClient.get('/graph/structure');
483
+ break;
484
+
485
+ case 'get_entities':
486
+ response = await httpClient.get('/graph/entities', {
487
+ params: args.limit ? { limit: args.limit } : {}
488
+ });
489
+ break;
490
+
491
+ case 'get_relations':
492
+ response = await httpClient.get('/graph/relations', {
493
+ params: args.limit ? { limit: args.limit } : {}
494
+ });
495
+ break;
496
+
497
+ case 'check_entity_exists':
498
+ response = await httpClient.get('/graph/entity/exists', {
499
+ params: { name: args.entity_name }
500
+ });
501
+ break;
502
+
503
+ case 'update_entity':
504
+ response = await httpClient.put(`/graph/entity/${args.entity_id}`, {
505
+ properties: args.properties
506
+ });
507
+ break;
508
+
509
+ case 'delete_entity':
510
+ response = await httpClient.delete(`/graph/entity/${args.entity_id}`);
511
+ break;
512
+
513
+ case 'delete_relation':
514
+ response = await httpClient.delete('/documents/delete_relation', {
515
+ data: {
516
+ source_entity: args.source_entity,
517
+ target_entity: args.target_entity
518
+ }
519
+ });
520
+ break;
521
+
522
+ case 'get_graph_labels':
523
+ response = await httpClient.get('/graph/label/list');
524
+ break;
525
+
526
+ case 'update_relation':
527
+ response = await httpClient.post('/graph/relation/edit', {
528
+ source_id: args.source_id,
529
+ target_id: args.target_id,
530
+ updated_data: args.properties
531
+ });
532
+ break;
533
+
534
+ // SYSTEM MANAGEMENT
535
+ case 'get_pipeline_status':
536
+ response = await httpClient.get('/pipeline/status');
537
+ break;
538
+
539
+ case 'get_track_status':
540
+ response = await httpClient.get(`/track/${args.track_id}/status`);
541
+ break;
542
+
543
+ case 'get_document_status_counts':
544
+ response = await httpClient.get('/documents/status/counts');
545
+ break;
546
+
547
+ case 'get_health':
548
+ response = await httpClient.get('/health');
549
+ break;
550
+
551
+ case 'clear_cache':
552
+ response = await httpClient.post('/cache/clear', {
553
+ cache_type: args.cache_type || 'all'
554
+ });
555
+ break;
556
+
557
+ default:
558
+ throw new Error(`Unknown tool: ${name}`);
559
+ }
560
+
561
+ return {
562
+ content: [
563
+ {
564
+ type: 'text',
565
+ text: JSON.stringify(response.data, null, 2)
566
+ }
567
+ ]
568
+ };
569
+ } catch (error) {
570
+ return {
571
+ content: [
572
+ {
573
+ type: 'text',
574
+ text: `Error: ${error.message}\n${error.response?.data ? `\nServer error: ${JSON.stringify(error.response.data, null, 2)}` : ''}`
575
+ }
576
+ ],
577
+ isError: true
578
+ };
579
+ }
580
+ });
581
+
582
+ // Start server
583
+ async function main() {
584
+ const transport = new StdioServerTransport();
585
+ await server.connect(transport);
586
+ console.error('╔══════════════════════════â•═══â•═â•══â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•—');
587
+ console.error('║ LightRAG MCP Server v1.0.9 - Started Successfully ║');
588
+ console.error('╚════â•═â•═â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•╝');
589
+ console.error(`Server: ${LIGHTRAG_SERVER_URL}`);
590
+ console.error(`Workspace: ${LIGHTRAG_WORKSPACE}`);
591
+ console.error(`Tools: 26 tools available`);
592
+ console.error('Ready for connections...\n');
593
+ }
594
+
595
+ main().catch((error) => {
596
+ console.error('Fatal error:', error);
597
+ process.exit(1);
598
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g99/lightrag-mcp-server",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Model Context Protocol (MCP) server for LightRAG - Complete RAG and Knowledge Graph integration with 30+ tools",
5
5
  "keywords": [
6
6
  "mcp",