adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

McpTool drops structuredContent and non-text content from CallToolResult

Open akbarkanso opened this issue 3 months ago • 4 comments

🔴 Required Information

Describe the Bug:

AbstractMcpTool.wrapCallResult(...) silently discards parts of a successful MCP CallToolResult.

When the result contains at least one TextContent, native McpTool.runAsync(...) returns only the legacy text_output map. It does not expose:

  • CallToolResult.isError on successful results
  • CallToolResult.structuredContent
  • non-text content entries such as images or embedded resources
  • the original ordered content list

This loss is irreversible for callers. An outer BaseTool decorator sees only the already-reduced map and cannot recover the discarded fields without bypassing native McpTool and invoking McpSyncClient itself.

Steps to Reproduce:

  1. Use com.google.adk:google-adk:1.7.1.
  2. Construct a native McpToolset over a streamable-HTTP MCP server.
  3. Have the server advertise a zero-argument tool.
  4. Return this successful tools/call result:
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {"type": "text", "text": "first"},
      {"type": "text", "text": "second"},
      {
        "type": "image",
        "data": "aW1hZ2U=",
        "mimeType": "image/png"
      }
    ],
    "structuredContent": {"count": 2},
    "isError": false
  }
}
  1. Call the discovered native tool through BaseTool.runAsync(...).

Expected Behavior:

Native MCP tools should preserve the complete semantic CallToolResult, including structured content and non-text content, without breaking callers that consume the existing text_output field.

A compatible resolution could be either:

  1. An additive envelope that retains text_output unchanged while also exposing content, structuredContent, isError, and metadata.
  2. A supported result-mapper/adapter hook on McpToolset or McpTool that receives the raw CallToolResult before reduction.

Observed Behavior:

The returned map contains only:

{text_output=[{text=first}, {text=second}]}

structuredContent, image data and MIME type, the original content parts, and explicit non-error state are absent.

The loss is silent. No exception or warning indicates that valid MCP response data was discarded.

Environment Details:

  • ADK Library Version (see maven dependency): 1.7.1
  • MCP Java SDK resolved by ADK: 1.1.2
  • MCP transport: streamable HTTP
  • Java: 21

🟡 Optional Information

Regression:

No

Additional Context:

PR #1078 changed wrapCallResult to serialize the complete CallToolResult, but PR #1090 reverted that change to preserve backward compatibility with text_output.

The requested fix is therefore not to remove text_output. It is to preserve compatibility without silently losing the remaining MCP result fields.

This blocks replacing a custom MCP bridge with native McpToolset: the custom implementation currently preserves text, structuredContent, non-text content parts, and error state, while native McpTool does not.

Minimal Reproduction Code:

N/A. The issue can be reproduced using the MCP response above and a native McpToolset over a streamable-HTTP MCP server.

How often has this issue occurred?:

  • Always (100%)

akbarkanso avatar Aug 20 '26 08:08 akbarkanso

Hi @akbarkanso, thank you for bringing this to our attention and @eyesofish we appreciate your contribution. I have been able to reproduce the behavior. Our team is currently reviewing the issue and proposed fix. we will reach out if we require any further information. Thank you.

hemasekhar-p avatar Aug 21 '26 09:08 hemasekhar-p

Hello @eyesofish. We tried implementing the change and it even landed in https://github.com/google/adk-java/commit/9b128dfba2c2f256bfab927bda46d476b8032443, but had to be reverted in https://github.com/google/adk-java/commit/c897cdb1e027bd3aaf5350e2a063b7e8c30bb8c1, because it affected first party customers.

In the current from the task is infeasible without affecting said customers. Could you specify what the use case that you needed the change for is?

MiloszSobczyk avatar Oct 06 '26 11:10 MiloszSobczyk

Hi @MiloszSobczyk,

Our use case is replacing a custom MCP client bridge with the native McpToolset.

Native McpTool currently reduces CallToolResult before application code can inspect it. As a result, fields such as structuredContent, non-text content, and the explicit isError field cannot be recovered by an outer tool decorator. Our bridge exists to preserve this protocol data before it is reduced.

We currently bypass native McpTool invocation and call the MCP SDK directly:

MCP server
    ↓
McpSyncClient.callTool
    ↓
Raw CallToolResult
    ↓
Custom result mapping
    ↓
ADK-compatible result map

This works because our mapper receives the raw result. However, it also requires us to maintain much more than result conversion:

  • MCP transport creation
  • Client initialization
  • Direct invocation
  • Session handling
  • Lifecycle and shutdown management
  • Schema conversion
  • Failure classification

We do not need to change the existing default result shape. A backward-compatible, opt-in result mapper or hook, configured on McpToolset and given the raw CallToolResult for both synchronous and asynchronous tools, would be sufficient. The default mapper could continue returning the current text_output/error shape.

With such a hook, we could use native discovery, invocation, session recovery, and lifecycle primitives while eliminating our custom MCP client bridge.

akbarkanso avatar Oct 22 '26 09:10 akbarkanso

Hello @akbarkanso, the requested change has been introduced in https://github.com/google/adk-java/commit/4dfe0b57fe2a5548cc9a49d1e06e87ad8b85713e and will be part of the next release.

MiloszSobczyk avatar Nov 09 '26 10:11 MiloszSobczyk