Skip to content

Commit fb7a5e2

Browse files
authored
fix: fix to correctly store permissions if user reverts his permission to original choice (#1551)
1 parent 0e2488a commit fb7a5e2

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,11 @@ ${params.message}`,
15821582
// Handle action clicks (save, cancel, etc.)
15831583
messager.onMcpServerClick(action.id)
15841584
},
1585-
onClose: () => {},
1585+
onClose: () => {
1586+
messager.onMcpServerClick('save-permission-change')
1587+
},
15861588
onBackClick: () => {
1589+
messager.onMcpServerClick('save-permission-change')
15871590
messager.onListMcpServers()
15881591
},
15891592
},

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export class McpEventHandler {
3636
#currentEditingServerName: string | undefined
3737
#shouldDisplayListMCPServers: boolean
3838
#telemetryController: ChatTelemetryController
39+
#pendingPermissionConfig: { serverName: string; permission: MCPServerPermission } | undefined
3940

4041
constructor(features: Features, telemetryService: TelemetryService) {
4142
this.#features = features
4243
this.#eventListenerRegistered = false
4344
this.#currentEditingServerName = undefined
4445
this.#shouldDisplayListMCPServers = true
4546
this.#telemetryController = new ChatTelemetryController(features, telemetryService)
47+
this.#pendingPermissionConfig = undefined
4648
}
4749

4850
/**
@@ -232,6 +234,7 @@ export class McpEventHandler {
232234
'open-mcp-server': () => this.#handleOpenMcpServer(params),
233235
'edit-mcp': () => this.#handleEditMcpServer(params),
234236
'mcp-permission-change': () => this.#handleMcpPermissionChange(params),
237+
'save-permission-change': () => this.#handleSavePermissionChange(params),
235238
'refresh-mcp-list': () => this.#handleRefreshMCPList(params),
236239
'mcp-enable-server': () => this.#handleEnableMcpServer(params),
237240
'mcp-disable-server': () => this.#handleDisableMcpServer(params),
@@ -833,6 +836,7 @@ export class McpEventHandler {
833836
* Handles edit MCP configuration
834837
*/
835838
async #handleEditMcpServer(params: McpServerClickParams, error?: string) {
839+
await this.#handleSavePermissionChange({ id: 'save-mcp-permission' })
836840
const serverName = params.title
837841
if (!serverName) {
838842
return { id: params.id }
@@ -970,7 +974,7 @@ export class McpEventHandler {
970974
// }
971975

972976
/**
973-
* Handles MCP permission change events
977+
* Handles MCP permission change events to update the pending permission config without applying changes
974978
*/
975979
async #handleMcpPermissionChange(params: McpServerClickParams) {
976980
const serverName = params.title
@@ -991,7 +995,36 @@ export class McpEventHandler {
991995

992996
const mcpServerPermission = await this.#processPermissionUpdates(updatedPermissionConfig)
993997

994-
await McpManager.instance.updateServerPermission(serverName, mcpServerPermission)
998+
// Store the permission config instead of applying it immediately
999+
this.#pendingPermissionConfig = {
1000+
serverName,
1001+
permission: mcpServerPermission,
1002+
}
1003+
1004+
this.#features.logging.info(`Stored pending permission change for server: ${serverName}`)
1005+
1006+
return { id: params.id }
1007+
} catch (error) {
1008+
this.#features.logging.error(`Failed to process MCP permissions: ${error}`)
1009+
return { id: params.id }
1010+
}
1011+
}
1012+
1013+
/**
1014+
* Handles saving MCP permission changes
1015+
* Applies the stored permission changes
1016+
*/
1017+
async #handleSavePermissionChange(params: McpServerClickParams) {
1018+
if (!this.#pendingPermissionConfig) {
1019+
this.#features.logging.warn('No pending permission changes to save')
1020+
return { id: params.id }
1021+
}
1022+
1023+
try {
1024+
const { serverName, permission } = this.#pendingPermissionConfig
1025+
1026+
// Apply the stored permission changes
1027+
await McpManager.instance.updateServerPermission(serverName, permission)
9951028
this.#emitMCPConfigEvent()
9961029

9971030
// Get server config to emit telemetry
@@ -1012,9 +1045,14 @@ export class McpEventHandler {
10121045
languageServerVersion: this.#features.runtime.serverInfo.version,
10131046
})
10141047
}
1048+
1049+
// Clear the pending permission config after applying
1050+
this.#pendingPermissionConfig = undefined
1051+
1052+
this.#features.logging.info(`Applied permission changes for server: ${serverName}`)
10151053
return { id: params.id }
10161054
} catch (error) {
1017-
this.#features.logging.error(`Failed to update MCP permissions: ${error}`)
1055+
this.#features.logging.error(`Failed to save MCP permissions: ${error}`)
10181056
return { id: params.id }
10191057
}
10201058
}

0 commit comments

Comments
 (0)