Repository navigation
fix(studio): normalize MCP image base64 before llama-server decode - #12080
Souravrajvi0 wants to merge 4 commits into
Conversation
MCP tools sometimes return data URLs or line-wrapped base64 in image payloads. The UI could still render those while promotion or llama-server rejected them with Invalid base64 value on replay. Peel data-URI prefixes and whitespace at ingestion and decode time, and coerce bare base64 through the same normalizer.
|
The
|
…ation Keep MCP/data-URL base64 normalization on the data: branch only. Bare base64 image_url values must still pass through unchanged after remote inline, matching llama-server and test_remote_image_url_fetch_behaviour.
|
Thank you for the PR and for digging into #12058! Closing this as superseded by #12236, which found the actual cause and closed #12058. Before each request Studio counts the prompt tokens with llama-server, and for that count it replaced every image with the text The data URI / wrapped base64 path here cannot produce that error: Studio never forwards MCP image bytes to llama-server as received. If you have a real MCP server that sends a data URI in the |
Summary
Fixes intermittent
Invalid base64 valuefrom llama-server when MCP tools return images in Unsloth Studio (reported in #12058).MCP servers sometimes put a full
data:<mime>;base64,<payload>string in the imagedatafield, or wrap base64 across lines. The chat UI could still render those (tool cards concatenatemimeType+data), but promotion and llama-server decoding rejected them—especially on replay deep in context, which matches the “reprocess whole window then succeed” behavior.Changes
normalize_mcp_image_b64()to peel data-URI prefixes and transport whitespace before decode._png_data_url, and in GGUFimage_urlnormalization (bare base64 is coerced through the same path instead of being passed through unchanged).mcpImageDataUrl()so tool cards do not double-wrap data URIs.Testing
node --test studio/frontend/tests/mcp-images.test.ts— all pass.Closes #12058