diff --git a/packages/opsxdb-mcp/dist/resolve-binary.js b/packages/opsxdb-mcp/dist/resolve-binary.js new file mode 100644 index 0000000..92ebc42 --- /dev/null +++ b/packages/opsxdb-mcp/dist/resolve-binary.js @@ -0,0 +1,92 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const os = require('os'); + +/** + * Resolve the OpsxDB Go MCP binary path. + * Order: OPSXDB_MCP_BIN → PATH → common install locations. + * @returns {string|null} + */ +function resolveBinary() { + const envBin = process.env.OPSXDB_MCP_BIN; + if (envBin && isExecutable(envBin)) return path.resolve(envBin); + + const onPath = findOnPath('opsxdb-mcp'); + if (onPath) return onPath; + + const home = os.homedir(); + const candidates = [ + path.join(home, 'devops', 'opsxdb', 'bin', 'opsxdb-mcp'), + path.join(home, '.opsxdb', 'bin', 'opsxdb-mcp'), + path.join(home, '.local', 'bin', 'opsxdb-mcp'), + '/usr/local/bin/opsxdb-mcp', + '/opt/homebrew/bin/opsxdb-mcp', + ]; + for (const c of candidates) { + if (isExecutable(c)) return c; + } + return null; +} + +function findOnPath(name) { + const pathEnv = process.env.PATH || ''; + for (const dir of pathEnv.split(path.delimiter)) { + if (!dir) continue; + const p = path.join(dir, name); + if (isExecutable(p)) return p; + if (process.platform === 'win32' && isExecutable(p + '.exe')) return p + '.exe'; + } + return null; +} + +function isExecutable(filePath) { + try { + const st = fs.statSync(filePath); + if (!st.isFile()) return false; + fs.accessSync(filePath, fs.constants.X_OK); + return true; + } catch { + return false; + } +} + +function missingBinaryMessage() { + return `opsxdb-mcp: Go binary not found. + +This npm package (@rlwj-lab/opsxdb-mcp) is a Node launcher for the OpsxDB +MCP server (stdio). The real server is a Go binary named opsxdb-mcp. + +Build it from the opsxdb repo: + + cd server && go build -o ../bin/opsxdb-mcp ./cmd/opsxdb-mcp + +Then either: + - put bin/opsxdb-mcp on your PATH, or + - export OPSXDB_MCP_BIN=/absolute/path/to/opsxdb-mcp + +Cursor / Claude Desktop example: + + { + "mcpServers": { + "opsxdb": { + "command": "npx", + "args": ["-y", "@rlwj-lab/opsxdb-mcp"], + "env": { + "OPSXDB_MCP_BIN": "/absolute/path/to/opsxdb-mcp" + } + } + } + } + +Config files (same as native binary): + ~/.opsxdb/mcp.json + ~/.opsxdb/connections.json +`; +} + +module.exports = { + resolveBinary, + missingBinaryMessage, +};