Feature: Media type validation/conversion for MCP tool results #8735

Open
opened 2026-02-16 18:10:42 -05:00 by yindo · 1 comment
Owner

Originally created by @nxxxsooo on GitHub (Feb 6, 2026).

Originally assigned to: @thdxr on GitHub.

Problem

When using the filesystem MCP server's ReadMediaFile tool on files with media types not supported by the Claude API (e.g., image/svg+xml, image/bmp, image/tiff), the API returns a Type validation failed error because it only accepts image/jpeg, image/png, image/gif, and image/webp.

The agent has no way to recover from this — the error happens at the API level after the tool result is already assembled.

Current Workaround

Added AGENTS.md instructions telling the agent to never use ReadMediaFile on unsupported formats. This works but relies on the agent remembering the rule, which isn't reliable.

Proposed Solutions (any of these would help)

Option 1: Automatic conversion layer (preferred)

Add a media type validation step before sending tool results to the API. If an MCP tool returns image content with an unsupported media type:

  • SVG: Convert to PNG (via rsvg-convert, cairosvg, or sips on macOS)
  • BMP/TIFF/ICO: Convert to PNG (via sips on macOS, ImageMagick, or sharp)
  • Unknown: Strip the image content and return a text message explaining the format isn't supported

Option 2: Hook support for MCP tool results

Extend the hook system (PostToolUse) to also fire for MCP server tool calls, not just built-in tools. This would allow users to write custom conversion/filtering hooks.

Option 3: MCP tool result filter in config

Allow configuring media type filters in mcp.json or OpenCode settings:

{
  "mediaTypeFilter": {
    "allowedTypes": ["image/jpeg", "image/png", "image/gif", "image/webp"],
    "action": "convert_to_png"  // or "strip" or "error"
  }
}

Environment

  • OpenCode v1.1.53
  • macOS (Apple Silicon)
  • Filesystem MCP server (@modelcontextprotocol/server-filesystem)
  • Claude API (Opus 4)

Reproduction

# 1. Have an SVG file in the filesystem MCP's allowed directories
# 2. Ask the agent to read the SVG as an image
# 3. Agent calls FilesystemReadMediaFile on the .svg
# 4. API returns "Type validation failed" error
Originally created by @nxxxsooo on GitHub (Feb 6, 2026). Originally assigned to: @thdxr on GitHub. ## Problem When using the `filesystem` MCP server's `ReadMediaFile` tool on files with media types not supported by the Claude API (e.g., `image/svg+xml`, `image/bmp`, `image/tiff`), the API returns a `Type validation failed` error because it only accepts `image/jpeg`, `image/png`, `image/gif`, and `image/webp`. The agent has no way to recover from this — the error happens at the API level after the tool result is already assembled. ## Current Workaround Added AGENTS.md instructions telling the agent to never use `ReadMediaFile` on unsupported formats. This works but relies on the agent remembering the rule, which isn't reliable. ## Proposed Solutions (any of these would help) ### Option 1: Automatic conversion layer (preferred) Add a media type validation step before sending tool results to the API. If an MCP tool returns image content with an unsupported media type: - **SVG**: Convert to PNG (via `rsvg-convert`, `cairosvg`, or `sips` on macOS) - **BMP/TIFF/ICO**: Convert to PNG (via `sips` on macOS, ImageMagick, or sharp) - **Unknown**: Strip the image content and return a text message explaining the format isn't supported ### Option 2: Hook support for MCP tool results Extend the hook system (`PostToolUse`) to also fire for MCP server tool calls, not just built-in tools. This would allow users to write custom conversion/filtering hooks. ### Option 3: MCP tool result filter in config Allow configuring media type filters in `mcp.json` or OpenCode settings: ```json { "mediaTypeFilter": { "allowedTypes": ["image/jpeg", "image/png", "image/gif", "image/webp"], "action": "convert_to_png" // or "strip" or "error" } } ``` ## Environment - OpenCode v1.1.53 - macOS (Apple Silicon) - Filesystem MCP server (`@modelcontextprotocol/server-filesystem`) - Claude API (Opus 4) ## Reproduction ```bash # 1. Have an SVG file in the filesystem MCP's allowed directories # 2. Ask the agent to read the SVG as an image # 3. Agent calls FilesystemReadMediaFile on the .svg # 4. API returns "Type validation failed" error ```
Author
Owner

@github-actions[bot] commented on GitHub (Feb 6, 2026):

This issue might be a duplicate of or closely related to existing issues. Please check:

  • #12472: Native Claude Code hooks compatibility (PreToolUse, PostToolUse, Stop) — Your Option 2 proposes extending PostToolUse hooks to MCP servers, which aligns with this feature request for hook support.

Feel free to ignore if your specific case differs.

@github-actions[bot] commented on GitHub (Feb 6, 2026): This issue might be a duplicate of or closely related to existing issues. Please check: - #12472: Native Claude Code hooks compatibility (PreToolUse, PostToolUse, Stop) — Your Option 2 proposes extending PostToolUse hooks to MCP servers, which aligns with this feature request for hook support. Feel free to ignore if your specific case differs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8735