Skip to content

Commit 11fa3d8

Browse files
authored
fix: success and error case for adding mcp server (#1412)
1 parent 73b8025 commit 11fa3d8

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ ${params.message}`,
13461346
header: {
13471347
title: params.header?.title || 'Add MCP Server',
13481348
description: params.header?.description || '',
1349+
status: params.header?.status || {},
13491350
},
13501351
filterOptions: processFilterOptions(params.filterOptions),
13511352
filterActions: params.filterActions,
@@ -1440,7 +1441,6 @@ ${params.message}`,
14401441
setTimeout(() => {
14411442
mynahUi.toggleSplashLoader(false)
14421443
}, 10000)
1443-
messager.onMcpServerClick('open-mcp-server', filterValues?.['name'])
14441444
}
14451445
},
14461446
}

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpEventHandler.ts

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,52 @@ export class McpEventHandler {
152152
* Handles the add new MCP server action
153153
*/
154154
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+
155190
return {
156191
id: params.id,
157192
header: {
158193
title: 'Add MCP Server',
159-
status: {},
194+
status: existingValues.errorTitle
195+
? {
196+
title: existingValues.errorTitle,
197+
icon: 'cancel-circle',
198+
status: 'error',
199+
}
200+
: {},
160201
actions: [],
161202
},
162203
list: [],
@@ -186,11 +227,13 @@ export class McpEventHandler {
186227
value: 'workspace',
187228
},
188229
],
230+
value: existingValues.scope || 'global',
189231
},
190232
{
191233
type: 'textinput',
192234
id: 'name',
193235
title: 'Name',
236+
value: existingValues.name || '',
194237
mandatory: true,
195238
},
196239
{
@@ -209,6 +252,7 @@ export class McpEventHandler {
209252
type: 'textinput',
210253
id: 'command',
211254
title: 'Command',
255+
value: existingValues.command || '',
212256
mandatory: true,
213257
},
214258
{
@@ -222,14 +266,7 @@ export class McpEventHandler {
222266
type: 'textinput',
223267
},
224268
],
225-
value: [
226-
{
227-
persistent: true,
228-
value: {
229-
arg_key: '',
230-
},
231-
},
232-
],
269+
value: argsValue,
233270
},
234271
{
235272
type: 'list',
@@ -248,14 +285,14 @@ export class McpEventHandler {
248285
type: 'textinput',
249286
},
250287
],
251-
value: [],
288+
value: envVarsValue,
252289
},
253290
{
254291
type: 'numericinput',
255292
id: 'timeout',
256293
title: 'Timeout',
257294
description: 'Seconds',
258-
value: '60', // Default value
295+
value: existingValues.timeout || '60', // Default value
259296
mandatory: false,
260297
},
261298
],
@@ -270,6 +307,19 @@ export class McpEventHandler {
270307
return this.#getDefaultMcpResponse(params.id)
271308
}
272309

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+
273323
// Process args to string[]
274324
let args: string[] = []
275325
const argsValue = params.optionsValues.args
@@ -325,7 +375,7 @@ export class McpEventHandler {
325375
// TODO: According to workspace specific scope and persona and pass configPath to addServer
326376
await McpManager.instance.addServer(serverName, config, configPath, personaPath)
327377

328-
return this.#getDefaultMcpResponse(params.id)
378+
return this.#handleOpenMcpServer({ id: 'open-mcp-server', title: serverName })
329379
}
330380

331381
/**

0 commit comments

Comments
 (0)