Skip to content

Commit 79fa055

Browse files
shivangagclaude
andcommitted
fix: resolve failing MCP tool tests
- Fix image limiting warning logic by checking original array length before slicing - Add missing getState mock in test to support MCP settings access - Update test assertion to match actual function signature with images parameter 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f7fc4de commit 79fa055

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/core/tools/__tests__/useMcpToolTool.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,10 @@ describe("useMcpToolTool", () => {
11471147
callTool: vi.fn().mockResolvedValue(mockToolResult),
11481148
}),
11491149
postMessageToWebview: vi.fn(),
1150+
getState: vi.fn().mockResolvedValue({
1151+
mcpMaxImagesPerResponse: 20,
1152+
mcpMaxImageSizeMB: 10,
1153+
}),
11501154
})
11511155

11521156
const block: ToolUse = {
@@ -1174,7 +1178,7 @@ describe("useMcpToolTool", () => {
11741178
expect(mockTask.consecutiveMistakeCount).toBe(0)
11751179
expect(mockTask.recordToolError).not.toHaveBeenCalled()
11761180
expect(mockTask.say).toHaveBeenCalledWith("mcp_server_request_started")
1177-
expect(mockTask.say).toHaveBeenCalledWith("mcp_server_response", "Tool executed successfully")
1181+
expect(mockTask.say).toHaveBeenCalledWith("mcp_server_response", "Tool executed successfully", [])
11781182
})
11791183

11801184
it("should reject unknown server names with available servers listed", async () => {

src/core/tools/useMcpToolTool.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,15 @@ async function processToolContent(toolResult: any, cline: Task): Promise<{ text:
269269
const maxImageSizeMB = Math.max(0.1, Math.min(50, state?.mcpMaxImageSizeMB ?? 10))
270270

271271
// Separate content by type for efficient processing
272-
const imageItems = toolResult.content.filter((item: any) => item.type === "image").slice(0, maxImagesPerResponse) // Limit images before processing
272+
const allImageItems = toolResult.content.filter((item: any) => item.type === "image")
273+
const imageItems = allImageItems.slice(0, maxImagesPerResponse) // Limit images before processing
274+
275+
// Check if we need to warn about exceeding the limit
276+
if (allImageItems.length > maxImagesPerResponse) {
277+
console.warn(
278+
`MCP response contains more than ${maxImagesPerResponse} images. Additional images will be ignored to prevent performance issues.`,
279+
)
280+
}
273281

274282
// Process images in parallel
275283
const validatedImages = await Promise.all(
@@ -287,12 +295,6 @@ async function processToolContent(toolResult: any, cline: Task): Promise<{ text:
287295
}
288296
})
289297

290-
if (imageItems.length > maxImagesPerResponse) {
291-
console.warn(
292-
`MCP response contains more than ${maxImagesPerResponse} images. Additional images will be ignored to prevent performance issues.`,
293-
)
294-
}
295-
296298
return {
297299
text: textParts.filter(Boolean).join("\n\n"),
298300
images,

0 commit comments

Comments
 (0)