fix(mcp): correct file extension when image format mismatches#68
Open
haosenwang1018 wants to merge 1 commit intollmsresearch:mainfrom
Open
fix(mcp): correct file extension when image format mismatches#68haosenwang1018 wants to merge 1 commit intollmsresearch:mainfrom
haosenwang1018 wants to merge 1 commit intollmsresearch:mainfrom
Conversation
When the image generator saves JPEG data with a .png extension, the MCP tool result declares image/png but the actual content is JPEG, causing Anthropic API validation errors. Now _compress_for_api copies the file with the correct extension when a mismatch is detected between the magic-byte format and the file extension. Fixes llmsresearch#58
Member
|
@haosenwang1018 Thanks for the fix, the approach looks good and targeted. I checked this against current After that, this looks good to go. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #58
The MCP generate_diagram tool returns JPEG image data with an image/png media type, causing the Anthropic API to reject the tool result.
Root Cause: The image generator may produce JPEG data but save it with a .png extension. While _compress_for_api correctly detects the actual format via magic-byte inspection, the fastmcp Image class may infer the MIME type from the file extension, resulting in a mismatch.
Fix: In _compress_for_api, after detecting the actual image format, check whether the file extension matches. If not, copy the file with the correct extension before returning.
No behavior change when the extension already matches the format.