vmoo-mcp-database-server 1.1.0 → 1.2.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.
@@ -1,81 +1,81 @@
1
- #!/usr/bin/env node
2
-
3
- // VMOO MCP数据库服务器主入口
4
-
5
- import { spawn } from 'child_process';
6
- import { fileURLToPath } from 'url';
7
- import path from 'path';
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
-
12
- // 解析命令行参数
13
- const args = process.argv.slice(2);
14
- const envArg = args.find(arg => arg.startsWith('--env='));
15
- const environment = envArg ? envArg.split('=')[1] : 'dev';
16
- const configPath = args.find(arg => arg.startsWith('--config='))?.split('=')[1];
17
-
18
- const envNames = {
19
- 'dev': '开发',
20
- 'prod': '生产',
21
- 'deliver': '配送测试'
22
- };
23
-
24
- console.log(`🚀 启动VMOO ${envNames[environment] || '开发'}环境MCP服务器...`);
25
-
26
- // 根据环境选择服务器文件路径
27
- let serverPath;
28
- switch (environment) {
29
- case 'prod':
30
- serverPath = path.join(__dirname, '../vmoo-database-prod/server.js');
31
- break;
32
- case 'deliver':
33
- serverPath = path.join(__dirname, '../vmoo-database-deliver/server.js');
34
- break;
35
- default:
36
- serverPath = path.join(__dirname, '../vmoo-database-dev/server.js');
37
- }
38
-
39
- // 启动服务器
40
- const serverProcess = spawn('node', [serverPath], {
41
- stdio: 'inherit',
42
- env: {
43
- ...process.env,
44
- ...(configPath && { CONFIG_PATH: configPath })
45
- }
46
- });
47
-
48
- // 处理进程退出
49
- serverProcess.on('close', (code) => {
50
- console.log(`🛑 ${envNames[environment] || '开发'}环境MCP服务器已退出,退出码: ${code}`);
51
- process.exit(code);
52
- });
53
-
54
- // 处理中断信号
55
- process.on('SIGINT', () => {
56
- console.log(`\n🛑 正在关闭${envNames[environment] || '开发'}环境MCP服务器...`);
57
- serverProcess.kill('SIGINT');
58
- });
59
-
60
- process.on('SIGTERM', () => {
61
- console.log(`\n🛑 正在关闭${envNames[environment] || '开发'}环境MCP服务器...`);
62
- serverProcess.kill('SIGTERM');
63
- });
64
-
65
- // 如果没有指定环境参数,显示帮助信息
66
- if (!envArg) {
67
- console.log(`
68
- 📋 使用方法:
69
- npx vmoo-mcp-database-server --env=dev # 开发环境
70
- npx vmoo-mcp-database-server --env=prod # 生产环境
71
- npx vmoo-mcp-database-server --env=deliver # 配送测试站
72
-
73
- 或者直接使用:
74
- npx vmoo-mcp-dev # 开发环境
75
- npx vmoo-mcp-prod # 生产环境
76
- npx vmoo-mcp-deliver # 配送测试站
77
-
78
- 配置选项:
79
- --config=path/to/config.json # 自定义配置文件路径
80
- `);
81
- }
1
+ #!/usr/bin/env node
2
+
3
+ // VMOO MCP数据库服务器主入口
4
+
5
+ import { spawn } from 'child_process';
6
+ import { fileURLToPath } from 'url';
7
+ import path from 'path';
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ // 解析命令行参数
13
+ const args = process.argv.slice(2);
14
+ const envArg = args.find(arg => arg.startsWith('--env='));
15
+ const environment = envArg ? envArg.split('=')[1] : 'dev';
16
+ const configPath = args.find(arg => arg.startsWith('--config='))?.split('=')[1];
17
+
18
+ const envNames = {
19
+ 'dev': '开发',
20
+ 'prod': '生产',
21
+ 'deliver': '配送测试'
22
+ };
23
+
24
+ console.log(`🚀 启动VMOO ${envNames[environment] || '开发'}环境MCP服务器...`);
25
+
26
+ // 根据环境选择服务器文件路径
27
+ let serverPath;
28
+ switch (environment) {
29
+ case 'prod':
30
+ serverPath = path.join(__dirname, '../vmoo-database-prod/server.js');
31
+ break;
32
+ case 'deliver':
33
+ serverPath = path.join(__dirname, '../vmoo-database-deliver/server.js');
34
+ break;
35
+ default:
36
+ serverPath = path.join(__dirname, '../vmoo-database-dev/server.js');
37
+ }
38
+
39
+ // 启动服务器
40
+ const serverProcess = spawn('node', [serverPath], {
41
+ stdio: 'inherit',
42
+ env: {
43
+ ...process.env,
44
+ ...(configPath && { CONFIG_PATH: configPath })
45
+ }
46
+ });
47
+
48
+ // 处理进程退出
49
+ serverProcess.on('close', (code) => {
50
+ console.log(`🛑 ${envNames[environment] || '开发'}环境MCP服务器已退出,退出码: ${code}`);
51
+ process.exit(code);
52
+ });
53
+
54
+ // 处理中断信号
55
+ process.on('SIGINT', () => {
56
+ console.log(`\n🛑 正在关闭${envNames[environment] || '开发'}环境MCP服务器...`);
57
+ serverProcess.kill('SIGINT');
58
+ });
59
+
60
+ process.on('SIGTERM', () => {
61
+ console.log(`\n🛑 正在关闭${envNames[environment] || '开发'}环境MCP服务器...`);
62
+ serverProcess.kill('SIGTERM');
63
+ });
64
+
65
+ // 如果没有指定环境参数,显示帮助信息
66
+ if (!envArg) {
67
+ console.log(`
68
+ 📋 使用方法:
69
+ npx vmoo-mcp-database-server --env=dev # 开发环境
70
+ npx vmoo-mcp-database-server --env=prod # 生产环境
71
+ npx vmoo-mcp-database-server --env=deliver # 配送测试站
72
+
73
+ 或者直接使用:
74
+ npx vmoo-mcp-dev # 开发环境
75
+ npx vmoo-mcp-prod # 生产环境
76
+ npx vmoo-mcp-deliver # 配送测试站
77
+
78
+ 配置选项:
79
+ --config=path/to/config.json # 自定义配置文件路径
80
+ `);
81
+ }
package/index.js CHANGED
@@ -1,38 +1,38 @@
1
- #!/usr/bin/env node
2
-
3
- // VMOO MCP数据库服务器包主入口
4
-
5
- export { createConnectionPool, executeQuery } from './shared/database-utils.js';
6
- export { SECURITY_LEVELS, performSecurityCheck } from './shared/security-utils.js';
7
- export { processTimeFields } from './shared/time-utils.js';
8
- export { anonymizeQueryResults } from './shared/privacy-utils.js';
9
-
10
- // 默认导出服务器启动函数
11
- export default function startServer(environment = 'dev') {
12
- const { spawn } = require('child_process');
13
- const path = require('path');
14
-
15
- const serverPath = environment === 'prod'
16
- ? path.join(__dirname, 'vmoo-database-prod/server.js')
17
- : path.join(__dirname, 'vmoo-database-dev/server.js');
18
-
19
- return spawn('node', [serverPath], { stdio: 'inherit' });
20
- }
21
-
22
- // 如果直接运行此文件,显示帮助信息
23
- if (import.meta.url === `file://${process.argv[1]}`) {
24
- console.log(`
25
- 🟡 VMOO MCP数据库服务器
26
-
27
- 使用方法:
28
- npx @vmoo/mcp-database-server@latest --env=dev # 开发环境
29
- npx @vmoo/mcp-database-server@latest --env=prod # 生产环境
30
-
31
- 或者直接使用:
32
- npx vmoo-mcp-dev # 开发环境
33
- npx vmoo-mcp-prod # 生产环境
34
-
35
- 配置文件:
36
- --config=path/to/config.json # 自定义配置文件路径
37
- `);
38
- }
1
+ #!/usr/bin/env node
2
+
3
+ // VMOO MCP数据库服务器包主入口
4
+
5
+ export { createConnectionPool, executeQuery } from './shared/database-utils.js';
6
+ export { SECURITY_LEVELS, performSecurityCheck } from './shared/security-utils.js';
7
+ export { processTimeFields } from './shared/time-utils.js';
8
+ export { anonymizeQueryResults } from './shared/privacy-utils.js';
9
+
10
+ // 默认导出服务器启动函数
11
+ export default function startServer(environment = 'dev') {
12
+ const { spawn } = require('child_process');
13
+ const path = require('path');
14
+
15
+ const serverPath = environment === 'prod'
16
+ ? path.join(__dirname, 'vmoo-database-prod/server.js')
17
+ : path.join(__dirname, 'vmoo-database-dev/server.js');
18
+
19
+ return spawn('node', [serverPath], { stdio: 'inherit' });
20
+ }
21
+
22
+ // 如果直接运行此文件,显示帮助信息
23
+ if (import.meta.url === `file://${process.argv[1]}`) {
24
+ console.log(`
25
+ 🟡 VMOO MCP数据库服务器
26
+
27
+ 使用方法:
28
+ npx @vmoo/mcp-database-server@latest --env=dev # 开发环境
29
+ npx @vmoo/mcp-database-server@latest --env=prod # 生产环境
30
+
31
+ 或者直接使用:
32
+ npx vmoo-mcp-dev # 开发环境
33
+ npx vmoo-mcp-prod # 生产环境
34
+
35
+ 配置文件:
36
+ --config=path/to/config.json # 自定义配置文件路径
37
+ `);
38
+ }
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "vmoo-mcp-database-server",
3
- "version": "1.1.0",
4
- "description": "VMOO数据库MCP服务器集合 - 支持开发和生产环境的安全数据库访问",
5
- "type": "module",
6
- "main": "index.js",
7
- "bin": {
8
- "vmoo-mcp-database-server": "./bin/vmoo-mcp-server.js",
9
- "vmoo-mcp-dev": "./bin/vmoo-mcp-dev.js",
10
- "vmoo-mcp-prod": "./bin/vmoo-mcp-prod.js",
11
- "vmoo-mcp-deliver": "./bin/vmoo-mcp-deliver.js"
12
- },
13
- "scripts": {
14
- "start:prod": "cd vmoo-database-prod && npm start",
15
- "start:dev": "cd vmoo-database-dev && npm start",
16
- "install:all": "npm install && cd vmoo-database-prod && npm install && cd ../vmoo-database-dev && npm install",
17
- "test:all": "cd vmoo-database-prod && npm test && cd ../vmoo-database-dev && npm test",
18
- "build": "echo '构建完成'",
19
- "deploy": "./scripts/deploy.sh"
20
- },
21
- "dependencies": {
22
- "@modelcontextprotocol/sdk": "^1.17.2",
23
- "mysql2": "^3.6.5"
24
- },
25
- "devDependencies": {
26
- "@types/node": "^20.0.0"
27
- },
28
- "keywords": [
29
- "mcp",
30
- "database",
31
- "mysql",
32
- "vmoo",
33
- "model-context-protocol",
34
- "production",
35
- "development",
36
- "privacy",
37
- "security"
38
- ],
39
- "author": "VMOO Team",
40
- "license": "MIT",
41
- "engines": {
42
- "node": ">=18.0.0"
43
- },
44
- "files": [
45
- "bin/",
46
- "shared/",
47
- "vmoo-database-dev/",
48
- "vmoo-database-prod/",
49
- "vmoo-database-deliver/",
50
- "index.js",
51
- "README.md"
52
- ],
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/jinzong8/vmoo-mcp-server.git"
56
- },
57
- "bugs": {
58
- "url": "https://github.com/jinzong8/vmoo-mcp-server/issues"
59
- },
60
- "homepage": "https://github.com/jinzong8/vmoo-mcp-server#readme"
61
- }
1
+ {
2
+ "name": "vmoo-mcp-database-server",
3
+ "version": "1.2.1",
4
+ "description": "VMOO数据库MCP服务器集合 - 支持开发和生产环境的安全数据库访问",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "vmoo-mcp-database-server": "./bin/vmoo-mcp-server.js",
9
+ "vmoo-mcp-dev": "./bin/vmoo-mcp-dev.js",
10
+ "vmoo-mcp-prod": "./bin/vmoo-mcp-prod.js",
11
+ "vmoo-mcp-deliver": "./bin/vmoo-mcp-deliver.js"
12
+ },
13
+ "scripts": {
14
+ "start:prod": "cd vmoo-database-prod && npm start",
15
+ "start:dev": "cd vmoo-database-dev && npm start",
16
+ "install:all": "npm install && cd vmoo-database-prod && npm install && cd ../vmoo-database-dev && npm install",
17
+ "test:all": "cd vmoo-database-prod && npm test && cd ../vmoo-database-dev && npm test",
18
+ "build": "echo '构建完成'",
19
+ "deploy": "./scripts/deploy.sh"
20
+ },
21
+ "dependencies": {
22
+ "@modelcontextprotocol/sdk": "^1.17.2",
23
+ "mysql2": "^3.6.5"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.0.0"
27
+ },
28
+ "keywords": [
29
+ "mcp",
30
+ "database",
31
+ "mysql",
32
+ "vmoo",
33
+ "model-context-protocol",
34
+ "production",
35
+ "development",
36
+ "privacy",
37
+ "security"
38
+ ],
39
+ "author": "VMOO Team",
40
+ "license": "MIT",
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "files": [
45
+ "bin/",
46
+ "shared/",
47
+ "vmoo-database-dev/",
48
+ "vmoo-database-prod/",
49
+ "vmoo-database-deliver/",
50
+ "index.js",
51
+ "README.md"
52
+ ],
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/jinzong8/vmoo-mcp-server.git"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/jinzong8/vmoo-mcp-server/issues"
59
+ },
60
+ "homepage": "https://github.com/jinzong8/vmoo-mcp-server#readme"
61
+ }
@@ -1,102 +1,102 @@
1
- // VMOO数据库工具函数
2
- import mysql from 'mysql2/promise';
3
-
4
- /**
5
- * 创建数据库连接池
6
- * @param {Object} config 数据库配置
7
- * @returns {Object} 连接池
8
- */
9
- function createConnectionPool(config) {
10
- return mysql.createPool({
11
- ...config,
12
- waitForConnections: true,
13
- connectionLimit: 10,
14
- queueLimit: 0
15
- });
16
- }
17
-
18
- /**
19
- * 标准化表名(添加fanwe_前缀)
20
- * @param {string} tableName 表名
21
- * @returns {string} 标准化后的表名
22
- */
23
- function normalizeTableName(tableName) {
24
- if (!tableName.startsWith('fanwe_')) {
25
- return `fanwe_${tableName}`;
26
- }
27
- return tableName;
28
- }
29
-
30
- /**
31
- * 执行查询并处理错误
32
- * @param {Object} pool 连接池
33
- * @param {string} query 查询语句
34
- * @returns {Array} 查询结果
35
- */
36
- async function executeQuery(pool, query) {
37
- try {
38
- const [rows] = await pool.execute(query);
39
- return rows;
40
- } catch (error) {
41
- throw new Error(`数据库查询失败: ${error.message}`);
42
- }
43
- }
44
-
45
- /**
46
- * 获取表结构
47
- * @param {Object} pool 连接池
48
- * @param {string} tableName 表名
49
- * @returns {Array} 表结构
50
- */
51
- async function getTableStructure(pool, tableName) {
52
- const normalizedName = normalizeTableName(tableName);
53
- return await executeQuery(pool, `DESCRIBE ${normalizedName}`);
54
- }
55
-
56
- /**
57
- * 获取表记录数
58
- * @param {Object} pool 连接池
59
- * @param {string} tableName 表名
60
- * @returns {number} 记录数
61
- */
62
- async function getTableCount(pool, tableName) {
63
- const normalizedName = normalizeTableName(tableName);
64
- const rows = await executeQuery(pool, `SELECT COUNT(*) as count FROM ${normalizedName}`);
65
- return rows[0].count;
66
- }
67
-
68
- /**
69
- * 获取表示例数据
70
- * @param {Object} pool 连接池
71
- * @param {string} tableName 表名
72
- * @param {number} limit 限制数量
73
- * @returns {Array} 示例数据
74
- */
75
- async function getTableSampleData(pool, tableName, limit = 10) {
76
- const normalizedName = normalizeTableName(tableName);
77
- return await executeQuery(pool, `SELECT * FROM ${normalizedName} LIMIT ${limit}`);
78
- }
79
-
80
- /**
81
- * 列出所有表
82
- * @param {Object} pool 连接池
83
- * @param {string} pattern 匹配模式
84
- * @returns {Array} 表列表
85
- */
86
- async function listTables(pool, pattern = null) {
87
- let query = "SHOW TABLES";
88
- if (pattern) {
89
- query += ` LIKE '%${pattern}%'`;
90
- }
91
- return await executeQuery(pool, query);
92
- }
93
-
94
- export {
95
- createConnectionPool,
96
- normalizeTableName,
97
- executeQuery,
98
- getTableStructure,
99
- getTableCount,
100
- getTableSampleData,
101
- listTables
102
- };
1
+ // VMOO数据库工具函数
2
+ import mysql from 'mysql2/promise';
3
+
4
+ /**
5
+ * 创建数据库连接池
6
+ * @param {Object} config 数据库配置
7
+ * @returns {Object} 连接池
8
+ */
9
+ function createConnectionPool(config) {
10
+ return mysql.createPool({
11
+ ...config,
12
+ waitForConnections: true,
13
+ connectionLimit: 10,
14
+ queueLimit: 0
15
+ });
16
+ }
17
+
18
+ /**
19
+ * 标准化表名(添加fanwe_前缀)
20
+ * @param {string} tableName 表名
21
+ * @returns {string} 标准化后的表名
22
+ */
23
+ function normalizeTableName(tableName) {
24
+ if (!tableName.startsWith('fanwe_')) {
25
+ return `fanwe_${tableName}`;
26
+ }
27
+ return tableName;
28
+ }
29
+
30
+ /**
31
+ * 执行查询并处理错误
32
+ * @param {Object} pool 连接池
33
+ * @param {string} query 查询语句
34
+ * @returns {Array} 查询结果
35
+ */
36
+ async function executeQuery(pool, query) {
37
+ try {
38
+ const [rows] = await pool.execute(query);
39
+ return rows;
40
+ } catch (error) {
41
+ throw new Error(`数据库查询失败: ${error.message}`);
42
+ }
43
+ }
44
+
45
+ /**
46
+ * 获取表结构
47
+ * @param {Object} pool 连接池
48
+ * @param {string} tableName 表名
49
+ * @returns {Array} 表结构
50
+ */
51
+ async function getTableStructure(pool, tableName) {
52
+ const normalizedName = normalizeTableName(tableName);
53
+ return await executeQuery(pool, `DESCRIBE ${normalizedName}`);
54
+ }
55
+
56
+ /**
57
+ * 获取表记录数
58
+ * @param {Object} pool 连接池
59
+ * @param {string} tableName 表名
60
+ * @returns {number} 记录数
61
+ */
62
+ async function getTableCount(pool, tableName) {
63
+ const normalizedName = normalizeTableName(tableName);
64
+ const rows = await executeQuery(pool, `SELECT COUNT(*) as count FROM ${normalizedName}`);
65
+ return rows[0].count;
66
+ }
67
+
68
+ /**
69
+ * 获取表示例数据
70
+ * @param {Object} pool 连接池
71
+ * @param {string} tableName 表名
72
+ * @param {number} limit 限制数量
73
+ * @returns {Array} 示例数据
74
+ */
75
+ async function getTableSampleData(pool, tableName, limit = 10) {
76
+ const normalizedName = normalizeTableName(tableName);
77
+ return await executeQuery(pool, `SELECT * FROM ${normalizedName} LIMIT ${limit}`);
78
+ }
79
+
80
+ /**
81
+ * 列出所有表
82
+ * @param {Object} pool 连接池
83
+ * @param {string} pattern 匹配模式
84
+ * @returns {Array} 表列表
85
+ */
86
+ async function listTables(pool, pattern = null) {
87
+ let query = "SHOW TABLES";
88
+ if (pattern) {
89
+ query += ` LIKE '%${pattern}%'`;
90
+ }
91
+ return await executeQuery(pool, query);
92
+ }
93
+
94
+ export {
95
+ createConnectionPool,
96
+ normalizeTableName,
97
+ executeQuery,
98
+ getTableStructure,
99
+ getTableCount,
100
+ getTableSampleData,
101
+ listTables
102
+ };