Practical technical guides / AI engineering: MCP interoperability in ADK Java (google/adk-java commit 4dfe0b5, 8 November 2026, unreleased as of 9 November)

ADK Java Can Now Keep MCP structuredContent: The Opt-In CallToolResultMapper and What the Model Receives

ADK Java 1.14.0 sends the model only MCP text and drops structuredContent. Recorded case by case, plus the opt-in CallToolResultMapper added on main on 8 November 2026.

By Sandeep Belgavi · Published 2026-11-09

ADK Java 1.14.0 sends the model only MCP text and drops structuredContent. Recorded case by case, plus the opt-in CallToolResultMapper added on main on 8 November 2026.

What an ADK Java MCP tool sends the model

An MCP tool call returns a CallToolResult: a list of content blocks (text, images, audio, embedded resources), an optional structuredContent object that matches the tool's output schema, an isError flag and optional _meta. A client decides how much of that reaches the model.

Through ADK Java 1.14.0, released on 2 November 2026, every MCP tool converts the result with one fixed helper, AbstractMcpTool.wrapCallResult. On 8 November 2026, commit 4dfe0b5 on the main branch of google/adk-java added an opt-in CallToolResultMapper so an application can choose. As of 9 November the commit was unreleased; this guide reads it from the repository and records the 1.14.0 behaviour it changes.

The companion probe calls the real 1.14.0 helper with seven synthetic results from a Belgavi's Book Store order tool, and prints what the model would receive. It also re-creates the mapper's fullResult() output with the same MCP SDK call the commit uses. It does not run an agent or call a model.

The 1.14.0 default, case by case

Reading wrapCallResult at v1.14.0 and running it gives these rules:

  • If isError is true, the model receives {"error": "Tool execution failed. Details: ..."} with the text of the first content block only.
  • If there is no content, the model receives an empty map {}.
  • Otherwise, every text block is parsed as a JSON object, or wrapped as {"text": ...} if it is not one, and the list is returned under text_output.
  • Non-text blocks are dropped. If there is no text at all, the model receives an error saying the content is not TextContent, followed by content_details holding the blocks' toString().
  • structuredContent is never read.

The recorded results for a tool called find_orders make the consequences concrete:

CaseWhat 1.14.0 sends the model
JSON text plus the same object as structuredContentthe parsed JSON under text_output; fine
Summary text "Found 2 orders for Geetha." plus structuredContentonly {"text": "Found 2 orders for Geetha."}; the orders are lost
structuredContent with no content blocks{}
Text holding a JSON array of order idsthe array as an unparsed string, because only objects are parsed
An image and a captionthe caption only; the image is dropped silently
An image onlyan error message plus the image's base64 data in content_details
isError with two text blocksthe first block only; the hint in the second is lost

Two of these deserve attention. A server that sends a short human-readable summary as text and the real data only as structuredContent is allowed by the MCP specification, which recommends but does not require a serialised copy in text. It works in clients that read structuredContent and gives an ADK Java 1.14.0 agent nothing to reason with. And an image-only result does not just fail: the error text includes the whole base64 payload, so a large image becomes a large block of meaningless text in the model's context.

The opt-in mapper

The commit adds a functional interface in com.google.adk.tools.mcp:

@FunctionalInterface
public interface CallToolResultMapper {
  Map<String, Object> map(Tool mcpTool, CallToolResult callToolResult);

  static CallToolResultMapper textOutput(ObjectMapper objectMapper) { ... }   // the 1.14.0 behaviour
  static CallToolResultMapper fullResult() { ... }                            // the whole result as MCP JSON
}

Both McpToolset.Builder and McpAsyncToolset.Builder gain callToolResultMapper(...). Without it, tools keep the old behaviour, so upgrading changes nothing until you opt in. The interface's documentation states the contract plainly:

  • the response becomes the function response sent to the model, so it must not be null and its values must serialise to JSON (the tool enforces non-null with a precondition check);
  • if the mapper throws, the tool call fails and is not retried: the commit moves mapping after the retry loop so that a failing mapper cannot call the tool again;
  • the default mapper's maps are immutable, so a custom mapper that wants to add a field must copy first.

