fix(tools-mcp): use removeprefix instead of lstrip for image/audio MIME format - #2289
Open
dineshyadav03 wants to merge 1 commit into
Open
dineshyadav03 wants to merge 1 commit into
dineshyadav03 wants to merge 1 commit into
Conversation
…ME format
str.lstrip strips any leading characters in the given set rather than a
literal prefix, so content.mimeType.lstrip("image/") corrupts formats
whose subtype starts with a letter in {i,m,a,g,e,/} (e.g. "image/gif"
-> "f", "image/apng" -> "png" is fine but "image/avif" -> "vif") and
likewise for audio (e.g. "audio/aac" -> "c"). This produces an invalid
ImageArtifact/AudioArtifact.format, which then propagates into an
incorrect mime_type sent to LLM providers and a wrong file extension on
save.
Switch both call sites to removeprefix, matching the existing pattern
already used elsewhere in the codebase (e.g. griptape_cloud_assistant_driver.py).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
collindutter
enabled auto-merge
September 1, 2026 17:33
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.
Describe your changes
MCPTool._convert_call_tool_result_to_artifactderivedImageArtifact/AudioArtifactformatfrom the MCP result'smimeTypeusingstr.lstrip("image/")/str.lstrip("audio/").lstripstrips any leading characters in the given set, not a literal prefix, so it silently corrupts any format whose subtype starts with a letter already in{i,m,a,g,e,/}(image) or{a,u,d,i,o,/}(audio):"image/gif".lstrip("image/")->"f"(should be"gif")"image/apng".lstrip("image/")->"png"(should be"apng")"audio/aac".lstrip("audio/")->"c"(should be"aac")This corrupted
formatthen flows into themime_typesent back to LLM providers and into the file extension used when saving the artifact. It happened to go unnoticed because the existing test only coveredimage/png, which coincidentally surviveslstripunscathed.Fix: use
str.removeprefix, which already the established pattern elsewhere in this codebase (e.g.griptape_cloud_assistant_driver.py,griptape_cloud_prompt_driver.py) for exact-prefix stripping.Added parametrized regression tests covering
image/gif,image/apng,audio/wav, andaudio/aac; confirmed they fail against the oldlstripimplementation and pass withremoveprefix.ruff checkandruff formatare clean on both changed files.Issue ticket number and link
Fixes #2286