MCPcopy Index your code
hub / github.com/codeaashu/claude-code / addToolResult

Function addToolResult

src/services/tools/toolExecution.ts:1403–1474  ·  view source on GitHub ↗
(
      toolUseResult: unknown,
      preMappedBlock?: ToolResultBlockParam,
    )

Source from the content-addressed store, hash-verified

1401 const mcpMeta = result.mcpMeta
1402
1403 async function addToolResult(
1404 toolUseResult: unknown,
1405 preMappedBlock?: ToolResultBlockParam,
1406 ) {
1407 // Use the pre-mapped block when available (non-MCP tools where hooks
1408 // don't modify the output), otherwise map from scratch.
1409 const toolResultBlock = preMappedBlock
1410 ? await processPreMappedToolResultBlock(
1411 preMappedBlock,
1412 tool.name,
1413 tool.maxResultSizeChars,
1414 )
1415 : await processToolResultBlock(tool, toolUseResult, toolUseID)
1416
1417 // Build content blocks - tool result first, then optional feedback
1418 const contentBlocks: ContentBlockParam[] = [toolResultBlock]
1419 // Add accept feedback if user provided feedback when approving
1420 // (acceptFeedback only exists on PermissionAllowDecision, which is guaranteed here)
1421 if (
1422 'acceptFeedback' in permissionDecision &&
1423 permissionDecision.acceptFeedback
1424 ) {
1425 contentBlocks.push({
1426 type: 'text',
1427 text: permissionDecision.acceptFeedback,
1428 })
1429 }
1430
1431 // Add content blocks (e.g., pasted images) from the permission decision
1432 const allowContentBlocks =
1433 'contentBlocks' in permissionDecision
1434 ? permissionDecision.contentBlocks
1435 : undefined
1436 if (allowContentBlocks?.length) {
1437 contentBlocks.push(...allowContentBlocks)
1438 }
1439
1440 // Generate sequential imagePasteIds so each image renders with a distinct label
1441 let allowImageIds: number[] | undefined
1442 if (allowContentBlocks?.length) {
1443 const imageCount = count(
1444 allowContentBlocks,
1445 (b: ContentBlockParam) => b.type === 'image',
1446 )
1447 if (imageCount > 0) {
1448 const startId = getNextImagePasteId(toolUseContext.messages)
1449 allowImageIds = Array.from(
1450 { length: imageCount },
1451 (_, i) => startId + i,
1452 )
1453 }
1454 }
1455
1456 resultingMessages.push({
1457 message: createUserMessage({
1458 content: contentBlocks,
1459 imagePasteIds: allowImageIds,
1460 toolUseResult:

Callers 1

Calls 6

processToolResultBlockFunction · 0.85
countFunction · 0.85
getNextImagePasteIdFunction · 0.85
createUserMessageFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected