openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
48 lines (47 loc) • 2.67 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as defaultRuntime } from "./runtime-B-SLYP-m.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./runtime-env-D-Pa5lD6.mjs";
//#region extensions/mcp-relay/src/cli.ts
function createRelayCommandFailure(e, t) {
const n = t(e instanceof Error ? e.message : String(e));
return /* @__PURE__ */ new Error(`${n}\nCheck that the Gateway is running and mcp-relay is enabled with openclaw plugins enable mcp-relay, then retry.`);
}
async function runCommand(e, t, n) {
const { callGatewayFromCli: r, redactSensitiveUrlLikeString: i } = await import("./plugin-sdk/gateway-runtime.js");
try {
const i = await r(`mcp-relay.${e}`, t, n, {
progress: !t.json,
scopes: [e === "status" ? "operator.read" : "operator.admin"]
});
if (t.json) {
defaultRuntime.writeJson(i);
return;
}
if (e === "pair" && typeof i.code === "string" && typeof i.mcpUrl === "string") {
defaultRuntime.log(`Pairing code: ${i.code}`);
if (typeof i.expiresAt === "number") defaultRuntime.log(`Expires: ${new Date(i.expiresAt).toISOString()}`);
defaultRuntime.log(`MCP URL: ${i.mcpUrl}`);
defaultRuntime.log("In ChatGPT, open Plugins and add this MCP URL; in Claude, add a custom connector. Enter this code on the OpenClaw consent page.");
return;
}
if (e === "status" && isRecord(i.ui)) defaultRuntime.log(i.ui.available === true ? `Control UI: available (${typeof i.ui.basePath === "string" ? i.ui.basePath : "/"})` : `Control UI: unavailable${typeof i.ui.reason === "string" ? ` — ${i.ui.reason}` : ""}`);
defaultRuntime.writeJson(i);
} catch (e) {
const n = createRelayCommandFailure(e, i);
if (t.json) throw n;
defaultRuntime.error(n.message);
defaultRuntime.exit(1);
}
}
async function registerMcpRelayCli({ program: e }) {
const { addGatewayClientOptions: t } = await import("./plugin-sdk/gateway-runtime.js");
const n = e.command("mcp-relay").description("Inspect the MCP relay connection and manage client grants");
const command = (e, r) => t(n.command(e).description(r)).option("--json", "Emit JSON", false);
command("status", "Show the running Gateway's relay connection and grant count").action((e) => runCommand("status", e, {}));
command("pair", "Issue a single-use pairing code for a remote MCP client").action((e) => runCommand("pair", e, {}));
command("grants", "List the running Gateway's MCP client grants").action((e) => runCommand("grants", e, {}));
command("revoke <grantId>", "Revoke a client grant locally and notify the relay").action((e, t) => runCommand("revoke", t, { grantId: e }));
}
//#endregion
export { registerMcpRelayCli };