Skip to content

Commit 570646f

Browse files
Garothrikaaa0928dcbartlettsaoudrizwanhugelung
authored
MCP Image: Support image type messages / base64 text (RooCodeInc#2962)
* feat: MCP ImageContent support * feat: MCP ImageContent support * feat: MCP ImageContent support changeset * Update src/core/prompts/responses.ts Co-authored-by: Dennis Bartlett <[email protected]> * Update src/core/Cline.ts Co-authored-by: Dennis Bartlett <[email protected]> * feat: MCP ImageContent support run format:fix * Remove mcpToolResult * Fix: Display original data:image URLs in rich display mode to maintain transparency --------- Co-authored-by: rikaaa0928 <[email protected]> Co-authored-by: rikaaa0928 <[email protected]> Co-authored-by: Dennis Bartlett <[email protected]> Co-authored-by: Saoud Rizwan <[email protected]> Co-authored-by: Andrei Edell <[email protected]>
1 parent e8b2169 commit 570646f

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

.changeset/slimy-jeans-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
MCP ImageContent as tool result

src/core/prompts/responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
22
import * as diff from "diff"
33
import * as path from "path"
44
import { ClineIgnoreController, LOCK_TEXT_SYMBOL } from "../ignore/ClineIgnoreController"
5+
import { McpToolCallResponse } from "../../shared/mcp"
56

67
export const formatResponse = {
78
duplicateFileReadNotice: () =>

src/core/task/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,8 +2690,13 @@ export class Task {
26902690
await this.say("mcp_server_request_started") // same as browser_action_result
26912691
const toolResult = await this.mcpHub.callTool(server_name, tool_name, parsedArguments)
26922692

2693-
// TODO: add progress indicator and ability to parse images and non-text responses
2694-
const toolResultPretty =
2693+
// TODO: add progress indicator
2694+
2695+
const toolResultImages =
2696+
toolResult?.content
2697+
.filter((item) => item.type === "image")
2698+
.map((item) => `data:${item.mimeType};base64,${item.data}`) || []
2699+
let toolResultText =
26952700
(toolResult?.isError ? "Error:\n" : "") +
26962701
toolResult?.content
26972702
.map((item) => {
@@ -2706,8 +2711,21 @@ export class Task {
27062711
})
27072712
.filter(Boolean)
27082713
.join("\n\n") || "(No response)"
2709-
await this.say("mcp_server_response", toolResultPretty)
2710-
pushToolResult(formatResponse.toolResult(toolResultPretty))
2714+
// webview extracts images from the text response to display in the UI
2715+
const toolResultToDisplay =
2716+
toolResultText + toolResultImages?.map((image) => `\n\n${image}`).join("")
2717+
await this.say("mcp_server_response", toolResultToDisplay)
2718+
2719+
// MCP's might return images to display to the user, but the model may not support them
2720+
const supportsImages = this.api.getModel().info.supportsImages ?? false
2721+
if (toolResultImages.length > 0 && !supportsImages) {
2722+
toolResultText += `\n\n[${toolResultImages.length} images were provided in the response, and while they are displayed to the user, you do not have the ability to view them.]`
2723+
}
2724+
2725+
// only passes in images if model supports them
2726+
pushToolResult(
2727+
formatResponse.toolResult(toolResultText, supportsImages ? toolResultImages : undefined),
2728+
)
27112729

27122730
await this.saveCheckpoint()
27132731

webview-ui/src/components/mcp/chat-display/McpResponseDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const McpResponseDisplay: React.FC<McpResponseDisplayProps> = ({ responseText })
162162
try {
163163
const text = responseText || ""
164164
const matches: UrlMatch[] = []
165-
const urlRegex = /https?:\/\/[^\s<>"']+/g
165+
const urlRegex = /(?:https?:\/\/|data:image)[^\s<>"']+/g
166166
let urlMatch: RegExpExecArray | null
167167
let urlCount = 0
168168

0 commit comments

Comments
 (0)