From d4a2412c49b47ba9dda210650379d613b8ac85f4 Mon Sep 17 00:00:00 2001 From: Aidan Daly Date: Tue, 3 Mar 2026 15:00:26 -0500 Subject: [PATCH] fix: wire gateway-target CLI flags and default source to existing-endpoint - Pass source/type/endpoint options through command.tsx to handler (were silently dropped, breaking --source existing-endpoint) - Default source to 'existing-endpoint' in validation (only supported path) - Reject 'create-new' source with clear error message - Move outbound auth validation before source branching so it applies to existing-endpoint targets (was unreachable due to early return) --- src/cli/commands/add/command.tsx | 3 ++ src/cli/commands/add/validate.ts | 69 +++++++++++++++++--------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/cli/commands/add/command.tsx b/src/cli/commands/add/command.tsx index 22e89dc5..8afd3982 100644 --- a/src/cli/commands/add/command.tsx +++ b/src/cli/commands/add/command.tsx @@ -120,6 +120,9 @@ async function handleAddGatewayTargetCLI(options: AddGatewayTargetOptions): Prom const result = await handleAddGatewayTarget({ name: options.name!, description: options.description, + type: options.type, + source: options.source as 'existing-endpoint' | 'create-new' | undefined, + endpoint: options.endpoint, language: options.language! as 'Python' | 'TypeScript', gateway: options.gateway, host: options.host, diff --git a/src/cli/commands/add/validate.ts b/src/cli/commands/add/validate.ts index 0aac0a21..3f88c6c8 100644 --- a/src/cli/commands/add/validate.ts +++ b/src/cli/commands/add/validate.ts @@ -205,8 +205,8 @@ export async function validateAddGatewayTargetOptions(options: AddGatewayTargetO return { valid: false, error: 'Invalid type. Valid options: mcpServer, lambda' }; } - if (options.source && options.source !== 'existing-endpoint' && options.source !== 'create-new') { - return { valid: false, error: 'Invalid source. Valid options: existing-endpoint, create-new' }; + if (options.source && options.source !== 'existing-endpoint') { + return { valid: false, error: "Only 'existing-endpoint' source is currently supported" }; } // Gateway is required — a gateway target must be attached to a gateway @@ -233,38 +233,10 @@ export async function validateAddGatewayTargetOptions(options: AddGatewayTargetO }; } - if (options.source === 'existing-endpoint') { - if (options.host) { - return { valid: false, error: '--host is not applicable for existing endpoint targets' }; - } - if (!options.endpoint) { - return { valid: false, error: '--endpoint is required when source is existing-endpoint' }; - } - - try { - const url = new URL(options.endpoint); - if (url.protocol !== 'http:' && url.protocol !== 'https:') { - return { valid: false, error: 'Endpoint must use http:// or https:// protocol' }; - } - } catch { - return { valid: false, error: 'Endpoint must be a valid URL (e.g. https://example.com/mcp)' }; - } + // Default to existing-endpoint (only supported source for now) + options.source ??= 'existing-endpoint'; - // Populate defaults for fields skipped by external endpoint flow - options.language ??= 'Other'; - - return { valid: true }; - } - - if (!options.language) { - return { valid: false, error: '--language is required' }; - } - - if (options.language !== 'Python' && options.language !== 'TypeScript' && options.language !== 'Other') { - return { valid: false, error: 'Invalid language. Valid options: Python, TypeScript, Other' }; - } - - // Validate outbound auth configuration + // Validate outbound auth configuration (applies to all source types) if (options.outboundAuthType && options.outboundAuthType !== 'NONE') { const hasInlineOAuth = !!(options.oauthClientId ?? options.oauthClientSecret ?? options.oauthDiscoveryUrl); @@ -310,6 +282,37 @@ export async function validateAddGatewayTargetOptions(options: AddGatewayTargetO } } + if (options.source === 'existing-endpoint') { + if (options.host) { + return { valid: false, error: '--host is not applicable for existing endpoint targets' }; + } + if (!options.endpoint) { + return { valid: false, error: '--endpoint is required when source is existing-endpoint' }; + } + + try { + const url = new URL(options.endpoint); + if (url.protocol !== 'http:' && url.protocol !== 'https:') { + return { valid: false, error: 'Endpoint must use http:// or https:// protocol' }; + } + } catch { + return { valid: false, error: 'Endpoint must be a valid URL (e.g. https://example.com/mcp)' }; + } + + // Populate defaults for fields skipped by external endpoint flow + options.language ??= 'Other'; + + return { valid: true }; + } + + if (!options.language) { + return { valid: false, error: '--language is required' }; + } + + if (options.language !== 'Python' && options.language !== 'TypeScript' && options.language !== 'Other') { + return { valid: false, error: 'Invalid language. Valid options: Python, TypeScript, Other' }; + } + return { valid: true }; }