unity-mcp-bridge 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 +28 -0
- package/install.js +122 -0
- package/package.json +29 -0
package/bin/run.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const binDir = __dirname;
|
|
8
|
+
const exeName = process.platform === "win32" ? "UnityMcpBridge.exe" : "UnityMcpBridge";
|
|
9
|
+
const exePath = path.join(binDir, exeName);
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(exePath)) {
|
|
12
|
+
console.error("unity-mcp-bridge binary not found. Run 'npm install' to download it.");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const child = spawn(exePath, process.argv.slice(2), {
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
env: process.env,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
child.on("error", (err) => {
|
|
22
|
+
console.error(`Failed to start unity-mcp-bridge: ${err.message}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
child.on("exit", (code) => {
|
|
27
|
+
process.exit(code ?? 0);
|
|
28
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const https = require("https");
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const VERSION = require("./package.json").version;
|
|
9
|
+
const REPO = "breadpack/UnityMcp";
|
|
10
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
11
|
+
|
|
12
|
+
function getPlatformAsset() {
|
|
13
|
+
const platform = process.platform;
|
|
14
|
+
const arch = process.arch;
|
|
15
|
+
|
|
16
|
+
const map = {
|
|
17
|
+
"win32-x64": "win-x64",
|
|
18
|
+
"win32-arm64": "win-arm64",
|
|
19
|
+
"linux-x64": "linux-x64",
|
|
20
|
+
"linux-arm64": "linux-arm64",
|
|
21
|
+
"darwin-x64": "osx-x64",
|
|
22
|
+
"darwin-arm64": "osx-arm64",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const rid = map[`${platform}-${arch}`];
|
|
26
|
+
if (!rid) {
|
|
27
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ext = platform === "win32" ? ".zip" : ".tar.gz";
|
|
32
|
+
return { rid, fileName: `unity-mcp-bridge-${rid}${ext}` };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function httpsGet(url) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
https
|
|
38
|
+
.get(url, { headers: { "User-Agent": "unity-mcp-bridge-npm" } }, (res) => {
|
|
39
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
40
|
+
return httpsGet(res.headers.location).then(resolve, reject);
|
|
41
|
+
}
|
|
42
|
+
if (res.statusCode !== 200) {
|
|
43
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
44
|
+
}
|
|
45
|
+
const chunks = [];
|
|
46
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
47
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
48
|
+
res.on("error", reject);
|
|
49
|
+
})
|
|
50
|
+
.on("error", reject);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function extractZip(buffer, destDir) {
|
|
55
|
+
const tmpZip = path.join(destDir, "_tmp.zip");
|
|
56
|
+
fs.writeFileSync(tmpZip, buffer);
|
|
57
|
+
try {
|
|
58
|
+
if (process.platform === "win32") {
|
|
59
|
+
execSync(
|
|
60
|
+
`powershell -NoProfile -Command "Expand-Archive -Path '${tmpZip}' -DestinationPath '${destDir}' -Force"`,
|
|
61
|
+
{ stdio: "pipe" }
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
execSync(`unzip -o "${tmpZip}" -d "${destDir}"`, { stdio: "pipe" });
|
|
65
|
+
}
|
|
66
|
+
} finally {
|
|
67
|
+
fs.unlinkSync(tmpZip);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function extractTarGz(buffer, destDir) {
|
|
72
|
+
const tmpTar = path.join(destDir, "_tmp.tar.gz");
|
|
73
|
+
fs.writeFileSync(tmpTar, buffer);
|
|
74
|
+
try {
|
|
75
|
+
execSync(`tar -xzf "${tmpTar}" -C "${destDir}"`, { stdio: "pipe" });
|
|
76
|
+
} finally {
|
|
77
|
+
fs.unlinkSync(tmpTar);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main() {
|
|
82
|
+
const { rid, fileName } = getPlatformAsset();
|
|
83
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${fileName}`;
|
|
84
|
+
|
|
85
|
+
console.log(`Downloading unity-mcp-bridge ${VERSION} for ${rid}...`);
|
|
86
|
+
|
|
87
|
+
let buffer;
|
|
88
|
+
try {
|
|
89
|
+
buffer = await httpsGet(url);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(`Failed to download: ${err.message}`);
|
|
92
|
+
console.error(`URL: ${url}`);
|
|
93
|
+
console.error(
|
|
94
|
+
`\nIf the release does not exist yet, install via dotnet tool instead:`
|
|
95
|
+
);
|
|
96
|
+
console.error(` dotnet tool install -g dev.breadpack.UnityMcpBridge`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
101
|
+
|
|
102
|
+
if (fileName.endsWith(".zip")) {
|
|
103
|
+
await extractZip(buffer, BIN_DIR);
|
|
104
|
+
} else {
|
|
105
|
+
await extractTarGz(buffer, BIN_DIR);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Make executable on Unix
|
|
109
|
+
if (process.platform !== "win32") {
|
|
110
|
+
const exePath = path.join(BIN_DIR, "UnityMcpBridge");
|
|
111
|
+
if (fs.existsSync(exePath)) {
|
|
112
|
+
fs.chmodSync(exePath, 0o755);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log(`unity-mcp-bridge ${VERSION} installed successfully.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
main().catch((err) => {
|
|
120
|
+
console.error(err);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "unity-mcp-bridge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP (Model Context Protocol) Bridge for Unity Editor — connect AI agents to Unity Editor",
|
|
5
|
+
"bin": {
|
|
6
|
+
"unity-mcp-bridge": "./bin/run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"mcp",
|
|
13
|
+
"unity",
|
|
14
|
+
"ai",
|
|
15
|
+
"editor",
|
|
16
|
+
"tools",
|
|
17
|
+
"model-context-protocol"
|
|
18
|
+
],
|
|
19
|
+
"author": "breadpack",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/breadpack/UnityMcp.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/breadpack/UnityMcp",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|