Skip to content

MCP tool results containing ImageContent reach the model as base64 text instead of image parts #8118

Description

@omnomkar

🔴 Required Information

Describe the Bug:
When an MCP tool returns an ImageContent block, ADK never turns it into an image the model can see. McpTool._run_async_impl dumps the CallToolResult into a plain dict (mcp_tool.py, result = _dump_mcp_model(response)), so the image becomes {"type": "image", "data": "<base64>", "mimeType": "image/png"}. _extract_multimodal_parts in flows/llm_flows/tools/_caller.py only extracts types.Part objects (_as_function_response_part), so nothing is moved into function_response.parts and the base64 stays inside the JSON response.

Effects:

  • Gemini receives the image as a base64 string inside the function response.
  • On Claude, _part_to_message_block in models/anthropic_llm.py serializes non-text content items with str(item), so the tool result is a Python dict repr with the full base64, sent as text.
  • In both cases the model can't see the image, and a real screenshot costs a large number of text tokens.
  • MultimodalToolResultsPlugin does not help: its after_tool_callback only acts on types.Part (or a list of them), and an MCP result is a dict.

A plain function tool returning types.Part.from_bytes(...) works correctly (the image lands in function_response.parts), so the gap is specific to the MCP path.

Steps to Reproduce:

  1. Save server.py and repro.py (below) in the adk-python repo root.
  2. From the repo root, run python repro.py. It uses MockModel from tests/unittests/testing_utils.py, so no API key is needed.

Expected Behavior:
The image from the MCP tool appears in function_response.parts as an image/png part, as it does for function tools that return a types.Part.

Observed Behavior:
Output of repro.py:

function_response.parts: None
response content types: ['image', 'text']

Extended checks from a fuller version of the same script (same setup with a 64x64 PNG, MockModel, second model request inspected):

McpToolset + MultimodalToolResultsPlugin:
  function_response.parts: count=0 (unchanged)

Same request -> anthropic_llm.content_to_message_param:
  tool_result.content is a STRING: "{'type': 'image', 'data': 'iVBORw0KGgo..."

Control, plain function tool returning types.Part.from_bytes:
  function_response.parts: count=1, mime_types=['image/png']

Environment Details:

  • ADK Library Version: 2.14.0 (main @ e5dd820)
  • Desktop OS: Linux (Ubuntu 24.04.1, WSL2)
  • Python Version: 3.11.18
  • MCP SDK: 2.3.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: MockModel for the repro; affects the Gemini and Claude paths

🟡 Optional Information

Regression:
No. The behavior appears long-standing; #2096 reported images from tool calls not reaching the model in July 2025.

Additional Context:
#2096 was closed as solved by a user-side plugin; later comments on it report that MCP ImageContent still never reaches the model.

Proposed fix: in McpTool, convert ImageContent items into types.Part before returning, so the existing _extract_multimodal_parts moves them into function_response.parts. Both adapters already map that field (the Anthropic adapter sends images and PDFs from it as tool result blocks). Text items and structuredContent stay in the response. The conversion would need to work with both MCP SDK 1.x and 2.x field names, which the module already handles. AudioContent and blob EmbeddedResource could follow the same path in a follow-up.

Would a PR along these lines be welcome? I'm happy to implement it with tests.

Minimal Reproduction Code:

# server.py (mcp 2.x; with mcp 1.x, import FastMCP and Image from mcp.server.fastmcp instead)
from mcp.server.mcpserver import Image, MCPServer

PNG_1x1 = bytes.fromhex(
    "89504e470d0a1a0a0000000d4948445200000001000000010806000000"
    "1f15c4890000000d49444154789c63f8cfc0f01f00050001ff89993d1d"
    "0000000049454e44ae426082"
)
mcp = MCPServer(name="screenshot_server")

@mcp.tool()
def screenshot():
  """Takes a screenshot and returns it as a PNG image."""
  return [Image(data=PNG_1x1, format="png"), "Captured a screenshot."]

if __name__ == "__main__":
  mcp.run(transport="stdio")
# repro.py (run from the adk-python repo root)
import asyncio, sys
from google.adk.agents.llm_agent import LlmAgent
from google.adk.runners import InMemoryRunner
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
from google.genai import types
from mcp import StdioServerParameters
from tests.unittests.testing_utils import MockModel

async def main():
  model = MockModel.create(responses=[
      types.Part.from_function_call(name="screenshot", args={}), "done"])
  toolset = McpToolset(connection_params=StdioConnectionParams(
      server_params=StdioServerParameters(
          command=sys.executable, args=["server.py"]), timeout=20))
  agent = LlmAgent(name="a", model=model, tools=[toolset])
  runner = InMemoryRunner(agent=agent, app_name="repro")
  session = await runner.session_service.create_session(
      app_name="repro", user_id="u")
  async for _ in runner.run_async(user_id="u", session_id=session.id,
      new_message=types.UserContent("take a screenshot")):
    pass
  await runner.close(); await toolset.close()

  fr = next(p.function_response for c in model.requests[1].contents
            for p in c.parts or [] if p.function_response)
  print("function_response.parts:", fr.parts)
  print("response content types:",
        [i["type"] for i in fr.response["content"]])

asyncio.run(main())

How often has this issue occurred?:

  • Always (100%)

Activity

  1. its-amann commented on Nov 13, 2026

    @its-amann
    Contributor

    i can take this. plan is to turn ImageContent items from McpTool results into types.Part (both mcp 1.x and 2.x field names) so they land in function_response.parts, with tests for the gemini and anthropic paths

  2. added
    mcp
    on Nov 17, 2026
  3. sanketpatil06 commented on Nov 23, 2026

    @sanketpatil06

    Hi @omnomkar, thanks for the detailed report and repro. If you have a fix in mind, feel free to raise a PR, we will be happy to review it.
    @its-amann, I see you've also offered to work on this. Could you two agree on who takes it so we don't get duplicate PRs? The approach you've both described looks good: Convert MCP ImageContent items into types.Part so they land in function_response.parts, Handle both MCP SDK 1.x and 2.x field names. Add tests for the Gemini and Anthropic paths.

  4. omnomkar commented on Nov 25, 2026

    @omnomkar
    Author

    Opened #8363 for this. It converts ImageContent items to types.Part in McpTool._run_async_impl right after _dump_mcp_model, so _extract_multimodal_parts moves them into function_response.parts. It works under MCP SDK 1.x and 2.x, and has tests for the Gemini path and the Anthropic path.

    @its-amann, sorry to step in after your comment. If you'd still like to contribute here, the AudioContent / blob EmbeddedResource follow-up is open and would make a natural separate PR, and I'm happy to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

mcp

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions