René's URL Explorer Experiment


Title: Image content blocks >99 bytes fail with "illegal base64 at byte 0" · Issue #3123 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Image content blocks >99 bytes fail with "illegal base64 at byte 0" · Issue #3123 · modelcontextprotocol/python-sdk

X Title: Image content blocks >99 bytes fail with "illegal base64 at byte 0" · Issue #3123 · modelcontextprotocol/python-sdk

Description: Image Content Blocks >99 Bytes Fail Client-Side Decode in stdio Mode Summary Image content blocks returned via _mcp_content_blocks fail client-side base64 decoding when the decoded image bytes exceed 99 bytes, despite the server emitting...

Open Graph Description: Image Content Blocks >99 Bytes Fail Client-Side Decode in stdio Mode Summary Image content blocks returned via _mcp_content_blocks fail client-side base64 decoding when the decoded image bytes exce...

X Description: Image Content Blocks >99 Bytes Fail Client-Side Decode in stdio Mode Summary Image content blocks returned via _mcp_content_blocks fail client-side base64 decoding when the decoded image bytes e...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3123

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Image content blocks >99 bytes fail with \"illegal base64 at byte 0\"","articleBody":"# Image Content Blocks >99 Bytes Fail Client-Side Decode in stdio Mode\n\n## Summary\n\nImage content blocks returned via `_mcp_content_blocks` fail client-side base64 decoding when the decoded image bytes exceed **99 bytes**, despite the server emitting spec-compliant MCP protocol messages. The issue manifests as `\"illegal base64 data at input byte 0\"` errors in the client, while server wire logs confirm correct base64 encoding with proper padding.\n\n## Environment\n\n**Server:**\n- Python SDK: `mcp==1.28.1`\n- Python: 3.12\n- Transport: stdio (JSON-RPC over stdin/stdout)\n- OS: Linux (Ubuntu-based)\n\n**Client:**\n- Claude Code (Anthropic's MCP client)\n- Error source: Go `encoding/base64` (based on error message format)\n\n**Dependencies:**\n```\nmcp==1.28.1\nstarlette==1.3.1\npydantic==2.13.4\nfastapi==0.139.2\n```\n\n## Issue Description\n\n### Observed Behavior\n\nImages returned in MCP content blocks exhibit a **binary size threshold at exactly 100 bytes** (decoded image data):\n\n| Decoded Bytes | Base64 Chars | Result | Error |\n|---------------|--------------|--------|-------|\n| ≤99 | ≤132 | ✅ Renders | None |\n| ≥100 | ≥136 | ❌ Fails | \"illegal base64 data at input byte 0\" |\n\n### Test Results\n\n**Pass Class (renders successfully):**\n- 48 bytes (64 base64 chars): ✅ Visual confirmation\n- 99 bytes (132 base64 chars): ✅ Visual confirmation\n\n**Fail Class (decode error):**\n- 102 bytes (136 base64 chars): ❌ \"illegal base64 data at input byte 0\"\n- 4,412 bytes (5,884 base64 chars): ❌ \"illegal base64 data at input byte 0\"\n- 5,108 bytes (6,812 base64 chars): ❌ \"illegal base64 data at input byte 0\"\n\n### Additional Finding (SDK Version Dependent)\n\nWith SDK 1.26.0, payloads >4KB exhibited a second error class:\n- **\"Incorrect padding\"** (Python `binascii` error)\n\nThis was **fixed by upgrading to SDK 1.28.1**, leaving only the 100-byte threshold issue.\n\n## Wire-Level Evidence\n\nServer logs confirm **spec-compliant** image blocks are emitted:\n\n```\n[ISS-011-WIRE] Image block: data_len=64, first_char='U', last_char='B', \n               has_mimeType=True, block_keys=['type', 'data', 'mimeType']\nResult: ✅ RENDERED\n\n[ISS-011-WIRE] Image block: data_len=6812, first_char='U', last_char='=', \n               has_mimeType=True, block_keys=['type', 'data', 'mimeType']\nResult: ❌ illegal base64 data at input byte 0\n\n[ISS-011-WIRE] Image block: data_len=5884, first_char='U', last_char='=', \n               has_mimeType=True, block_keys=['type', 'data', 'mimeType']\nResult: ❌ illegal base64 data at input byte 0\n```\n\n**Analysis:**\n- ✅ Correct keys: `['type', 'data', 'mimeType']`\n- ✅ Valid base64 start: `'U'` (valid character)\n- ✅ Proper padding: `'='` where expected\n- ✅ No wrapping, prefixing, or unexpected keys\n- ❌ **Client receives \"illegal at byte 0\"** despite clean server output\n\n## Reproduction\n\n### Minimal Server Code\n\n```python\nimport base64\nfrom PIL import Image\nimport io\n\ndef img_test_base64_transport(test_variant: int = 0):\n    \"\"\"\n    Test image content blocks at different sizes.\n    Variant 0: 48 bytes (passes)\n    Variant 1: 102 bytes (fails)\n    \"\"\"\n    if test_variant == 0:\n        # Small image: 4x4 solid color\n        img = Image.new('RGB', (4, 4), color=(128, 128, 128))\n    else:\n        # Larger image: ~102 bytes\n        img = Image.new('RGB', (6, 6), color=(128, 128, 128))\n    \n    buf = io.BytesIO()\n    img.save(buf, format='WEBP', quality=100, method=6)\n    webp_bytes = buf.getvalue()\n    \n    # Encode to base64\n    b64_data = base64.b64encode(webp_bytes).decode(\"utf-8\")\n    \n    # Ensure padding (though b64encode already does this)\n    missing_padding = len(b64_data) % 4\n    if missing_padding:\n        b64_data += '=' * (4 - missing_padding)\n    \n    # Return as MCP image content block\n    return {\n        \"success\": True,\n        \"test_variant\": test_variant,\n        \"actual_b64_length\": len(b64_data),\n        \"bytes_emitted\": len(webp_bytes),\n        \"b64_padding_check\": len(b64_data) % 4,\n        \"mime_type\": \"image/webp\",\n        \"_mcp_content_blocks\": [\n            {\n                \"type\": \"image\",\n                \"data\": b64_data,\n                \"mimeType\": \"image/webp\"\n            }\n        ]\n    }\n```\n\n### MCP Tool Registration\n\n```python\n@server.call_tool()\nasync def test_image_size(test_variant: int = 0):\n    \"\"\"Test image at different sizes to reproduce 100-byte threshold bug.\"\"\"\n    result = img_test_base64_transport(test_variant)\n    \n    # Extract content blocks\n    content_blocks = result.pop(\"_mcp_content_blocks\", [])\n    \n    # Return content blocks + metadata\n    return content_blocks + [{\"type\": \"text\", \"text\": json.dumps(result)}]\n```\n\n### Steps to Reproduce\n\n1. Run MCP server with test tool above\n2. Connect with Claude Code client\n3. Call `test_image_size(test_variant=0)` → ✅ Image renders\n4. Call `test_image_size(test_variant=1)` → ❌ \"illegal base64 data at input byte 0\"\n\n## Expected Behavior\n\nImage content blocks should render regardless of size, as long as:\n1. Base64 encoding is valid (length % 4 == 0)\n2. Decoded bytes are valid WebP/image data\n3. Block structure follows MCP spec: `{\"type\": \"image\", \"data\": \"\u003cbase64>\", \"mimeType\": \"image/webp\"}`\n\n## Actual Behavior\n\nImages >99 decoded bytes fail with:\n```\nImage '\u003cuuid>.webp' could not be processed: illegal base64 data at input byte 0\n```\n\nThis error indicates the **first character received by the client decoder is not valid base64**, despite server logs showing `first_char='U'` (valid base64).\n\n## Root Cause Analysis\n\nThe evidence suggests:\n\n1. **Server-side is correct:**\n   - Wire logs show proper base64 encoding\n   - First/last characters are valid\n   - Padding is correct (len % 4 == 0)\n   - No unexpected keys or wrapping\n\n2. **Client-side has size threshold:**\n   - Exact boundary at 100 decoded bytes\n   - Error message from Go `encoding/base64` (not Python)\n   - Suggests client code path branches on size:\n     ```go\n     if len(imageBytes) > 100 {\n         // Wrapper/attachment path (breaks base64)\n     } else {\n         // Inline path (works)\n     }\n     ```\n\n3. **Hypothesis:**\n   - Client wraps/prefixes large payloads before decoding\n   - Wrapper invalidates base64 (illegal first byte)\n   - 100 bytes is a human-round-number threshold (not power-of-2)\n\n## Impact\n\n- **Thumbnails fail:** 128x128 WebP thumbnails are ~3-5KB (always fail)\n- **Image preview broken:** Cannot display images in MCP responses\n- **Workaround required:** External file references instead of inline images\n\n## Diagnostic Data Available\n\nWe have comprehensive test results including:\n- 10 test fixtures spanning 48-6,812 bytes\n- Server-side wire logs for all sizes\n- Exact boundary detection (99 vs 100 bytes)\n- SDK version comparison (1.26.0 vs 1.28.1)\n\nHappy to provide additional test cases or logs if needed.\n\n## Related Issues\n\n- #2376 - Image/ImageContent serialization fails in stateless HTTP mode (possibly related)\n\n## Proposed Fix\n\nSince server-side emits correct data, the fix likely needs to be in:\n\n1. **Client SDK** (Claude Code's MCP harness) - remove size-based branching for image content blocks\n2. **Or MCP spec clarification** - if >100-byte images require different encoding, document it\n\n---\n\n**CC:** @anthropics/mcp-team\n\n**Test server available:** We have a fully instrumented test server with wire-level logging if needed for debugging.","author":{"url":"https://github.com/PeeperFrog","@type":"Person","name":"PeeperFrog"},"datePublished":"2026-07-18T00:19:29Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3123"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0e4c535b-1ef3-9615-8b4b-0b57bd4572cc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC2F4:29AEE8:9841FC:CCD8A5:6B00E898
html-safe-nonce0b1da374ec627d127613733361325d772bfdb133606ccdd023c3af4ab915e73b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkY0OjI5QUVFODo5ODQxRkM6Q0NEOEE1OjZCMDBFODk4IiwidmlzaXRvcl9pZCI6Ijc3NDY1MzU3OTU3NzQ3Nzc0OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac24a837678a9b856ae255a55c42ce234594663779b801c5c6d618a18bbed3fc48
hovercard-subject-tagissue:4915765224
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3123/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ba05fc784b91f46646c48f26493bde984023cd86398861fd7f91357c2a46f044/modelcontextprotocol/python-sdk/issues/3123
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ba05fc784b91f46646c48f26493bde984023cd86398861fd7f91357c2a46f044/modelcontextprotocol/python-sdk/issues/3123
og:image:altImage Content Blocks >99 Bytes Fail Client-Side Decode in stdio Mode Summary Image content blocks returned via _mcp_content_blocks fail client-side base64 decoding when the decoded image bytes exce...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamePeeperFrog
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3123#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3123
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3123
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3123
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3123
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3123
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3123
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3123
Image content blocks >99 bytes fail with "illegal base64 at byte 0"https://github.com/modelcontextprotocol/python-sdk/issues/3123#top
https://github.com/PeeperFrog
PeeperFroghttps://github.com/PeeperFrog
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issue-4915765224
Image/ImageContent serialization fails in stateless HTTP mode #2376https://github.com/modelcontextprotocol/python-sdk/issues/2376
https://github.com/PeeperFrog
PeeperFroghttps://github.com/PeeperFrog
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5008749585
https://github.com/PeeperFrog
PeeperFroghttps://github.com/PeeperFrog
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5008769137
https://github.com/PeeperFrog
PeeperFroghttps://github.com/PeeperFrog
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5009012371
https://github.com/PeeperFrog/noisk-ai-mcp/blob/18919c7b/src/NOISK_AI_server.py#L14006-14133https://github.com/PeeperFrog/noisk-ai-mcp/blob/18919c7b/src/NOISK_AI_server.py#L14006-14133
https://github.com/PeeperFrog
PeeperFroghttps://github.com/PeeperFrog
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5009163577
https://github.com/PeeperFrog/noisk-ai-mcphttps://github.com/PeeperFrog/noisk-ai-mcp
https://github.com/earfman
earfmanhttps://github.com/earfman
on Jul 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5010246574
https://github.com/maxisbey
maxisbeyhttps://github.com/maxisbey
on Aug 10, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#issuecomment-5243209946
https://github.com/anthropics/claude-codehttps://github.com/anthropics/claude-code
AI Disclaimerhttps://gist.github.com/maxisbey/6123d132484e4c533eab519a2800693d
maxisbeyhttps://github.com/maxisbey
not plannedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Aug 10, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3123#event-29235234152
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3123
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3123
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.