Skip to content

Commit 701bc31

Browse files
authored
fix(read_file): return image bytes in MCP content so the model can see images (#488)
read_file on an image previously put the image bytes only in structuredContent (for the preview widget) and sent the host model a text-only summary ("Image file: ... (image/png)"). The model received no image block, so reading an image was effectively a no-op for the model — it could never actually see the image. Add the image content block back into the `content` array while keeping structuredContent unchanged, so: - the host model receives the image and can analyze it - the preview widget still renders from structuredContent as before The previous "text-only for broad host compatibility" approach blinded every host that can handle images, which is the common case.
1 parent 673111c commit 701bc31

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/handlers/filesystem-handlers.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ export async function handleReadFile(args: unknown): Promise<ServerResult> {
147147

148148
// Handle image files
149149
if (fileResult.metadata?.isImage) {
150-
// For image files, keep content payload text-only for broad host compatibility.
151-
// The preview widget reads image bytes from structuredContent.
150+
// Return the image bytes in the MCP content array so the host model can
151+
// actually see the image. structuredContent additionally carries the bytes
152+
// for the preview widget to render.
152153
const imageData = typeof fileResult.content === 'string'
153154
? fileResult.content
154155
: fileResult.content.toString('base64');
@@ -158,6 +159,11 @@ export async function handleReadFile(args: unknown): Promise<ServerResult> {
158159
{
159160
type: "text",
160161
text: imageSummary
162+
},
163+
{
164+
type: "image",
165+
data: imageData,
166+
mimeType: fileResult.mimeType
161167
}
162168
],
163169
structuredContent: {

0 commit comments

Comments
 (0)