11import { Command } from "commander" ;
2- import { readSecretFromFile } from "../acp/secret-file.js" ;
32import { parseConfigValue } from "../auto-reply/reply/config-value.js" ;
43import {
54 listConfiguredMcpServers ,
@@ -8,9 +7,11 @@ import {
87} from "../config/mcp-config.js" ;
98import { serveOpenClawChannelMcp } from "../mcp/channel-server.js" ;
109import { defaultRuntime } from "../runtime.js" ;
11- import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js" ;
12- import { normalizeOptionalString } from "../shared/string-coerce.js" ;
13- import { normalizeStringifiedOptionalString } from "../shared/string-coerce.js" ;
10+ import {
11+ normalizeLowercaseStringOrEmpty ,
12+ normalizeStringifiedOptionalString ,
13+ } from "../shared/string-coerce.js" ;
14+ import { resolveGatewayAuthOptions } from "./gateway-secret-options.js" ;
1415
1516function fail ( message : string ) : never {
1617 defaultRuntime . error ( message ) ;
@@ -22,30 +23,6 @@ function printJson(value: unknown): void {
2223 defaultRuntime . writeJson ( value ) ;
2324}
2425
25- function resolveSecretOption ( params : {
26- direct ?: string ;
27- file ?: string ;
28- directFlag : string ;
29- fileFlag : string ;
30- label : string ;
31- } ) {
32- const direct = normalizeOptionalString ( params . direct ) ;
33- const file = normalizeOptionalString ( params . file ) ;
34- if ( direct && file ) {
35- throw new Error ( `Use either ${ params . directFlag } or ${ params . fileFlag } for ${ params . label } .` ) ;
36- }
37- if ( file ) {
38- return readSecretFromFile ( file , params . label ) ;
39- }
40- return direct || undefined ;
41- }
42-
43- function warnSecretCliFlag ( flag : "--token" | "--password" ) {
44- defaultRuntime . error (
45- `Warning: ${ flag } can be exposed via process listings. Prefer ${ flag } -file or environment variables.` ,
46- ) ;
47- }
48-
4926export function registerMcpCli ( program : Command ) {
5027 const mcp = program . command ( "mcp" ) . description ( "Manage OpenClaw MCP config and channel bridge" ) ;
5128
@@ -65,26 +42,7 @@ export function registerMcpCli(program: Command) {
6542 . option ( "-v, --verbose" , "Verbose logging to stderr" , false )
6643 . action ( async ( opts ) => {
6744 try {
68- const gatewayToken = resolveSecretOption ( {
69- direct : opts . token as string | undefined ,
70- file : opts . tokenFile as string | undefined ,
71- directFlag : "--token" ,
72- fileFlag : "--token-file" ,
73- label : "Gateway token" ,
74- } ) ;
75- const gatewayPassword = resolveSecretOption ( {
76- direct : opts . password as string | undefined ,
77- file : opts . passwordFile as string | undefined ,
78- directFlag : "--password" ,
79- fileFlag : "--password-file" ,
80- label : "Gateway password" ,
81- } ) ;
82- if ( opts . token ) {
83- warnSecretCliFlag ( "--token" ) ;
84- }
85- if ( opts . password ) {
86- warnSecretCliFlag ( "--password" ) ;
87- }
45+ const { gatewayToken, gatewayPassword } = resolveGatewayAuthOptions ( opts ) ;
8846 const claudeChannelMode = normalizeLowercaseStringOrEmpty (
8947 normalizeStringifiedOptionalString ( opts . claudeChannelMode ) ?? "auto" ,
9048 ) ;
0 commit comments