-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (61 loc) · 1.88 KB
/
index.js
File metadata and controls
72 lines (61 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
/**
* DBJavaGenix MCP Server Entry Point
* 作者: ZXP (2638265504@qq.com)
* 用于Cherry Studio等MCP客户端的标准化入口
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const projectDir = __dirname;
const srcDir = path.join(projectDir, 'src');
console.log('DBJavaGenix MCP Server v0.1.0');
console.log('🚀 Starting server in stdio mode...');
console.log(`📁 Project: ${projectDir}`);
console.log(`📂 Source: ${srcDir}`);
// 验证项目结构
if (!fs.existsSync(srcDir)) {
console.error('❌ Error: Source directory not found');
console.error(`Expected: ${srcDir}`);
process.exit(1);
}
if (!fs.existsSync(path.join(srcDir, 'dbjavagenix'))) {
console.error('❌ Error: dbjavagenix module not found');
console.error(`Expected: ${path.join(srcDir, 'dbjavagenix')}`);
process.exit(1);
}
// 启动Python MCP服务器
const python = spawn('python', ['-m', 'dbjavagenix.cli', 'server'], {
cwd: projectDir,
env: {
...process.env,
PYTHONPATH: srcDir
},
stdio: 'inherit'
});
python.on('error', (err) => {
console.error('❌ Failed to start Python MCP server:', err.message);
console.error('💡 Make sure Python is installed and available in PATH');
console.error('💡 Make sure dbjavagenix module is properly installed');
process.exit(1);
});
python.on('close', (code) => {
if (code !== 0) {
console.error(`❌ Python process exited with code ${code}`);
}
process.exit(code);
});
// 优雅关闭处理
process.on('SIGINT', () => {
console.log('\n🛑 Received SIGINT, shutting down...');
python.kill('SIGINT');
});
process.on('SIGTERM', () => {
console.log('\n🛑 Received SIGTERM, shutting down...');
python.kill('SIGTERM');
});
process.on('uncaughtException', (err) => {
console.error('❌ Uncaught exception:', err);
python.kill('SIGTERM');
process.exit(1);
});