dragon-head-mcp 0.1.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/bin/run.js +115 -0
- package/package.json +30 -0
package/bin/run.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
|
|
8
|
+
// Keep this map in sync with the wrapper package.json's optionalDependencies
|
|
9
|
+
// and the 5 npm/platform/*/package.json names (see test/run.test.js, which
|
|
10
|
+
// asserts all three agree). scripts/install.sh and .github/workflows/release.yml
|
|
11
|
+
// maintain their own parallel platform lists in different languages/formats —
|
|
12
|
+
// check those too when adding or removing a platform here.
|
|
13
|
+
const PLATFORM_PACKAGES = {
|
|
14
|
+
'darwin,arm64': 'dragon-head-mcp-darwin-arm64',
|
|
15
|
+
'darwin,x64': 'dragon-head-mcp-darwin-x64',
|
|
16
|
+
'linux,x64': 'dragon-head-mcp-linux-x64',
|
|
17
|
+
'linux,arm64': 'dragon-head-mcp-linux-arm64',
|
|
18
|
+
'win32,x64': 'dragon-head-mcp-win32-x64',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Architectures we publish glibc Linux builds for. Used only to decide
|
|
22
|
+
// whether the musl/Alpine hint below is relevant — an unsupported Linux
|
|
23
|
+
// architecture outside this set (e.g. ia32, arm) is an arch problem, not a
|
|
24
|
+
// libc problem, and the hint would be misleading there.
|
|
25
|
+
const SUPPORTED_LINUX_ARCHS = new Set(['x64', 'arm64']);
|
|
26
|
+
|
|
27
|
+
function resolveBinaryPath(platform = process.platform, arch = process.arch) {
|
|
28
|
+
const key = `${platform},${arch}`;
|
|
29
|
+
const pkgName = PLATFORM_PACKAGES[key];
|
|
30
|
+
|
|
31
|
+
if (!pkgName) {
|
|
32
|
+
const muslHint =
|
|
33
|
+
platform === 'linux' && SUPPORTED_LINUX_ARCHS.has(arch)
|
|
34
|
+
? ' Note: only glibc Linux builds are published (no musl/Alpine support yet).'
|
|
35
|
+
: '';
|
|
36
|
+
console.error(
|
|
37
|
+
`dragon-head-mcp: unsupported platform "${key}".${muslHint}\n` +
|
|
38
|
+
'Use scripts/install.sh or build from source: https://github.com/takurot/dragon-head#install'
|
|
39
|
+
);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Resolve via the platform package's own package.json rather than guessing
|
|
44
|
+
// a node_modules path directly, so this also works under non-flat layouts
|
|
45
|
+
// (pnpm, yarn PnP) where require.resolve still honors the resolver's own
|
|
46
|
+
// module map even without a literal node_modules tree.
|
|
47
|
+
let pkgJsonPath;
|
|
48
|
+
try {
|
|
49
|
+
pkgJsonPath = require.resolve(`${pkgName}/package.json`);
|
|
50
|
+
} catch {
|
|
51
|
+
console.error(
|
|
52
|
+
`dragon-head-mcp: optional dependency "${pkgName}" is not installed.\n` +
|
|
53
|
+
'Re-run npm install, or check that npm config (ignore-scripts / os-cpu ' +
|
|
54
|
+
'mismatch) did not skip optionalDependencies.'
|
|
55
|
+
);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let pkgJson;
|
|
60
|
+
try {
|
|
61
|
+
pkgJson = require(pkgJsonPath);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(
|
|
64
|
+
`dragon-head-mcp: "${pkgName}"'s package.json is corrupted (${err.message}).\n` +
|
|
65
|
+
'Re-run npm install to repair it.'
|
|
66
|
+
);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const relativeBinaryPath = pkgJson.dragonHeadBinary;
|
|
71
|
+
if (!relativeBinaryPath) {
|
|
72
|
+
console.error(`dragon-head-mcp: "${pkgName}" is missing its dragonHeadBinary field.`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const binaryPath = path.join(path.dirname(pkgJsonPath), relativeBinaryPath);
|
|
77
|
+
if (!fs.existsSync(binaryPath)) {
|
|
78
|
+
console.error(`dragon-head-mcp: binary not found at ${binaryPath} (corrupt install?).`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return binaryPath;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function main() {
|
|
86
|
+
const binaryPath = resolveBinaryPath();
|
|
87
|
+
const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
88
|
+
|
|
89
|
+
const forwardSignal = (signal) => {
|
|
90
|
+
child.kill(signal);
|
|
91
|
+
};
|
|
92
|
+
process.on('SIGINT', forwardSignal);
|
|
93
|
+
process.on('SIGTERM', forwardSignal);
|
|
94
|
+
|
|
95
|
+
child.on('error', (err) => {
|
|
96
|
+
console.error(`dragon-head-mcp: failed to start binary: ${err.message}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
child.on('exit', (code, signal) => {
|
|
101
|
+
if (signal) {
|
|
102
|
+
// Re-raise the same signal on this process so a wrapping supervisor
|
|
103
|
+
// sees the real termination cause instead of a synthetic exit code.
|
|
104
|
+
process.kill(process.pid, signal);
|
|
105
|
+
} else {
|
|
106
|
+
process.exit(code ?? 1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = { PLATFORM_PACKAGES, resolveBinaryPath };
|
|
112
|
+
|
|
113
|
+
if (require.main === module) {
|
|
114
|
+
main();
|
|
115
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dragon-head-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI-native headless browser runtime MCP server (npm distribution wrapper)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/takurot/dragon-head.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/takurot/dragon-head",
|
|
11
|
+
"bin": {
|
|
12
|
+
"dragon-head-mcp": "bin/run.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/run.js"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node --test test/run.test.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"dragon-head-mcp-darwin-arm64": "0.1.0",
|
|
25
|
+
"dragon-head-mcp-darwin-x64": "0.1.0",
|
|
26
|
+
"dragon-head-mcp-linux-x64": "0.1.0",
|
|
27
|
+
"dragon-head-mcp-linux-arm64": "0.1.0",
|
|
28
|
+
"dragon-head-mcp-win32-x64": "0.1.0"
|
|
29
|
+
}
|
|
30
|
+
}
|