Skip to content

Commit 6d506dd

Browse files
committed
fix: refresh mcp server functionality
1 parent 3345baa commit 6d506dd

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,27 @@ export class AgenticChatController implements ChatHandlers {
415415
}
416416
}
417417
async onMcpServerClick(params: McpServerClickParams) {
418-
return {
419-
id: params.id,
420-
success: true,
418+
switch (params.id) {
419+
case 'refresh-mcp-list':
420+
try {
421+
await McpManager.instance.reinitializeMcpServers()
422+
return {
423+
id: params.id,
424+
success: true,
425+
}
426+
} catch (err) {
427+
this.#features.logging.error(`Failed to reinitialize MCP servers: ${err}`)
428+
return {
429+
id: params.id,
430+
success: false,
431+
error: err instanceof Error ? err.message : 'Unknown error when reinitializing MCP server',
432+
}
433+
}
434+
default:
435+
return {
436+
id: params.id,
437+
success: true,
438+
}
421439
}
422440
}
423441

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ export class McpManager {
412412
McpManager.#instance = undefined
413413
}
414414

415+
/**
416+
* Reinitialize all MCP servers by closing existing connections and rediscovering servers
417+
*/
418+
public async reinitializeMcpServers(): Promise<void> {
419+
this.features.logging.info('Reinitializing MCP servers')
420+
421+
try {
422+
// Close all existing connections
423+
await this.close()
424+
425+
// Reinitialize with the same configuration paths
426+
const newMcpManager = await McpManager.init(this.configPaths, this.features)
427+
428+
this.features.logging.info(
429+
`MCP servers reinitialized completed with mcpServers count: ${newMcpManager.mcpServers.size}`
430+
)
431+
} catch (err: any) {
432+
this.features.logging.error(`Error reinitializing MCP servers: ${err.message}`)
433+
throw err
434+
}
435+
}
436+
415437
/**
416438
* Check if a tool requires approval.
417439
*/

0 commit comments

Comments
 (0)