Skip to content

Conversation

@libertyteeth
Copy link

@libertyteeth libertyteeth commented Sep 12, 2025

Summary

This PR adds native support for reading image and binary files through the MCP protocol.

Changes

  • Added get_file_type() function for magic number detection
  • Images are returned as ImageContent for direct LLM processing
  • Binary files are handled appropriately with base64 encoding
  • Enhanced file info to include MIME type and binary status

Motivation

Currently, the filesystem MCP server only handles text files. With the rise of multimodal LLMs that can process images, it's valuable to support native image reading through the MCP protocol.

Testing

  • Tested with PNG, JPEG images
  • Verified backward compatibility with text files
  • Confirmed proper MIME type detection

Technical Details

  • Uses magic numbers for reliable file type detection (more accurate than extension-based)
  • Falls back to extension-based detection via mimetypes
  • No additional dependencies required
  • Minimal changes to existing codebase

Example Usage

After this change, LLMs can directly process images:

# Server returns ImageContent for images
result = read_file('/data/a/screenshot.png')
# result is ImageContent with base64 data and MIME type
# LLM can directly analyze the image

Compatibility

  • Fully backward compatible with existing text file operations
  • No breaking changes to the API
  • No additional dependencies needed

- Add magic number detection for common image formats (PNG, JPEG, GIF, BMP, WEBP, HEIC)
- Return ImageContent for images to enable direct LLM processing
- Add proper MIME type detection using both magic numbers and extensions
- Support binary file handling with appropriate metadata
- Maintain backward compatibility for text files

This allows LLMs to directly analyze images through the MCP protocol
without manual base64 encoding/decoding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant