Skip to content

Commit 38df958

Browse files
committed
fix: fix for correct initialization of tools with namespacing for refresh
1 parent 1f23675 commit 38df958

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,6 @@ ${params.message}`,
15921592
)
15931593
} else if (['mcp-disable-server', 'mcp-delete-server', 'mcp-enable-server'].includes(params.id)) {
15941594
messager.onListMcpServers()
1595-
} else if (params.id === 'refresh-mcp-list') {
1596-
messager.onListMcpServers({ 'refresh-mcp-list': 'refresh-mcp-list' })
15971595
} else if (params.id === 'update-mcp-list') {
15981596
if (isMcpServersListActive) {
15991597
messager.onListMcpServers()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,15 @@ export class McpManager {
552552
this.features.logging.info('Reinitializing MCP servers')
553553

554554
try {
555+
// Save the current tool name mapping to preserve tool names across reinitializations
556+
const savedToolNameMapping = this.getToolNameMapping()
557+
555558
// close clients, clear state, but don't reset singleton
556559
await this.close(true)
560+
561+
// Restore the saved tool name mapping
562+
this.setToolNameMapping(savedToolNameMapping)
563+
557564
await this.discoverAllServers()
558565

559566
const reinitializedServerCount = McpManager.#instance?.mcpServers.size

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,19 @@ export function createNamespacedToolName(
337337
allNamespacedTools: Set<string>,
338338
toolNameMapping: Map<string, { serverName: string; toolName: string }>
339339
): string {
340+
// First, check if this server/tool combination already has a mapping
341+
// If it does, reuse that name to maintain consistency across reinitializations
342+
for (const [existingName, mapping] of toolNameMapping.entries()) {
343+
if (mapping.serverName === serverName && mapping.toolName === toolName) {
344+
// If the name is already in the set, it's already registered
345+
// If not, add it to the set
346+
if (!allNamespacedTools.has(existingName)) {
347+
allNamespacedTools.add(existingName)
348+
}
349+
return existingName
350+
}
351+
}
352+
340353
const sep = '___'
341354
// If tool name alone isn't unique or is too long, try adding server prefix
342355
const fullName = `${serverName}${sep}${toolName}`

0 commit comments

Comments
 (0)