feat: support images in mcp tool responses (#4100)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
Brian Cheung
2025-11-14 15:00:52 -06:00
committed by GitHub
parent b939470302
commit 37cf365927

View File

@@ -671,15 +671,31 @@ export namespace SessionPrompt {
result, result,
) )
const output = result.content const textParts: string[] = []
.filter((x: any) => x.type === "text") const attachments: MessageV2.FilePart[] = []
.map((x: any) => x.text)
.join("\n\n") for (const item of result.content) {
if (item.type === "text") {
textParts.push(item.text)
} else if (item.type === "image") {
attachments.push({
id: Identifier.ascending("part"),
sessionID: input.sessionID,
messageID: input.processor.message.id,
type: "file",
mime: item.mimeType,
url: `data:${item.mimeType};base64,${item.data}`,
})
}
// Add support for other types if needed
}
return { return {
title: "", title: "",
metadata: result.metadata ?? {}, metadata: result.metadata ?? {},
output, output: textParts.join("\n\n"),
attachments,
content: result.content, // directly return content to preserve ordering when outputting to model
} }
} }
item.toModelOutput = (result) => { item.toModelOutput = (result) => {