@samanhappy/mcphub 0.0.2 → 0.0.4
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/bin/cli.js +45 -0
- package/package.json +26 -27
- package/bin/mcphub.js +0 -54
package/bin/cli.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// This script enables 'npx @samanhappy/mcphub' functionality
|
|
4
|
+
// It simply forwards all arguments to the main executable
|
|
5
|
+
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
// Get the path to the build directory
|
|
14
|
+
const buildPath = path.resolve(__dirname, '../dist');
|
|
15
|
+
|
|
16
|
+
// Handle the 'node dist/index.js' command format
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
let scriptPath = path.join(buildPath, 'index.js');
|
|
19
|
+
|
|
20
|
+
// If the command includes 'node dist/index.js', use provided arguments
|
|
21
|
+
if (args.length >= 2 && args[0] === 'node' && args[1].includes('index.js')) {
|
|
22
|
+
scriptPath = args[1].startsWith('/') ? args[1] : path.join(process.cwd(), args[1]);
|
|
23
|
+
// Remove 'node' and script path from arguments
|
|
24
|
+
args.splice(0, 2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Start the server with provided arguments
|
|
28
|
+
const server = spawn('node', [scriptPath, ...args], {
|
|
29
|
+
stdio: 'inherit',
|
|
30
|
+
shell: true
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Handle process exit
|
|
34
|
+
server.on('close', (code) => {
|
|
35
|
+
process.exit(code);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Forward signals to the child process
|
|
39
|
+
['SIGINT', 'SIGTERM'].forEach(signal => {
|
|
40
|
+
process.on(signal, () => {
|
|
41
|
+
if (!server.killed) {
|
|
42
|
+
server.kill(signal);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
package/package.json
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samanhappy/mcphub",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A hub server for mcp servers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"mcphub": "./bin/
|
|
9
|
-
"@samanhappy/mcphub": "./bin/mcphub.js"
|
|
8
|
+
"mcphub": "./bin/cli.js"
|
|
10
9
|
},
|
|
11
10
|
"files": [
|
|
12
11
|
"dist",
|
|
13
12
|
"bin",
|
|
14
|
-
"README.md"
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
15
|
],
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"backend:dev": "tsx watch src/index.ts",
|
|
20
|
+
"lint": "eslint . --ext .ts",
|
|
21
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"frontend:dev": "cd frontend && vite",
|
|
24
|
+
"frontend:build": "cd frontend && vite build",
|
|
25
|
+
"frontend:preview": "cd frontend && vite preview",
|
|
26
|
+
"dev": "concurrently \"pnpm backend:dev\" \"pnpm frontend:dev\"",
|
|
27
|
+
"prepublishOnly": "npm run build && npm run frontend:build"
|
|
23
28
|
},
|
|
24
|
-
"
|
|
29
|
+
"keywords": [
|
|
30
|
+
"typescript",
|
|
31
|
+
"server",
|
|
32
|
+
"mcp",
|
|
33
|
+
"model-context-protocol"
|
|
34
|
+
],
|
|
35
|
+
"author": "",
|
|
25
36
|
"license": "ISC",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
26
40
|
"dependencies": {
|
|
27
41
|
"@modelcontextprotocol/sdk": "^1.10.2",
|
|
28
42
|
"@radix-ui/react-accordion": "^1.2.3",
|
|
@@ -74,20 +88,5 @@
|
|
|
74
88
|
"tsx": "^4.7.0",
|
|
75
89
|
"typescript": "^5.2.2",
|
|
76
90
|
"vite": "^5.4.18"
|
|
77
|
-
},
|
|
78
|
-
"scripts": {
|
|
79
|
-
"build": "tsc",
|
|
80
|
-
"start": "node dist/index.js",
|
|
81
|
-
"backend:dev": "tsx watch src/index.ts",
|
|
82
|
-
"lint": "eslint . --ext .ts",
|
|
83
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
84
|
-
"test": "jest",
|
|
85
|
-
"frontend:dev": "cd frontend && vite",
|
|
86
|
-
"frontend:build": "cd frontend && vite build",
|
|
87
|
-
"frontend:preview": "cd frontend && vite preview",
|
|
88
|
-
"dev": "concurrently \"pnpm backend:dev\" \"pnpm frontend:dev\"",
|
|
89
|
-
"prepublishOnly": "npm run build && npm run frontend:build",
|
|
90
|
-
"version": "npm run format && git add -A src",
|
|
91
|
-
"postversion": "git push && git push --tags"
|
|
92
91
|
}
|
|
93
92
|
}
|
package/bin/mcphub.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { dirname, resolve } from 'path';
|
|
5
|
-
import { spawn } from 'child_process';
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const rootDir = resolve(__dirname, '..');
|
|
10
|
-
|
|
11
|
-
// 检查是否有参数
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
const isDev = args.includes('--dev');
|
|
14
|
-
|
|
15
|
-
async function main() {
|
|
16
|
-
try {
|
|
17
|
-
console.log('Starting MCPHub...');
|
|
18
|
-
|
|
19
|
-
if (isDev) {
|
|
20
|
-
// 开发模式:同时启动前端和后端
|
|
21
|
-
console.log('Running in development mode');
|
|
22
|
-
const child = spawn('pnpm', ['dev'], {
|
|
23
|
-
cwd: rootDir,
|
|
24
|
-
stdio: 'inherit',
|
|
25
|
-
shell: true
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// 处理进程退出
|
|
29
|
-
process.on('SIGINT', () => {
|
|
30
|
-
child.kill('SIGINT');
|
|
31
|
-
process.exit(0);
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
// 生产模式:只启动后端(假设前端已经构建)
|
|
35
|
-
console.log('Running in production mode');
|
|
36
|
-
const child = spawn('node', ['dist/index.js'], {
|
|
37
|
-
cwd: rootDir,
|
|
38
|
-
stdio: 'inherit',
|
|
39
|
-
shell: true
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// 处理进程退出
|
|
43
|
-
process.on('SIGINT', () => {
|
|
44
|
-
child.kill('SIGINT');
|
|
45
|
-
process.exit(0);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('Failed to start MCPHub:', error);
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
main();
|