fullResult() converts the result with the MCP SDK's own JSON mapper, so the model sees the wire format: content, plus structuredContent, isError and _meta when present. Its documentation warns about two costs, and the probe shows both. A server that repeats structuredContent as text sends the same data twice: the first case grew from 123 characters with the default to 308 with fullResult(). Images reach the model as base64 text, which it cannot read as an image.

Reshape after the tool, before the model

The commit's sample, examples/mcpfullresult, pairs fullResult() with an after-tool callback that keeps only structuredContent. That is the pattern to copy: let the mapper keep everything, then decide per tool what the model needs. A sketch for the store's order server, following the shape of that sample and written against the commit's API (unreleased as of 9 November, so names could change before release):

McpToolset orders = McpToolset.builder()
    .connectionParams(ordersServer)
    .callToolResultMapper(CallToolResultMapper.fullResult())
    .build();

LlmAgent agent = LlmAgent.builder()
    .name("returns_helper")
    .model("gemini-2.5-flash")
    .tools(orders)
    .afterToolCallbackSync((invocation, tool, args, context, response) ->
        keepStructured((Map<?, ?>) response))
    .build();

static Optional<Map<String, Object>> keepStructured(Map<?, ?> result) {
  Object structured = result.get("structuredContent");
  if (structured == null || Boolean.TRUE.equals(result.get("isError"))) {
    return Optional.empty();                       // errors and plain results pass through unchanged
  }
  return Optional.of(Map.of("result", structured)); // drop the duplicate text
}

In the probe, keeping only structuredContent brought the first case down to 116 characters and turned the summary-text case from a useless sentence into the two orders. For an error, the full result keeps both text blocks, so the model sees the server's hint about which orders exist.

Write your own mapper instead when you need per-tool rules that do not fit a callback, for example truncating large arrays with a visible marker, or converting an image into a short description produced elsewhere. Keep mappers pure and fast: they run on every call, and an exception fails the call without a retry.

Migration steps

  1. Inventory what your MCP servers return. For each tool, record whether it sends text only, text plus structuredContent, structured content only, or non-text blocks. The MCP specification requires a tool that declares an outputSchema to return structuredContent that conforms to it, and recommends, without requiring, a serialised copy in a text block.
  2. Find the silent losses. Any tool whose useful data is only in structuredContent or in a non-text block is currently returning less to an ADK Java agent than its authors intended. Those are the tools to opt in first.
  3. Pin before you opt in. The mapper is on main, not in 1.14.0. Use a release that contains commit 4dfe0b5, check the class and builder method exist, and keep a test that fails if they change.
  4. Opt in per toolset, then reshape per tool. Start with fullResult() plus an after-tool callback; move to a custom mapper only for tools that need it.
  5. Measure context size. Compare response sizes before and after on recorded calls. The duplicate-text case can more than double tool output tokens.

Failure modes

  • Mapper returns null or non-JSON values. The call fails. Unit-test mappers with every content shape your servers can send.
  • Mapper throws on an unexpected block type. The call fails and is not retried. Prefer a fallback branch to an exception.
  • Base64 sent to a text model. Large images become large meaningless strings. Strip or replace binary blocks before the model sees them.
  • Error details lost or over-shared. The default keeps only the first error block; fullResult() keeps all of them, which may include server internals. Decide what error text an agent should see.
  • Callback ordering. An after-tool callback that returns a value replaces the tool response for the model; make sure only one layer reshapes a given tool.

Verification

The companion probe (Java 17, Maven, google-adk 1.14.0 with MCP SDK 2.0.0) prints three lines per case: the real 1.14.0 default, the re-created fullResult() output and a reshaped version, with their sizes. Its recording is checked in; rerun it after upgrading and compare the default lines, which should not change unless you opt in. When a release contains the mapper, replace the re-creation with the real CallToolResultMapper.fullResult() and confirm the two match.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/java/mcp_result_mapping. Views are my own and do not represent any employer, past or present.