@@ -552,26 +552,17 @@ export class McpEventHandler {
552552 }
553553
554554 const transport = values . transport
555- const usingStdio = ! ! values . command ?. trim ( )
556- const usingHttp = ! ! values . url ?. trim ( )
555+ const command = values . command ?. trim ( ) || ''
556+ const url = values . url ?. trim ( ) || ''
557557
558- if ( transport ) {
559- if ( transport === 'stdio' ) {
560- if ( ! usingStdio ) {
561- errors . push ( 'Command is required for stdio transport' )
562- }
563- } else {
564- if ( ! usingHttp ) {
565- errors . push ( `URL is required for ${ transport } transport` )
566- }
567- }
568- }
569-
570- // Validate mutual exclusivity and presence of either
571- if ( usingStdio && usingHttp ) {
572- errors . push ( 'Provide either command OR url, not both' )
573- } else if ( ! usingStdio && ! usingHttp ) {
558+ if ( ! command && ! url ) {
574559 errors . push ( 'Either command or url is required' )
560+ } else if ( command && url ) {
561+ errors . push ( 'Provide either command OR url, not both' )
562+ } else if ( transport === 'stdio' && ! command ) {
563+ errors . push ( 'Command is required for stdio transport' )
564+ } else if ( transport !== 'stdio' && ! url ) {
565+ errors . push ( `URL is required for ${ transport } transport` )
575566 }
576567
577568 if ( values . timeout && values . timeout . trim ( ) !== '' ) {
@@ -606,17 +597,19 @@ export class McpEventHandler {
606597
607598 if ( Array . isArray ( values . headers ) ) {
608599 const hdrs = values . headers as Array < { key : string ; value : string } >
609- const emptyKeyWithValue = hdrs . some (
610- h => ( ! h . key || h . key . trim ( ) === '' ) && h . value && h . value . trim ( ) !== ''
611- )
612- const keyWithEmptyValue = hdrs . some (
613- h => h . key && h . key . trim ( ) !== '' && ( ! h . value || h . value . trim ( ) === '' )
614- )
615- if ( emptyKeyWithValue ) {
616- errors . push ( 'Header key cannot be empty when value is provided' )
617- }
618- if ( keyWithEmptyValue ) {
619- errors . push ( 'Header value cannot be empty when key is provided' )
600+ const invalidHeaders = hdrs . find ( h => {
601+ const key = h . key ?. trim ( ) || ''
602+ const value = h . value ?. trim ( ) || ''
603+ return ( key === '' && value !== '' ) || ( key !== '' && value === '' )
604+ } )
605+
606+ if ( invalidHeaders ) {
607+ const hasKey = invalidHeaders . key ?. trim ( )
608+ errors . push (
609+ hasKey
610+ ? 'Header value cannot be empty when key is provided'
611+ : 'Header key cannot be empty when value is provided'
612+ )
620613 }
621614 }
622615
@@ -665,7 +658,7 @@ export class McpEventHandler {
665658 )
666659 . filter ( Boolean )
667660 } catch ( e ) {
668- this . #features. logging . warn ( `Failed to process args: ${ e } ` )
661+ this . #features. logging . warn ( `MCP: Failed to process args: ${ e } ` )
669662 }
670663
671664 try {
@@ -678,7 +671,7 @@ export class McpEventHandler {
678671 return acc
679672 } , { } )
680673 } catch ( e ) {
681- this . #features. logging . warn ( `Failed to process env variables: ${ e } ` )
674+ this . #features. logging . warn ( `MCP: Failed to process env variables: ${ e } ` )
682675 }
683676 }
684677
@@ -699,7 +692,7 @@ export class McpEventHandler {
699692 return acc
700693 } , { } )
701694 } catch ( e ) {
702- this . #features. logging . warn ( `Failed to process headers: ${ e } ` )
695+ this . #features. logging . warn ( `MCP: Failed to process headers: ${ e } ` )
703696 }
704697 }
705698
@@ -1072,29 +1065,26 @@ export class McpEventHandler {
10721065 }
10731066
10741067 async #handleChangeTransport( params : McpServerClickParams ) {
1068+ const { optionsValues, title } = params
10751069 const editingServerName = this . #currentEditingServerName
10761070
1077- if ( params . optionsValues ) {
1078- const transport = params . optionsValues . transport ?? 'stdio'
1079- if ( transport === 'http' ) {
1080- delete params . optionsValues . command
1081- delete params . optionsValues . args
1082- delete params . optionsValues . env_variables
1083- } else {
1084- delete params . optionsValues . url
1085- delete params . optionsValues . headers
1086- }
1071+ // Clean up transport-specific fields
1072+ if ( optionsValues ) {
1073+ const transport = optionsValues . transport ?? 'stdio' // Maintain default to 'stdio'
1074+ const fieldsToDelete = transport === 'http' ? [ 'command' , 'args' , 'env_variables' ] : [ 'url' , 'headers' ]
1075+
1076+ fieldsToDelete . forEach ( field => delete optionsValues [ field ] )
10871077 }
10881078
1089- // Handle server name change if in edit mode
1090- if ( editingServerName && params . title && editingServerName !== params . title ) {
1079+ // Handle server name change in edit mode
1080+ if ( editingServerName && title && editingServerName !== title ) {
10911081 const servers = McpManager . instance . getAllServerConfigs ( )
10921082 const existingConfig = servers . get ( editingServerName )
10931083
10941084 if ( existingConfig ) {
10951085 const updatedServers = new Map ( servers )
10961086 updatedServers . delete ( editingServerName )
1097- updatedServers . set ( params . title , existingConfig )
1087+ updatedServers . set ( title , existingConfig )
10981088 await McpManager . instance . updateServerMap ( updatedServers )
10991089 }
11001090 this . #serverNameBeforeUpdate = editingServerName
0 commit comments