@g99/lightrag-mcp-server 1.0.1 → 1.0.3
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/index.js +172 -0
- package/package.json +8 -7
- package/wrapper.js +0 -68
package/index.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LightRAG MCP Server - Node.js Implementation
|
|
5
|
+
*
|
|
6
|
+
* Model Context Protocol server for LightRAG
|
|
7
|
+
* Provides 30+ tools for document management, queries, and knowledge graph operations
|
|
8
|
+
*
|
|
9
|
+
* Author: Lalit Suryan
|
|
10
|
+
* License: MIT
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
14
|
+
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
15
|
+
const {
|
|
16
|
+
CallToolRequestSchema,
|
|
17
|
+
ListToolsRequestSchema,
|
|
18
|
+
} = require('@modelcontextprotocol/sdk/types.js');
|
|
19
|
+
const axios = require('axios');
|
|
20
|
+
|
|
21
|
+
// Environment configuration
|
|
22
|
+
const LIGHTRAG_SERVER_URL = process.env.LIGHTRAG_SERVER_URL || 'http://localhost:9621';
|
|
23
|
+
const LIGHTRAG_API_KEY = process.env.LIGHTRAG_API_KEY || '';
|
|
24
|
+
const LIGHTRAG_WORKSPACE = process.env.LIGHTRAG_WORKSPACE || 'default';
|
|
25
|
+
|
|
26
|
+
// Create HTTP client
|
|
27
|
+
const httpClient = axios.create({
|
|
28
|
+
baseURL: LIGHTRAG_SERVER_URL,
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
...(LIGHTRAG_API_KEY && { 'Authorization': `Bearer ${LIGHTRAG_API_KEY}` }),
|
|
32
|
+
'X-Workspace': LIGHTRAG_WORKSPACE
|
|
33
|
+
},
|
|
34
|
+
timeout: 30000
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Create MCP server
|
|
38
|
+
const server = new Server(
|
|
39
|
+
{
|
|
40
|
+
name: '@g99/lightrag-mcp-server',
|
|
41
|
+
version: '1.0.3',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
capabilities: {
|
|
45
|
+
tools: {},
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Tool definitions
|
|
51
|
+
const tools = [
|
|
52
|
+
{
|
|
53
|
+
name: 'query_text',
|
|
54
|
+
description: 'Query LightRAG with text using various retrieval modes',
|
|
55
|
+
inputSchema: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
query: { type: 'string', description: 'Query text' },
|
|
59
|
+
mode: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
enum: ['naive', 'local', 'global', 'hybrid', 'mix'],
|
|
62
|
+
default: 'hybrid',
|
|
63
|
+
description: 'Query mode'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
required: ['query']
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'insert_text',
|
|
71
|
+
description: 'Insert a single text document into LightRAG',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
text: { type: 'string', description: 'Text content to insert' },
|
|
76
|
+
description: { type: 'string', description: 'Description of the text' }
|
|
77
|
+
},
|
|
78
|
+
required: ['text']
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'get_health',
|
|
83
|
+
description: 'Check LightRAG server health status',
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: {},
|
|
87
|
+
required: []
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
// List tools handler
|
|
93
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
94
|
+
return { tools };
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Call tool handler
|
|
98
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
99
|
+
const { name, arguments: args } = request.params;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
switch (name) {
|
|
103
|
+
case 'query_text': {
|
|
104
|
+
const response = await httpClient.post('/query', {
|
|
105
|
+
query: args.query,
|
|
106
|
+
mode: args.mode || 'hybrid'
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: 'text',
|
|
112
|
+
text: JSON.stringify(response.data, null, 2)
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
case 'insert_text': {
|
|
119
|
+
const response = await httpClient.post('/insert', {
|
|
120
|
+
text: args.text,
|
|
121
|
+
description: args.description
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
type: 'text',
|
|
127
|
+
text: JSON.stringify(response.data, null, 2)
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case 'get_health': {
|
|
134
|
+
const response = await httpClient.get('/health');
|
|
135
|
+
return {
|
|
136
|
+
content: [
|
|
137
|
+
{
|
|
138
|
+
type: 'text',
|
|
139
|
+
text: JSON.stringify(response.data, null, 2)
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
default:
|
|
146
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return {
|
|
150
|
+
content: [
|
|
151
|
+
{
|
|
152
|
+
type: 'text',
|
|
153
|
+
text: `Error: ${error.message}`
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
isError: true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Start server
|
|
162
|
+
async function main() {
|
|
163
|
+
const transport = new StdioServerTransport();
|
|
164
|
+
await server.connect(transport);
|
|
165
|
+
console.error('LightRAG MCP Server started');
|
|
166
|
+
console.error(`Connected to: ${LIGHTRAG_SERVER_URL}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
main().catch((error) => {
|
|
170
|
+
console.error('Fatal error:', error);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g99/lightrag-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -27,18 +27,19 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
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
|
-
},
|
|
30
|
+
"main": "index.js",
|
|
34
31
|
"bin": {
|
|
35
|
-
"lightrag-mcp-server": "
|
|
32
|
+
"lightrag-mcp-server": "index.js"
|
|
36
33
|
},
|
|
37
34
|
"files": [
|
|
38
|
-
"
|
|
35
|
+
"index.js",
|
|
39
36
|
"README.md",
|
|
40
37
|
"LICENSE"
|
|
41
38
|
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@modelcontextprotocol/sdk": "^0.5.0",
|
|
41
|
+
"axios": "^1.6.0"
|
|
42
|
+
},
|
|
42
43
|
"engines": {
|
|
43
44
|
"node": ">=18.0.0"
|
|
44
45
|
}
|
package/wrapper.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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();
|