Skip to content

fix(tools-mcp): use removeprefix instead of lstrip for image/audio MIME format - #2289

Open
dineshyadav03 wants to merge 1 commit into
griptape-ai:mainfrom
dineshyadav03:fix/mcp-tool-mime-format-lstrip
Open

dineshyadav03 wants to merge 1 commit into
griptape-ai:mainfrom
dineshyadav03:fix/mcp-tool-mime-format-lstrip

Conversation

@dineshyadav03

Copy link
Copy Markdown

Describe your changes

MCPTool._convert_call_tool_result_to_artifact derived ImageArtifact/AudioArtifact format from the MCP result's mimeType using str.lstrip("image/") / str.lstrip("audio/"). lstrip strips 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 format then flows into the mime_type sent back to LLM providers and into the file extension used when saving the artifact. It happened to go unnoticed because the existing test only covered image/png, which coincidentally survives lstrip unscathed.

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, and audio/aac; confirmed they fail against the old lstrip implementation and pass with removeprefix. ruff check and ruff format are clean on both changed files.

Issue ticket number and link

Fixes #2286

…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

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@collindutter collindutter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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.

MCPTool derives image/audio format with str.lstrip, corrupting formats like gif and aac

2 participants