@@ -152,11 +152,52 @@ export class McpEventHandler {
152
152
* Handles the add new MCP server action
153
153
*/
154
154
async #handleAddNewMcp( params : McpServerClickParams ) {
155
+ const existingValues = params . optionsValues || { }
156
+ let argsValue = [
157
+ {
158
+ persistent : true ,
159
+ value : { arg_key : '' } ,
160
+ } ,
161
+ ]
162
+ if ( existingValues . args && Array . isArray ( existingValues . args ) ) {
163
+ argsValue = existingValues . args . map ( ( arg , index ) => ( {
164
+ persistent : index === 0 ,
165
+ value : {
166
+ arg_key : arg . arg_key || '' ,
167
+ } ,
168
+ } ) )
169
+ }
170
+
171
+ let envVarsValue = [
172
+ {
173
+ persistent : true ,
174
+ value : {
175
+ env_var_name : '' ,
176
+ env_var_value : '' ,
177
+ } ,
178
+ } ,
179
+ ]
180
+ if ( existingValues . env_variables && Array . isArray ( existingValues . env_variables ) ) {
181
+ envVarsValue = existingValues . env_variables . map ( ( env , index ) => ( {
182
+ persistent : index === 0 ,
183
+ value : {
184
+ env_var_name : env . env_var_name || '' ,
185
+ env_var_value : env . env_var_value || '' ,
186
+ } ,
187
+ } ) )
188
+ }
189
+
155
190
return {
156
191
id : params . id ,
157
192
header : {
158
193
title : 'Add MCP Server' ,
159
- status : { } ,
194
+ status : existingValues . errorTitle
195
+ ? {
196
+ title : existingValues . errorTitle ,
197
+ icon : 'cancel-circle' ,
198
+ status : 'error' ,
199
+ }
200
+ : { } ,
160
201
actions : [ ] ,
161
202
} ,
162
203
list : [ ] ,
@@ -186,11 +227,13 @@ export class McpEventHandler {
186
227
value : 'workspace' ,
187
228
} ,
188
229
] ,
230
+ value : existingValues . scope || 'global' ,
189
231
} ,
190
232
{
191
233
type : 'textinput' ,
192
234
id : 'name' ,
193
235
title : 'Name' ,
236
+ value : existingValues . name || '' ,
194
237
mandatory : true ,
195
238
} ,
196
239
{
@@ -209,6 +252,7 @@ export class McpEventHandler {
209
252
type : 'textinput' ,
210
253
id : 'command' ,
211
254
title : 'Command' ,
255
+ value : existingValues . command || '' ,
212
256
mandatory : true ,
213
257
} ,
214
258
{
@@ -222,14 +266,7 @@ export class McpEventHandler {
222
266
type : 'textinput' ,
223
267
} ,
224
268
] ,
225
- value : [
226
- {
227
- persistent : true ,
228
- value : {
229
- arg_key : '' ,
230
- } ,
231
- } ,
232
- ] ,
269
+ value : argsValue ,
233
270
} ,
234
271
{
235
272
type : 'list' ,
@@ -248,14 +285,14 @@ export class McpEventHandler {
248
285
type : 'textinput' ,
249
286
} ,
250
287
] ,
251
- value : [ ] ,
288
+ value : envVarsValue ,
252
289
} ,
253
290
{
254
291
type : 'numericinput' ,
255
292
id : 'timeout' ,
256
293
title : 'Timeout' ,
257
294
description : 'Seconds' ,
258
- value : '60' , // Default value
295
+ value : existingValues . timeout || '60' , // Default value
259
296
mandatory : false ,
260
297
} ,
261
298
] ,
@@ -270,6 +307,19 @@ export class McpEventHandler {
270
307
return this . #getDefaultMcpResponse( params . id )
271
308
}
272
309
310
+ const requiredFields = [ 'name' , 'command' , 'timeout' ]
311
+ const missingFields = requiredFields . filter (
312
+ field => ! params . optionsValues ?. [ field ] || params . optionsValues [ field ] . trim ( ) === ''
313
+ )
314
+ if ( missingFields . length > 0 ) {
315
+ const formattedFields = missingFields . map ( f => f . charAt ( 0 ) . toUpperCase ( ) + f . slice ( 1 ) ) . join ( ', ' )
316
+ // adds errorTitle mapping to optionsValues which is not normally there. chose this option over adding new parameter to #handleAddNewMcp
317
+ params . optionsValues [ 'errorTitle' ] = `Required Fields: ${ formattedFields } `
318
+ // goes back to add-new-mcp page but will now show an error card
319
+ params . id = 'add-new-mcp'
320
+ return this . #handleAddNewMcp( params )
321
+ }
322
+
273
323
// Process args to string[]
274
324
let args : string [ ] = [ ]
275
325
const argsValue = params . optionsValues . args
@@ -325,7 +375,7 @@ export class McpEventHandler {
325
375
// TODO: According to workspace specific scope and persona and pass configPath to addServer
326
376
await McpManager . instance . addServer ( serverName , config , configPath , personaPath )
327
377
328
- return this . #getDefaultMcpResponse ( params . id )
378
+ return this . #handleOpenMcpServer ( { id : 'open-mcp-server' , title : serverName } )
329
379
}
330
380
331
381
/**
0 commit comments