@@ -325,6 +325,11 @@ func isTextFile(mimeType string) bool {
325
325
strings .Contains (mimeType , "+json" )
326
326
}
327
327
328
+ // isImageFile determines if a file is an image based on MIME type
329
+ func isImageFile (mimeType string ) bool {
330
+ return strings .HasPrefix (mimeType , "image/" )
331
+ }
332
+
328
333
// pathToResourceURI converts a file path to a resource URI
329
334
func pathToResourceURI (path string ) string {
330
335
return "file://" + path
@@ -575,8 +580,44 @@ func (s *FilesystemServer) handleReadFile(
575
580
},
576
581
},
577
582
}, nil
583
+ } else if isImageFile (mimeType ) {
584
+ // It's an image file, return as image content
585
+ if info .Size () <= MAX_BASE64_SIZE {
586
+ return & mcp.CallToolResult {
587
+ Content : []mcp.Content {
588
+ mcp.TextContent {
589
+ Type : "text" ,
590
+ Text : fmt .Sprintf ("Image file: %s (%s, %d bytes)" , validPath , mimeType , info .Size ()),
591
+ },
592
+ mcp.ImageContent {
593
+ Type : "image" ,
594
+ Data : base64 .StdEncoding .EncodeToString (content ),
595
+ MIMEType : mimeType ,
596
+ },
597
+ },
598
+ }, nil
599
+ } else {
600
+ // Too large for base64, return a reference
601
+ resourceURI := pathToResourceURI (validPath )
602
+ return & mcp.CallToolResult {
603
+ Content : []mcp.Content {
604
+ mcp.TextContent {
605
+ Type : "text" ,
606
+ Text : fmt .Sprintf ("Image file is too large to display inline (%d bytes). Access it via resource URI: %s" , info .Size (), resourceURI ),
607
+ },
608
+ mcp.EmbeddedResource {
609
+ Type : "resource" ,
610
+ Resource : mcp.TextResourceContents {
611
+ URI : resourceURI ,
612
+ MIMEType : "text/plain" ,
613
+ Text : fmt .Sprintf ("Large image: %s (%s, %d bytes)" , validPath , mimeType , info .Size ()),
614
+ },
615
+ },
616
+ },
617
+ }, nil
618
+ }
578
619
} else {
579
- // It's a binary file
620
+ // It's another type of binary file
580
621
resourceURI := pathToResourceURI (validPath )
581
622
582
623
if info .Size () <= MAX_BASE64_SIZE {
0 commit comments