@hayasaka7/go-arch-xray 0.5.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/LICENSE +21 -0
- package/README.md +53 -0
- package/bin/go-arch-xray.js +46 -0
- package/install.js +158 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HAYASAKA7
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# go-arch-xray
|
|
2
|
+
|
|
3
|
+
npm distribution of [`go-arch-xray`](https://github.com/HAYASAKA7/go-arch-xray) — a
|
|
4
|
+
Model Context Protocol (MCP) server for static analysis of Go codebases.
|
|
5
|
+
|
|
6
|
+
This package contains a small Node launcher. On install, a `postinstall` script
|
|
7
|
+
downloads the matching native binary (Windows / macOS / Linux × x64 / arm64)
|
|
8
|
+
from the corresponding [GitHub Release](https://github.com/HAYASAKA7/go-arch-xray/releases).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @hayasaka7/go-arch-xray
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or use it without installing:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx -y @hayasaka7/go-arch-xray
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## MCP host configuration
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"mcpServers": {
|
|
27
|
+
"go-arch-xray": {
|
|
28
|
+
"command": "npx",
|
|
29
|
+
"args": ["-y", "@hayasaka7/go-arch-xray"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Environment variables
|
|
36
|
+
|
|
37
|
+
- `GO_ARCH_XRAY_BIN` — absolute path to a pre-installed binary. When set,
|
|
38
|
+
`postinstall` is skipped and the launcher invokes that binary directly.
|
|
39
|
+
Useful for air-gapped environments or corporate package mirrors.
|
|
40
|
+
|
|
41
|
+
## Troubleshooting
|
|
42
|
+
|
|
43
|
+
- **Install ran with `--ignore-scripts`**: download blocked. Run
|
|
44
|
+
`npm rebuild @hayasaka7/go-arch-xray` once, or set `GO_ARCH_XRAY_BIN`.
|
|
45
|
+
- **Behind a firewall**: download the matching release asset manually from
|
|
46
|
+
<https://github.com/HAYASAKA7/go-arch-xray/releases>, extract it, and set
|
|
47
|
+
`GO_ARCH_XRAY_BIN` to the binary path.
|
|
48
|
+
- **Unsupported platform**: build from source —
|
|
49
|
+
see <https://github.com/HAYASAKA7/go-arch-xray#build-from-source>.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher: locates the platform-specific go-arch-xray binary downloaded
|
|
3
|
+
// by install.js (or pointed to by GO_ARCH_XRAY_BIN) and execs it with the
|
|
4
|
+
// caller's argv, inheriting stdio and exit code.
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const { spawnSync } = require("child_process");
|
|
11
|
+
|
|
12
|
+
const REPO = "HAYASAKA7/go-arch-xray";
|
|
13
|
+
|
|
14
|
+
function resolveBinary() {
|
|
15
|
+
if (process.env.GO_ARCH_XRAY_BIN) {
|
|
16
|
+
return process.env.GO_ARCH_XRAY_BIN;
|
|
17
|
+
}
|
|
18
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
19
|
+
return path.join(__dirname, `go-arch-xray${ext}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const binPath = resolveBinary();
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(binPath)) {
|
|
25
|
+
process.stderr.write(
|
|
26
|
+
`[go-arch-xray] binary not found at ${binPath}\n` +
|
|
27
|
+
`The npm postinstall step did not run or failed.\n` +
|
|
28
|
+
`Try one of:\n` +
|
|
29
|
+
` npm rebuild @hayasaka7/go-arch-xray\n` +
|
|
30
|
+
` download the asset manually from https://github.com/${REPO}/releases and set GO_ARCH_XRAY_BIN\n`
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
36
|
+
|
|
37
|
+
if (result.error) {
|
|
38
|
+
process.stderr.write(`[go-arch-xray] failed to spawn binary: ${result.error.message}\n`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (result.signal) {
|
|
43
|
+
process.kill(process.pid, result.signal);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process.exit(result.status ?? 1);
|
package/install.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Downloads the platform-specific go-arch-xray binary from the matching
|
|
3
|
+
// GitHub Release and extracts it into ./bin. Runs automatically as the
|
|
4
|
+
// npm `postinstall` step.
|
|
5
|
+
//
|
|
6
|
+
// Override the binary location entirely by setting GO_ARCH_XRAY_BIN to an
|
|
7
|
+
// absolute path; in that case this script does nothing.
|
|
8
|
+
//
|
|
9
|
+
// Skip the download in CI / offline installs with `npm install --ignore-scripts`.
|
|
10
|
+
// The bin shim will print a clear remediation message at first run.
|
|
11
|
+
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const os = require("os");
|
|
17
|
+
const { spawnSync } = require("child_process");
|
|
18
|
+
const { pipeline } = require("stream/promises");
|
|
19
|
+
const { Readable } = require("stream");
|
|
20
|
+
|
|
21
|
+
const REPO = "HAYASAKA7/go-arch-xray";
|
|
22
|
+
const pkg = require("./package.json");
|
|
23
|
+
const VERSION = pkg.version;
|
|
24
|
+
const TAG = `v${VERSION}`;
|
|
25
|
+
|
|
26
|
+
const PLATFORM_MAP = {
|
|
27
|
+
"win32-x64": { goos: "windows", goarch: "amd64", ext: ".exe", archive: "zip" },
|
|
28
|
+
"win32-arm64": { goos: "windows", goarch: "arm64", ext: ".exe", archive: "zip" },
|
|
29
|
+
"darwin-x64": { goos: "darwin", goarch: "amd64", ext: "", archive: "tar.gz" },
|
|
30
|
+
"darwin-arm64": { goos: "darwin", goarch: "arm64", ext: "", archive: "tar.gz" },
|
|
31
|
+
"linux-x64": { goos: "linux", goarch: "amd64", ext: "", archive: "tar.gz" },
|
|
32
|
+
"linux-arm64": { goos: "linux", goarch: "arm64", ext: "", archive: "tar.gz" },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function log(msg) {
|
|
36
|
+
process.stderr.write(`[go-arch-xray] ${msg}\n`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function fail(msg, code = 1) {
|
|
40
|
+
log(`ERROR: ${msg}`);
|
|
41
|
+
process.exit(code);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function detectTarget() {
|
|
45
|
+
const key = `${process.platform}-${process.arch}`;
|
|
46
|
+
const target = PLATFORM_MAP[key];
|
|
47
|
+
if (!target) {
|
|
48
|
+
fail(
|
|
49
|
+
`Unsupported platform ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}.\n` +
|
|
50
|
+
`Build from source: https://github.com/${REPO}#build-from-source`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return { key, ...target };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function binaryPath(target) {
|
|
57
|
+
const binDir = path.join(__dirname, "bin");
|
|
58
|
+
const name = `go-arch-xray${target.ext}`;
|
|
59
|
+
return { binDir, binPath: path.join(binDir, name) };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function archiveInternalName(target) {
|
|
63
|
+
return `go-arch-xray-${target.goos}-${target.goarch}${target.ext}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function archiveAssetName(target) {
|
|
67
|
+
return `go-arch-xray-${TAG}-${target.goos}-${target.goarch}.${target.archive}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function assetUrl(target) {
|
|
71
|
+
return `https://github.com/${REPO}/releases/download/${TAG}/${archiveAssetName(target)}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function download(url, destFile) {
|
|
75
|
+
log(`downloading ${url}`);
|
|
76
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
throw new Error(`HTTP ${res.status} ${res.statusText} for ${url}`);
|
|
79
|
+
}
|
|
80
|
+
await pipeline(Readable.fromWeb(res.body), fs.createWriteStream(destFile));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function ensureTar() {
|
|
84
|
+
const probe = spawnSync("tar", ["--version"], { stdio: "ignore" });
|
|
85
|
+
if (probe.status !== 0) {
|
|
86
|
+
fail(
|
|
87
|
+
"`tar` was not found on PATH. Install GNU tar / bsdtar, or set " +
|
|
88
|
+
"GO_ARCH_XRAY_BIN to an existing binary path."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function extract(archivePath, destDir) {
|
|
94
|
+
ensureTar();
|
|
95
|
+
// Modern bsdtar (Windows 10 1803+, macOS, Linux) handles both .tar.gz and .zip via -xf.
|
|
96
|
+
const result = spawnSync("tar", ["-xf", archivePath, "-C", destDir], {
|
|
97
|
+
stdio: "inherit",
|
|
98
|
+
});
|
|
99
|
+
if (result.status !== 0) {
|
|
100
|
+
fail(`tar extraction failed (exit ${result.status})`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function main() {
|
|
105
|
+
if (process.env.GO_ARCH_XRAY_BIN) {
|
|
106
|
+
log(`GO_ARCH_XRAY_BIN is set; skipping download.`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const target = detectTarget();
|
|
111
|
+
const { binDir, binPath } = binaryPath(target);
|
|
112
|
+
|
|
113
|
+
if (fs.existsSync(binPath)) {
|
|
114
|
+
log(`binary already present at ${binPath}; skipping download.`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
119
|
+
|
|
120
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "go-arch-xray-"));
|
|
121
|
+
const archivePath = path.join(tmpDir, archiveAssetName(target));
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await download(assetUrl(target), archivePath);
|
|
125
|
+
extract(archivePath, tmpDir);
|
|
126
|
+
|
|
127
|
+
const extractedName = archiveInternalName(target);
|
|
128
|
+
const extractedPath = path.join(tmpDir, extractedName);
|
|
129
|
+
if (!fs.existsSync(extractedPath)) {
|
|
130
|
+
fail(
|
|
131
|
+
`expected '${extractedName}' inside archive but it was not found. ` +
|
|
132
|
+
`Open an issue: https://github.com/${REPO}/issues`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fs.renameSync(extractedPath, binPath);
|
|
137
|
+
if (process.platform !== "win32") {
|
|
138
|
+
fs.chmodSync(binPath, 0o755);
|
|
139
|
+
}
|
|
140
|
+
log(`installed ${binPath}`);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
fail(
|
|
143
|
+
`failed to install binary: ${err && err.message ? err.message : err}\n` +
|
|
144
|
+
`URL: ${assetUrl(target)}\n` +
|
|
145
|
+
`You can download the asset manually, extract it, and either drop the binary at\n` +
|
|
146
|
+
` ${binPath}\n` +
|
|
147
|
+
`or set GO_ARCH_XRAY_BIN to its absolute path.`
|
|
148
|
+
);
|
|
149
|
+
} finally {
|
|
150
|
+
try {
|
|
151
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
152
|
+
} catch {
|
|
153
|
+
/* best effort */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
main().catch((err) => fail(err && err.stack ? err.stack : String(err)));
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hayasaka7/go-arch-xray",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Model Context Protocol server for static analysis of Go codebases (call graphs, import graphs, interface topology, struct lifecycle, HTTP routes).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"golang",
|
|
9
|
+
"go",
|
|
10
|
+
"static-analysis",
|
|
11
|
+
"call-graph",
|
|
12
|
+
"ssa",
|
|
13
|
+
"architecture"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/HAYASAKA7/go-arch-xray#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/HAYASAKA7/go-arch-xray/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/HAYASAKA7/go-arch-xray.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "HAYASAKA7",
|
|
25
|
+
"bin": {
|
|
26
|
+
"go-arch-xray": "bin/go-arch-xray.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"install.js",
|
|
30
|
+
"bin/",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"postinstall": "node install.js"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"darwin",
|
|
42
|
+
"linux",
|
|
43
|
+
"win32"
|
|
44
|
+
],
|
|
45
|
+
"cpu": [
|
|
46
|
+
"x64",
|
|
47
|
+
"arm64"
|
|
48
|
+
]
|
|
49
|
+
}
|