Skip to content

Commit 23f5ec3

Browse files
fix(amazonq): fix to add mcp server tool error handling and status for card (aws#2176)
Co-authored-by: Laxman Reddy <[email protected]>
1 parent 8600c52 commit 23f5ec3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,50 @@ export class AgenticChatController implements ChatHandlers {
21922192
)
21932193
}
21942194

2195+
// Handle MCP tool failures
2196+
const originalNames = McpManager.instance.getOriginalToolNames(toolUse.name)
2197+
if (originalNames && toolUse.toolUseId) {
2198+
const { toolName } = originalNames
2199+
const cachedToolUse = session.toolUseLookup.get(toolUse.toolUseId)
2200+
const cachedButtonBlockId = (cachedToolUse as any)?.cachedButtonBlockId
2201+
const customerFacingError = getCustomerFacingErrorMessage(err)
2202+
2203+
const errorResult = {
2204+
type: 'tool',
2205+
messageId: toolUse.toolUseId,
2206+
summary: {
2207+
content: {
2208+
header: {
2209+
icon: 'tools',
2210+
body: `${toolName}`,
2211+
status: {
2212+
status: 'error',
2213+
icon: 'cancel-circle',
2214+
text: 'Error',
2215+
description: customerFacingError,
2216+
},
2217+
},
2218+
},
2219+
collapsedContent: [
2220+
{
2221+
header: { body: 'Parameters' },
2222+
body: `\`\`\`json\n${JSON.stringify(toolUse.input, null, 2)}\n\`\`\``,
2223+
},
2224+
{
2225+
header: { body: 'Error' },
2226+
body: customerFacingError,
2227+
},
2228+
],
2229+
},
2230+
} as ChatResult
2231+
2232+
if (cachedButtonBlockId !== undefined) {
2233+
await chatResultStream.overwriteResultBlock(errorResult, cachedButtonBlockId)
2234+
} else {
2235+
await chatResultStream.writeResultBlock(errorResult)
2236+
}
2237+
}
2238+
21952239
// display fs write failure status in the UX of that file card
21962240
if ((toolUse.name === FS_WRITE || toolUse.name === FS_REPLACE) && toolUse.toolUseId) {
21972241
const existingCard = chatResultStream.getMessageBlockId(toolUse.toolUseId)
@@ -4568,6 +4612,13 @@ export class AgenticChatController implements ChatHandlers {
45684612
await chatResultStream.overwriteResultBlock(toolResultCard, cachedButtonBlockId)
45694613
} else {
45704614
// Fallback to creating a new card
4615+
if (toolResultCard.summary?.content?.header) {
4616+
toolResultCard.summary.content.header.status = {
4617+
status: 'success',
4618+
icon: 'ok',
4619+
text: 'Completed',
4620+
}
4621+
}
45714622
this.#log(`Warning: No blockId found for tool use ${toolUse.toolUseId}, creating new card`)
45724623
await chatResultStream.writeResultBlock(toolResultCard)
45734624
}

0 commit comments

Comments
 (0)