Repository navigation
Conversation
map_mcp_content_to_tool_result_content indexed MIME_TO_FORMAT directly, so a successful tool result carrying an ImageContent block with an image mime type outside the supported set (e.g. image/svg+xml) raised a KeyError that call_tool_sync/call_tool_async turned into an error result, losing every other content block in the same result. Mirror the typescript sdk and fall back to a json content block with a warning instead.
BlueX888
force-pushed
the
fix/prep-mcp-client-image-mime-keyerror
branch
from
October 22, 2026 18:02
d0ac137 to
1ce6966
Compare
This branch has not been deployed
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.
Description
MCPClient.map_mcp_content_to_tool_result_contentindexedMIME_TO_FORMATdirectly with the mime type supplied by the MCP server. That map only coversimage/jpeg,image/jpg,image/png,image/gifandimage/webp, so a successful tool result carrying a top-levelImageContentblock with any other image mime type (e.g.image/svg+xmlfrom a chart-rendering server) raisedKeyError: 'image/svg+xml'.call_tool_sync/call_tool_asynccatch that exception and turn the whole result into{"status": "error", "content": [{"text": "Tool execution failed: 'image/svg+xml'"}]}— discarding every other content block of a call that actually succeeded.This falls back to a
jsoncontent block carrying the full image payload and logs a warning, mirroring the TypeScript SDK's_mapMcpImageContent(strands-ts/src/tools/mcp-tool.ts), which does the same fallback with the same warning text.Related Issues
None open. #2218 previously proposed this fallback and was closed without merging; the unguarded
MIME_TO_FORMAT[image_mime]lookup is still onmain.Documentation PR
Not needed — no public API change, and no documentation currently enumerates the supported image mime types.
Type of Change
Bug fix
Testing
hatch test/hatch run preparecannot run on this machine: hatch 1.18.1's environment dependency sync fails withRecursionError: maximum recursion depth exceededdeep in its dependency-in-sync walk (packaging marker parsing). It reproduces with hatch on Python 3.12 and 3.13, withsys.setrecursionlimitraised, and identically on the unpatched tree, so it is unrelated to this change. The commands below are the ones the hatch scripts define (pytest {args},ruff format --check,ruff check), run against an equivalent environment: Python 3.13.15, project installed editable with theallextra plus thehatch-testdependency set.Regression test on the unpatched tree (
git checkout origin/main -- src/strands/tools/mcp/mcp_client.py):pytest -n 0 -vv tests/strands/tools/mcp/test_mcp_client.py -k "unsupported_mime"→ 1 failed — the result degrades to{'status': 'error', 'content': [{'text': "Tool execution failed: 'image/svg+xml'"}]}New test on the patched tree: same command →
1 passedModule tests:
pytest -n auto tests/strands/tools/mcp/→357 passed, 31 skippedFull unit suite:
pytest -n auto tests/→6949 passed, 31 skippedruff format --check→724 files already formattedruff check→All checks passed!mypyscoped to the changed module with--python-version 3.13(the repo-wide run cannot complete in this ad-hoc environment because the latest numpy/smithy_core stubs use Python 3.12+ syntax under the pinnedpython_version = "3.10"; pre-existing and unrelated, and mypy is not part of the CI lint gate) →Success: no issues found in 1 source fileI ran
hatch run prepare— not run: see note above; the checks it wraps (format, lint, full test suite) were run individually.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.