openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.62 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{o as getAsyncWorkSignal}from"./async-work-scope-DBcxYU4O.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./concurrency-runtime-A2TPGCdf.mjs";import"./runtime-env-Qb8DG6sI.mjs";
//!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`);const a=e===`status`||e===`grants`?getAsyncWorkSignal():void 0;try{const i=await r(`mcp-relay.${e}`,t,n,{progress:!t.json,scopes:[e===`status`?`operator.read`:`operator.admin`],...a?{signal:a}:{}});a?.throwIfAborted();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){a?.throwIfAborted();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}))}export{registerMcpRelayCli};