* Register a single tool as a subcommand.
( yargs: Argv, tool: ToolDefinition, invoker: DefaultToolInvoker, opts: RegisterToolCommandsOptions, cliExposedWorkflowIds: string[], )
| 197 | * Register a single tool as a subcommand. |
| 198 | */ |
| 199 | function registerToolSubcommand( |
| 200 | yargs: Argv, |
| 201 | tool: ToolDefinition, |
| 202 | invoker: DefaultToolInvoker, |
| 203 | opts: RegisterToolCommandsOptions, |
| 204 | cliExposedWorkflowIds: string[], |
| 205 | ): void { |
| 206 | const builderProfileOverride = readProfileOverrideFromProcessArgv(); |
| 207 | const hydratedDefaults = getCliSessionDefaultsForTool({ |
| 208 | tool, |
| 209 | runtimeConfig: opts.runtimeConfig, |
| 210 | profileOverride: builderProfileOverride, |
| 211 | }); |
| 212 | const yargsOptions = schemaToYargsOptions(tool.cliSchema, { |
| 213 | hydratedDefaults, |
| 214 | }); |
| 215 | const unsupportedKeys = getUnsupportedSchemaKeys(tool.cliSchema); |
| 216 | |
| 217 | const commandName = tool.cliName; |
| 218 | const requiredFlagNames = [...yargsOptions.entries()] |
| 219 | .filter(([, config]) => Boolean(config.demandOption)) |
| 220 | .map(([flagName]) => flagName); |
| 221 | |
| 222 | yargs.command( |
| 223 | commandName, |
| 224 | tool.description ?? `Run the ${tool.mcpName} tool`, |
| 225 | (subYargs) => { |
| 226 | // Hide root-level options from tool help |
| 227 | subYargs |
| 228 | .option('log-level', { hidden: true }) |
| 229 | .option('style', { hidden: true }) |
| 230 | .option('file-path-render-style', { hidden: true }); |
| 231 | |
| 232 | // Parse option-like values as arguments (e.g. --extra-args "-only-testing:...") |
| 233 | subYargs.parserConfiguration({ |
| 234 | 'unknown-options-as-args': true, |
| 235 | }); |
| 236 | |
| 237 | // Register schema-derived options (tool arguments) |
| 238 | const toolArgNames: string[] = []; |
| 239 | for (const [flagName, config] of yargsOptions) { |
| 240 | subYargs.option(flagName, { ...config, demandOption: false }); |
| 241 | toolArgNames.push(flagName); |
| 242 | } |
| 243 | |
| 244 | // Add --profile option for per-invocation defaults override |
| 245 | subYargs.option('profile', { |
| 246 | type: 'string', |
| 247 | describe: 'Override the defaults profile for this command only', |
| 248 | }); |
| 249 | |
| 250 | // Add --json option for complex args or full override |
| 251 | subYargs.option('json', { |
| 252 | type: 'string', |
| 253 | describe: 'JSON object of tool args (merged with flags)', |
| 254 | }); |
| 255 | |
| 256 | // Add --output option for format control |
no test coverage detected