@@ -445,3 +445,56 @@ export function formatServerConfig(
445445 args : npxArgs ,
446446 }
447447}
448+
449+ /**
450+ * Formats and validates configuration values for the run command.
451+ * This is a special case that allows empty strings for required fields.
452+ *
453+ * @param connection - Server connection details containing the config schema
454+ * @param configValues - Optional existing configuration values to format
455+ * @returns Formatted configuration values with proper types according to schema
456+ */
457+ export async function formatRunConfigValues (
458+ connection : ConnectionDetails ,
459+ configValues ?: ServerConfig ,
460+ ) : Promise < ServerConfig > {
461+ const formattedValues : ServerConfig = { }
462+
463+ if ( ! connection . configSchema ?. properties ) {
464+ return configValues || { }
465+ }
466+
467+ const required = new Set < string > ( connection . configSchema . required || [ ] )
468+
469+ // First pass: collect all values and track missing required fields
470+ for ( const [ key , prop ] of Object . entries (
471+ connection . configSchema . properties ,
472+ ) ) {
473+ const schemaProp = prop as { type ?: string ; default ?: unknown }
474+ const value = configValues ?. [ key ]
475+
476+ try {
477+ let finalValue : unknown
478+ if ( value !== undefined ) {
479+ finalValue = value
480+ } else if ( ! required . has ( key ) ) {
481+ finalValue = schemaProp . default
482+ } else {
483+ finalValue = "" // Use empty string for required fields that are missing
484+ }
485+
486+ if ( finalValue === undefined ) {
487+ // Use empty string for optional values without defaults
488+ formattedValues [ key ] = ""
489+ continue
490+ }
491+
492+ formattedValues [ key ] = convertValueToType ( finalValue , schemaProp . type )
493+ } catch ( error ) {
494+ // For any errors, use empty string for required fields and null for optional ones
495+ formattedValues [ key ] = required . has ( key ) ? "" : null
496+ }
497+ }
498+
499+ return formattedValues
500+ }
0 commit comments