| 74 | } |
| 75 | |
| 76 | function parseRunner(args: string[]): "npx" | "bunx" { |
| 77 | const explicit = args.find((arg) => arg.startsWith("--runner=")); |
| 78 | if (explicit) { |
| 79 | const value = explicit.split("=")[1]; |
| 80 | if (value === "npx" || value === "bunx") return value; |
| 81 | throw new Error(`Unsupported runner \"${value}\". Use --runner=npx or --runner=bunx.`); |
| 82 | } |
| 83 | const runnerFlagIndex = args.findIndex((arg) => arg === "--runner"); |
| 84 | if (runnerFlagIndex >= 0) { |
| 85 | const value = args[runnerFlagIndex + 1]; |
| 86 | if (value === "npx" || value === "bunx") return value; |
| 87 | throw new Error(`Unsupported runner \"${value}\". Use --runner=npx or --runner=bunx.`); |
| 88 | } |
| 89 | const userAgent = (process.env.npm_config_user_agent ?? "").toLowerCase(); |
| 90 | const execPath = (process.env.npm_execpath ?? "").toLowerCase(); |
| 91 | if (userAgent.includes("bun/") || execPath.includes("bun")) return "bunx"; |
| 92 | return "npx"; |
| 93 | } |
| 94 | |
| 95 | function buildMcpConfig(runner: "npx" | "bunx") { |
| 96 | const commandArgs = runner === "npx" ? ["-y", "contextplus"] : ["contextplus"]; |