@g99/lightrag-mcp-server 1.0.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/LICENSE +21 -0
- package/README.md +720 -0
- package/package.json +45 -0
- package/wrapper.js +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Lalit Suryan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
# LightRAG MCP Server
|
|
2
|
+
|
|
3
|
+
A comprehensive Model Context Protocol (MCP) server for LightRAG - Simple and Fast Retrieval-Augmented Generation. This server enables AI assistants to interact with LightRAG's powerful knowledge graph and RAG capabilities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
LightRAG MCP Server provides complete integration with LightRAG's API, offering 30+ tools for document management, knowledge graph operations, querying, and system management. Build sophisticated RAG applications with knowledge graph capabilities through a simple MCP interface.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Complete LightRAG API Coverage**: Access all major LightRAG endpoints
|
|
12
|
+
- **30+ Tools**: Comprehensive toolset for RAG operations
|
|
13
|
+
- **Knowledge Graph Operations**: Full control over entities and relationships
|
|
14
|
+
- **Multiple Query Modes**: Support for naive, local, global, hybrid, and mix modes
|
|
15
|
+
- **Document Management**: Insert, upload, scan, and manage documents
|
|
16
|
+
- **Streaming Support**: Real-time streaming responses for queries
|
|
17
|
+
- **Easy Installation**: Install via uvx or npx
|
|
18
|
+
- **Dual Language Support**: Both Python and TypeScript implementations
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### Using uvx (Python - Recommended)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uvx lightrag-mcp-server
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Using npx (Node.js)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @g99/lightrag-mcp-server
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Using pip (Global Installation)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install lightrag-mcp-server
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Using npm (Global Installation)
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g @g99/lightrag-mcp-server
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
You need a running LightRAG server instance. Install and start LightRAG:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Install LightRAG
|
|
52
|
+
pip install "lightrag-hku[api]"
|
|
53
|
+
|
|
54
|
+
# Create .env file with your LLM and embedding configurations
|
|
55
|
+
cp env.example .env
|
|
56
|
+
|
|
57
|
+
# Start LightRAG server (default: http://localhost:9621)
|
|
58
|
+
lightrag-server
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For detailed LightRAG server setup, visit [LightRAG GitHub](https://github.com/HKUDS/LightRAG).
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
### Environment Variables
|
|
66
|
+
|
|
67
|
+
Create a `.env` file or set the following environment variables:
|
|
68
|
+
|
|
69
|
+
```env
|
|
70
|
+
# Required: Your LightRAG server URL
|
|
71
|
+
LIGHTRAG_SERVER_URL=http://localhost:9621
|
|
72
|
+
|
|
73
|
+
# Optional: Authentication token if your LightRAG server requires it
|
|
74
|
+
LIGHTRAG_API_KEY=your_api_key_here
|
|
75
|
+
|
|
76
|
+
# Optional: Custom workspace name for data isolation
|
|
77
|
+
LIGHTRAG_WORKSPACE=default
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Getting Your API Key
|
|
81
|
+
|
|
82
|
+
If your LightRAG server has authentication enabled:
|
|
83
|
+
|
|
84
|
+
1. Check your LightRAG server's `.env` file for `LIGHTRAG_API_KEY`
|
|
85
|
+
2. Alternatively, check the startup logs for the API key
|
|
86
|
+
3. Use that key in your MCP configuration
|
|
87
|
+
|
|
88
|
+
## MCP Client Configuration
|
|
89
|
+
|
|
90
|
+
### Claude Desktop
|
|
91
|
+
|
|
92
|
+
Add to your `claude_desktop_config.json`:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"lightrag": {
|
|
98
|
+
"command": "uvx",
|
|
99
|
+
"args": ["lightrag-mcp-server"],
|
|
100
|
+
"env": {
|
|
101
|
+
"LIGHTRAG_SERVER_URL": "http://localhost:9621",
|
|
102
|
+
"LIGHTRAG_API_KEY": "your_api_key_here"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Cline (VS Code Extension)
|
|
110
|
+
|
|
111
|
+
Add to your MCP settings:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"lightrag": {
|
|
117
|
+
"command": "uvx",
|
|
118
|
+
"args": ["lightrag-mcp-server"],
|
|
119
|
+
"env": {
|
|
120
|
+
"LIGHTRAG_SERVER_URL": "http://localhost:9621",
|
|
121
|
+
"LIGHTRAG_API_KEY": "your_api_key_here"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Available Tools
|
|
129
|
+
|
|
130
|
+
### Document Management Tools (10 tools)
|
|
131
|
+
|
|
132
|
+
#### insert_text
|
|
133
|
+
Insert a single text document into LightRAG.
|
|
134
|
+
|
|
135
|
+
**Parameters:**
|
|
136
|
+
- `text` (required): Text content to insert
|
|
137
|
+
- `description` (optional): Description of the text
|
|
138
|
+
|
|
139
|
+
**Example:**
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"text": "LightRAG is a powerful retrieval-augmented generation system that uses knowledge graphs.",
|
|
143
|
+
"description": "Introduction to LightRAG"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### insert_texts
|
|
148
|
+
Insert multiple text documents into LightRAG in batch.
|
|
149
|
+
|
|
150
|
+
**Parameters:**
|
|
151
|
+
- `texts` (required): Array of text documents with optional metadata
|
|
152
|
+
|
|
153
|
+
**Example:**
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"texts": [
|
|
157
|
+
{
|
|
158
|
+
"content": "LightRAG uses knowledge graphs for enhanced retrieval.",
|
|
159
|
+
"title": "LightRAG Overview",
|
|
160
|
+
"metadata": {"category": "documentation"}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"content": "Knowledge graphs connect entities and relationships.",
|
|
164
|
+
"title": "Knowledge Graphs"
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### upload_document
|
|
171
|
+
Upload a document file to LightRAG.
|
|
172
|
+
|
|
173
|
+
**Parameters:**
|
|
174
|
+
- `file_path` (required): Path to the file to upload
|
|
175
|
+
- `chunk_size` (optional): Custom chunk size for document splitting
|
|
176
|
+
- `chunk_overlap` (optional): Overlap size between chunks
|
|
177
|
+
|
|
178
|
+
**Example:**
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"file_path": "/path/to/document.pdf",
|
|
182
|
+
"chunk_size": 1200,
|
|
183
|
+
"chunk_overlap": 100
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### upload_documents
|
|
188
|
+
Upload multiple documents in batch.
|
|
189
|
+
|
|
190
|
+
**Parameters:**
|
|
191
|
+
- `file_paths` (required): Array of file paths to upload
|
|
192
|
+
|
|
193
|
+
**Example:**
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"file_paths": [
|
|
197
|
+
"/path/to/doc1.pdf",
|
|
198
|
+
"/path/to/doc2.txt",
|
|
199
|
+
"/path/to/doc3.docx"
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### scan_documents
|
|
205
|
+
Scan for new documents in the configured input directory.
|
|
206
|
+
|
|
207
|
+
**Parameters:** None
|
|
208
|
+
|
|
209
|
+
**Example:**
|
|
210
|
+
```json
|
|
211
|
+
{}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### get_documents
|
|
215
|
+
Retrieve all documents from LightRAG.
|
|
216
|
+
|
|
217
|
+
**Parameters:** None
|
|
218
|
+
|
|
219
|
+
**Example:**
|
|
220
|
+
```json
|
|
221
|
+
{}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### get_documents_paginated
|
|
225
|
+
Retrieve documents with pagination support.
|
|
226
|
+
|
|
227
|
+
**Parameters:**
|
|
228
|
+
- `page` (required): Page number (1-based)
|
|
229
|
+
- `page_size` (required): Number of documents per page (1-100)
|
|
230
|
+
|
|
231
|
+
**Example:**
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"page": 1,
|
|
235
|
+
"page_size": 20
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### delete_document
|
|
240
|
+
Delete a specific document by ID.
|
|
241
|
+
|
|
242
|
+
**Parameters:**
|
|
243
|
+
- `document_id` (required): ID of the document to delete
|
|
244
|
+
|
|
245
|
+
**Example:**
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"document_id": "doc_12345"
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### clear_documents
|
|
253
|
+
Clear all documents from LightRAG.
|
|
254
|
+
|
|
255
|
+
**Parameters:** None
|
|
256
|
+
|
|
257
|
+
**Example:**
|
|
258
|
+
```json
|
|
259
|
+
{}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### document_status
|
|
263
|
+
Get processing status for documents.
|
|
264
|
+
|
|
265
|
+
**Parameters:**
|
|
266
|
+
- `document_id` (optional): Specific document ID to check
|
|
267
|
+
|
|
268
|
+
**Example:**
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"document_id": "doc_12345"
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Query Tools (3 tools)
|
|
276
|
+
|
|
277
|
+
#### query_text
|
|
278
|
+
Query LightRAG with text using various retrieval modes.
|
|
279
|
+
|
|
280
|
+
**Parameters:**
|
|
281
|
+
- `query` (required): Query text
|
|
282
|
+
- `mode` (optional): Query mode - "naive", "local", "global", "hybrid", or "mix" (default: "hybrid")
|
|
283
|
+
- `only_need_context` (optional): Return only context without generation (default: false)
|
|
284
|
+
- `top_k` (optional): Number of top results to retrieve (default: 60)
|
|
285
|
+
- `max_tokens` (optional): Maximum tokens in response
|
|
286
|
+
|
|
287
|
+
**Example:**
|
|
288
|
+
```json
|
|
289
|
+
{
|
|
290
|
+
"query": "What are the main concepts in machine learning?",
|
|
291
|
+
"mode": "hybrid",
|
|
292
|
+
"top_k": 20
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### query_text_stream
|
|
297
|
+
Stream query results from LightRAG in real-time.
|
|
298
|
+
|
|
299
|
+
**Parameters:**
|
|
300
|
+
- `query` (required): Query text
|
|
301
|
+
- `mode` (optional): Query mode (default: "hybrid")
|
|
302
|
+
- `only_need_context` (optional): Return only context (default: false)
|
|
303
|
+
|
|
304
|
+
**Example:**
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"query": "Explain the evolution of artificial intelligence",
|
|
308
|
+
"mode": "global"
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### query_with_citation
|
|
313
|
+
Query LightRAG and get results with source citations.
|
|
314
|
+
|
|
315
|
+
**Parameters:**
|
|
316
|
+
- `query` (required): Query text
|
|
317
|
+
- `mode` (optional): Query mode (default: "hybrid")
|
|
318
|
+
|
|
319
|
+
**Example:**
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"query": "What is retrieval-augmented generation?",
|
|
323
|
+
"mode": "hybrid"
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Knowledge Graph Tools (8 tools)
|
|
328
|
+
|
|
329
|
+
#### get_knowledge_graph
|
|
330
|
+
Retrieve the complete knowledge graph from LightRAG.
|
|
331
|
+
|
|
332
|
+
**Parameters:** None
|
|
333
|
+
|
|
334
|
+
**Example:**
|
|
335
|
+
```json
|
|
336
|
+
{}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### get_graph_structure
|
|
340
|
+
Get the structure and statistics of the knowledge graph.
|
|
341
|
+
|
|
342
|
+
**Parameters:** None
|
|
343
|
+
|
|
344
|
+
**Example:**
|
|
345
|
+
```json
|
|
346
|
+
{}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### get_entities
|
|
350
|
+
Retrieve all entities from the knowledge graph.
|
|
351
|
+
|
|
352
|
+
**Parameters:**
|
|
353
|
+
- `limit` (optional): Maximum number of entities to retrieve
|
|
354
|
+
|
|
355
|
+
**Example:**
|
|
356
|
+
```json
|
|
357
|
+
{
|
|
358
|
+
"limit": 100
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
#### get_relations
|
|
363
|
+
Retrieve all relationships from the knowledge graph.
|
|
364
|
+
|
|
365
|
+
**Parameters:**
|
|
366
|
+
- `limit` (optional): Maximum number of relations to retrieve
|
|
367
|
+
|
|
368
|
+
**Example:**
|
|
369
|
+
```json
|
|
370
|
+
{
|
|
371
|
+
"limit": 100
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### check_entity_exists
|
|
376
|
+
Check if an entity exists in the knowledge graph.
|
|
377
|
+
|
|
378
|
+
**Parameters:**
|
|
379
|
+
- `entity_name` (required): Name of the entity to check
|
|
380
|
+
|
|
381
|
+
**Example:**
|
|
382
|
+
```json
|
|
383
|
+
{
|
|
384
|
+
"entity_name": "Machine Learning"
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### update_entity
|
|
389
|
+
Update properties of an entity in the knowledge graph.
|
|
390
|
+
|
|
391
|
+
**Parameters:**
|
|
392
|
+
- `entity_id` (required): ID of the entity to update
|
|
393
|
+
- `properties` (required): Properties to update
|
|
394
|
+
|
|
395
|
+
**Example:**
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"entity_id": "entity_123",
|
|
399
|
+
"properties": {
|
|
400
|
+
"description": "Updated description",
|
|
401
|
+
"category": "AI Technology"
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
#### delete_entity
|
|
407
|
+
Delete an entity from the knowledge graph.
|
|
408
|
+
|
|
409
|
+
**Parameters:**
|
|
410
|
+
- `entity_id` (required): ID of the entity to delete
|
|
411
|
+
|
|
412
|
+
**Example:**
|
|
413
|
+
```json
|
|
414
|
+
{
|
|
415
|
+
"entity_id": "entity_789"
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
#### delete_relation
|
|
420
|
+
Delete a relationship from the knowledge graph.
|
|
421
|
+
|
|
422
|
+
**Parameters:**
|
|
423
|
+
- `relation_id` (required): ID of the relation to delete
|
|
424
|
+
|
|
425
|
+
**Example:**
|
|
426
|
+
```json
|
|
427
|
+
{
|
|
428
|
+
"relation_id": "rel_456"
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### System Management Tools (5 tools)
|
|
433
|
+
|
|
434
|
+
#### get_health
|
|
435
|
+
Check LightRAG server health and status.
|
|
436
|
+
|
|
437
|
+
**Parameters:** None
|
|
438
|
+
|
|
439
|
+
**Example:**
|
|
440
|
+
```json
|
|
441
|
+
{}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
#### get_status
|
|
445
|
+
Get detailed system status and statistics.
|
|
446
|
+
|
|
447
|
+
**Parameters:** None
|
|
448
|
+
|
|
449
|
+
**Example:**
|
|
450
|
+
```json
|
|
451
|
+
{}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
#### clear_cache
|
|
455
|
+
Clear LightRAG's internal cache.
|
|
456
|
+
|
|
457
|
+
**Parameters:**
|
|
458
|
+
- `cache_type` (optional): Type of cache to clear (default: "all")
|
|
459
|
+
|
|
460
|
+
**Example:**
|
|
461
|
+
```json
|
|
462
|
+
{
|
|
463
|
+
"cache_type": "llm"
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
#### get_config
|
|
468
|
+
Get current LightRAG server configuration.
|
|
469
|
+
|
|
470
|
+
**Parameters:** None
|
|
471
|
+
|
|
472
|
+
**Example:**
|
|
473
|
+
```json
|
|
474
|
+
{}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
#### get_workspace_info
|
|
478
|
+
Get information about the current workspace.
|
|
479
|
+
|
|
480
|
+
**Parameters:** None
|
|
481
|
+
|
|
482
|
+
**Example:**
|
|
483
|
+
```json
|
|
484
|
+
{}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
## Usage Examples
|
|
488
|
+
|
|
489
|
+
### Example 1: Index and Query Documents
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
// Insert documents
|
|
493
|
+
await use_mcp_tool("lightrag", "insert_texts", {
|
|
494
|
+
texts: [
|
|
495
|
+
{
|
|
496
|
+
content: "LightRAG is an advanced RAG system with knowledge graph capabilities.",
|
|
497
|
+
title: "LightRAG Introduction"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
content: "Knowledge graphs enhance retrieval by capturing entity relationships.",
|
|
501
|
+
title: "Knowledge Graphs"
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// Query the indexed content
|
|
507
|
+
await use_mcp_tool("lightrag", "query_text", {
|
|
508
|
+
query: "How does LightRAG use knowledge graphs?",
|
|
509
|
+
mode: "hybrid"
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Example 2: Upload and Process Documents
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
// Upload a PDF document
|
|
517
|
+
await use_mcp_tool("lightrag", "upload_document", {
|
|
518
|
+
file_path: "/path/to/research-paper.pdf"
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// Check document status
|
|
522
|
+
await use_mcp_tool("lightrag", "document_status", {
|
|
523
|
+
document_id: "doc_12345"
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// Query the document
|
|
527
|
+
await use_mcp_tool("lightrag", "query_text", {
|
|
528
|
+
query: "What are the key findings in the research?",
|
|
529
|
+
mode: "local"
|
|
530
|
+
});
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
### Example 3: Work with Knowledge Graph
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
// Get knowledge graph structure
|
|
537
|
+
await use_mcp_tool("lightrag", "get_graph_structure", {});
|
|
538
|
+
|
|
539
|
+
// Check if entity exists
|
|
540
|
+
await use_mcp_tool("lightrag", "check_entity_exists", {
|
|
541
|
+
entity_name: "Artificial Intelligence"
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// Get all entities
|
|
545
|
+
await use_mcp_tool("lightrag", "get_entities", {
|
|
546
|
+
limit: 50
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// Update an entity
|
|
550
|
+
await use_mcp_tool("lightrag", "update_entity", {
|
|
551
|
+
entity_id: "entity_123",
|
|
552
|
+
properties: {
|
|
553
|
+
description: "A comprehensive field of computer science",
|
|
554
|
+
category: "Technology"
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
### Example 4: Advanced Query with Citation
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
// Query with source citations
|
|
563
|
+
await use_mcp_tool("lightrag", "query_with_citation", {
|
|
564
|
+
query: "Explain the benefits of RAG systems",
|
|
565
|
+
mode: "hybrid"
|
|
566
|
+
});
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
## Query Modes Explained
|
|
570
|
+
|
|
571
|
+
LightRAG supports multiple query modes for different use cases:
|
|
572
|
+
|
|
573
|
+
- **naive**: Simple vector similarity search without knowledge graph
|
|
574
|
+
- **local**: Focus on local context and nearby entities
|
|
575
|
+
- **global**: Use global knowledge graph understanding
|
|
576
|
+
- **hybrid**: Combine local and global retrieval (recommended)
|
|
577
|
+
- **mix**: Advanced mode mixing knowledge graph and vector retrieval
|
|
578
|
+
|
|
579
|
+
## Development
|
|
580
|
+
|
|
581
|
+
### Prerequisites
|
|
582
|
+
|
|
583
|
+
- Python 3.10 or higher (for Python implementation)
|
|
584
|
+
- Node.js 18 or higher (for TypeScript implementation)
|
|
585
|
+
- Running LightRAG server instance
|
|
586
|
+
|
|
587
|
+
### Setup for Development
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
# Clone the repository
|
|
591
|
+
git clone https://github.com/yourusername/lightrag-mcp-server.git
|
|
592
|
+
cd lightrag-mcp-server
|
|
593
|
+
|
|
594
|
+
# For Python development
|
|
595
|
+
pip install -e ".[dev]"
|
|
596
|
+
|
|
597
|
+
# For TypeScript development
|
|
598
|
+
npm install
|
|
599
|
+
npm run build
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Running Tests
|
|
603
|
+
|
|
604
|
+
```bash
|
|
605
|
+
# Python tests
|
|
606
|
+
pytest tests/
|
|
607
|
+
|
|
608
|
+
# TypeScript tests
|
|
609
|
+
npm test
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
## API Reference
|
|
613
|
+
|
|
614
|
+
This MCP server implements the LightRAG API. For detailed API documentation, visit:
|
|
615
|
+
|
|
616
|
+
- Official Documentation: [LightRAG GitHub](https://github.com/HKUDS/LightRAG)
|
|
617
|
+
- API Documentation: [LightRAG API Docs](https://github.com/HKUDS/LightRAG/tree/main/lightrag/api)
|
|
618
|
+
|
|
619
|
+
## Requirements
|
|
620
|
+
|
|
621
|
+
- **LightRAG Server**: Running instance of LightRAG (version 1.4.9+)
|
|
622
|
+
- **Python**: Version 3.10 or higher (for Python MCP)
|
|
623
|
+
- **Node.js**: Version 18.0.0 or higher (for TypeScript MCP)
|
|
624
|
+
- **MCP Client**: Compatible MCP client (Claude Desktop, Cline, etc.)
|
|
625
|
+
|
|
626
|
+
## Architecture
|
|
627
|
+
|
|
628
|
+
The LightRAG MCP Server is built with:
|
|
629
|
+
|
|
630
|
+
- **Python MCP**: Using the MCP SDK for Python
|
|
631
|
+
- **TypeScript MCP**: Using the @modelcontextprotocol/sdk
|
|
632
|
+
- **REST API Client**: HTTP client for LightRAG server communication
|
|
633
|
+
- **Error Handling**: Comprehensive error handling and validation
|
|
634
|
+
- **Type Safety**: Full typing support in both implementations
|
|
635
|
+
|
|
636
|
+
## Security Best Practices
|
|
637
|
+
|
|
638
|
+
1. **Never commit API keys** to version control
|
|
639
|
+
2. **Use environment variables** for sensitive credentials
|
|
640
|
+
3. **Run LightRAG server** on localhost or secure network
|
|
641
|
+
4. **Enable authentication** on LightRAG server for production
|
|
642
|
+
5. **Monitor API usage** through server logs
|
|
643
|
+
|
|
644
|
+
## Troubleshooting
|
|
645
|
+
|
|
646
|
+
### Error: Cannot connect to LightRAG server
|
|
647
|
+
|
|
648
|
+
Verify that:
|
|
649
|
+
1. Your LightRAG server is running (`lightrag-server`)
|
|
650
|
+
2. The server URL is correct (default: `http://localhost:9621`)
|
|
651
|
+
3. No firewall is blocking the connection
|
|
652
|
+
|
|
653
|
+
### Error: Authentication failed
|
|
654
|
+
|
|
655
|
+
Verify that:
|
|
656
|
+
1. Your API key matches the LightRAG server configuration
|
|
657
|
+
2. Authentication is properly configured in both server and client
|
|
658
|
+
3. The API key is correctly set in environment variables
|
|
659
|
+
|
|
660
|
+
### Error: Tool not found
|
|
661
|
+
|
|
662
|
+
Ensure you're using the correct tool name. All available tools are listed in the documentation above.
|
|
663
|
+
|
|
664
|
+
### Error: Document upload failed
|
|
665
|
+
|
|
666
|
+
Check that:
|
|
667
|
+
1. The file path is correct and accessible
|
|
668
|
+
2. The file format is supported (PDF, TXT, DOCX, etc.)
|
|
669
|
+
3. You have sufficient permissions to read the file
|
|
670
|
+
|
|
671
|
+
## Contributing
|
|
672
|
+
|
|
673
|
+
Contributions are welcome! Please follow these steps:
|
|
674
|
+
|
|
675
|
+
1. Fork the repository
|
|
676
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
677
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
678
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
679
|
+
5. Open a Pull Request
|
|
680
|
+
|
|
681
|
+
## License
|
|
682
|
+
|
|
683
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
684
|
+
|
|
685
|
+
## Support
|
|
686
|
+
|
|
687
|
+
- **Issues**: [GitHub Issues](https://github.com/lalitsuryan/lightragmcp/issues)
|
|
688
|
+
- **Documentation**: [GitHub README](https://github.com/lalitsuryan/lightragmcp#readme)
|
|
689
|
+
- **LightRAG Support**: [LightRAG GitHub](https://github.com/HKUDS/LightRAG)
|
|
690
|
+
- **Discord**: [LightRAG Discord Community](https://discord.gg/yF2MmDJyGJ)
|
|
691
|
+
|
|
692
|
+
## Acknowledgments
|
|
693
|
+
|
|
694
|
+
- **Author**: [Lalit Suryan](https://github.com/lalitsuryan) - Creator and maintainer
|
|
695
|
+
- Built with the [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
|
|
696
|
+
- Powered by [LightRAG](https://github.com/HKUDS/LightRAG)
|
|
697
|
+
- Inspired by the MCP community
|
|
698
|
+
|
|
699
|
+
## Changelog
|
|
700
|
+
|
|
701
|
+
### Version 1.0.0 (Initial Release)
|
|
702
|
+
|
|
703
|
+
- Complete LightRAG API integration
|
|
704
|
+
- 30+ management tools
|
|
705
|
+
- Support for all query modes
|
|
706
|
+
- Knowledge graph operations
|
|
707
|
+
- Document management
|
|
708
|
+
- Streaming support
|
|
709
|
+
- Full TypeScript and Python support
|
|
710
|
+
- Comprehensive documentation
|
|
711
|
+
- UVX and NPX installation support
|
|
712
|
+
|
|
713
|
+
## Related Projects
|
|
714
|
+
|
|
715
|
+
- [LightRAG](https://github.com/HKUDS/LightRAG) - The core LightRAG library
|
|
716
|
+
- [MiniRAG](https://github.com/HKUDS/MiniRAG) - RAG with small models
|
|
717
|
+
- [VideoRAG](https://github.com/HKUDS/VideoRAG) - RAG for long-context videos
|
|
718
|
+
- [RAG-Anything](https://github.com/HKUDS/RAG-Anything) - All-in-One Multimodal RAG
|
|
719
|
+
|
|
720
|
+
Made with ❤️ by **Lalit Suryan** for the LightRAG and MCP communities
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@g99/lightrag-mcp-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server for LightRAG - Complete RAG and Knowledge Graph integration with 30+ tools",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"lightrag",
|
|
8
|
+
"rag",
|
|
9
|
+
"retrieval-augmented-generation",
|
|
10
|
+
"knowledge-graph",
|
|
11
|
+
"model-context-protocol",
|
|
12
|
+
"ai",
|
|
13
|
+
"llm",
|
|
14
|
+
"claude",
|
|
15
|
+
"mcp-server"
|
|
16
|
+
],
|
|
17
|
+
"author": "Lalit Suryan <lalit@example.com>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/lalitsuryan/lightragmcp.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/lalitsuryan/lightragmcp/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/lalitsuryan/lightragmcp#readme",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prepare": "echo 'This is a Python package wrapper for npm. Install the Python package: pip install lightrag-mcp-server'",
|
|
32
|
+
"postinstall": "echo 'LightRAG MCP Server is a Python package. Please ensure Python 3.10+ is installed and run: pip install lightrag-mcp-server'"
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"lightrag-mcp-server": "wrapper.js"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"wrapper.js",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/wrapper.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LightRAG MCP Server - Node.js Wrapper
|
|
5
|
+
*
|
|
6
|
+
* This is a wrapper script that runs the Python-based LightRAG MCP Server.
|
|
7
|
+
* The actual implementation is in Python. This wrapper helps with npx execution.
|
|
8
|
+
*
|
|
9
|
+
* Author: Lalit Suryan
|
|
10
|
+
* License: MIT
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { spawn } = require('child_process');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
|
|
16
|
+
console.log('LightRAG MCP Server');
|
|
17
|
+
console.log('===================\n');
|
|
18
|
+
|
|
19
|
+
// Check if Python is available
|
|
20
|
+
const checkPython = () => {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
const python = spawn('python', ['--version']);
|
|
23
|
+
|
|
24
|
+
python.on('error', () => {
|
|
25
|
+
const python3 = spawn('python3', ['--version']);
|
|
26
|
+
python3.on('error', () => resolve(false));
|
|
27
|
+
python3.on('close', (code) => resolve(code === 0 ? 'python3' : false));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
python.on('close', (code) => resolve(code === 0 ? 'python' : false));
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const main = async () => {
|
|
35
|
+
const pythonCmd = await checkPython();
|
|
36
|
+
|
|
37
|
+
if (!pythonCmd) {
|
|
38
|
+
console.error('Error: Python 3.10+ is required but not found.');
|
|
39
|
+
console.error('\nPlease install Python from: https://www.python.org/downloads/');
|
|
40
|
+
console.error('\nOr use uvx directly:');
|
|
41
|
+
console.error(' uvx lightrag-mcp-server');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`Found Python: ${pythonCmd}`);
|
|
46
|
+
console.log('\nAttempting to run LightRAG MCP Server...\n');
|
|
47
|
+
|
|
48
|
+
// Try to run the installed Python package
|
|
49
|
+
const server = spawn(pythonCmd, ['-m', 'lightrag_mcp_server'], {
|
|
50
|
+
stdio: 'inherit',
|
|
51
|
+
shell: true
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
server.on('error', (error) => {
|
|
55
|
+
console.error('\nError: LightRAG MCP Server Python package not found.');
|
|
56
|
+
console.error('\nPlease install it first:');
|
|
57
|
+
console.error(' pip install lightrag-mcp-server');
|
|
58
|
+
console.error('\nOr use uvx (recommended):');
|
|
59
|
+
console.error(' uvx lightrag-mcp-server');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
server.on('close', (code) => {
|
|
64
|
+
process.exit(code);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
main();
|