Skip to content

Python: Decode base64 image, audio and blob content from MCP servers - #14675

Open
Jae Birdsall (jaeminbird) wants to merge 1 commit into
microsoft:mainfrom
jaeminbird:fix-mcp-base64-content
Open

Jae Birdsall (jaeminbird) wants to merge 1 commit into
microsoft:mainfrom
jaeminbird:fix-mcp-base64-content

Conversation

@jaeminbird

Copy link
Copy Markdown
Contributor

Motivation and Context

MCP sends image/audio data and blob blob as base64, but the MCP connector builds ImageContent/AudioContent/BinaryContent without data_format="base64". So .data holds the base64 text, data_uri becomes data:image/png;,iVBOR... (no ;base64), and blob resources lose their mimeType (text/plain). Tool results, prompts and sampling messages with images reach the model broken; the Google AI connector sends the base64 text as image bytes.

Description

Pass data_format="base64" for the three types, and the resource mimeType for blobs.

  • New test covers image, audio and a blob resource via call_tool and get_prompt; fails before, passes after.
  • urllib.request.urlopen(content.data_uri) now returns the original bytes (before: the base64 text).
  • tests/unit/connectors/mcp and tests/unit/contents pass; ruff and mypy clean.

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings October 29, 2026 06:19
@jaeminbird
Jae Birdsall (jaeminbird) requested a review from a team as a code owner October 29, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 29, 2026
@jaeminbird

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@eavanvalkenburg

Copy link
Copy Markdown
Member

This is approved, but GitHub now marks its merge-queue entry UNMERGEABLE. I confirmed a conflict with #14676 in python/tests/unit/connectors/mcp/test_mcp.py: both PRs append tests at the same location. Please rebase after #14676 lands and keep both sets of regression tests.

@jaeminbird

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #14676 (a68f006). Both sets of tests are kept in test_mcp.py, and tests/unit/connectors/mcp passes (69 tests).

@jaeminbird

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main (4c8d27c), which also picks up #14095 in mcp.py. Both sets of regression tests from #14676 and this PR are kept in test_mcp.py; tests/unit/connectors/mcp passes (73 tests) and ruff/mypy are clean. Thanks Eduard van Valkenburg (@eavanvalkenburg) for tracking down the conflict.

This branch was successfully deployed

1 active deployment
github-app-auth — 4c8d27ce Deployed Nov 3, 2026 by jaeminbird via add_label #29567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants