Interface CallToolResultMapper

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CallToolResultMapper
A converter from the McpSchema.CallToolResult of an MCP tool call to the response of the ADK tool.

By default, MCP tools return only the text content of a result, under text_output. Set a mapper on McpToolset.Builder or McpAsyncToolset.Builder to return other parts of the result, such as structuredContent or images.

  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a mapper that returns the whole result in the MCP wire format: content, plus structuredContent, isError and _meta when set.
    map(io.modelcontextprotocol.spec.McpSchema.Tool mcpTool, io.modelcontextprotocol.spec.McpSchema.CallToolResult callToolResult)
    Returns the response of mcpTool for callToolResult, including results with isError set.
    textOutput(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Returns the default mapper, which keeps only the text content under text_output, or returns an error.
  • Method Details

    • map

      Map<String,Object> map(io.modelcontextprotocol.spec.McpSchema.Tool mcpTool, io.modelcontextprotocol.spec.McpSchema.CallToolResult callToolResult)
      Returns the response of mcpTool for callToolResult, including results with isError set.

      The response becomes the function response sent to the model, so it must not be null and its values must serialize to JSON. If the mapper throws, the tool call fails and is not retried.

    • textOutput

      static CallToolResultMapper textOutput(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Returns the default mapper, which keeps only the text content under text_output, or returns an error. It parses each text item as JSON with objectMapper, or keeps it under text. Its responses are immutable, so a custom mapper copies one before adding other parts of the result.
    • fullResult

      static CallToolResultMapper fullResult()
      Returns a mapper that returns the whole result in the MCP wire format: content, plus structuredContent, isError and _meta when set. An afterToolCallback can then reshape it, as the examples/mcpfullresult sample does. Servers that repeat structuredContent as text send it to the model twice, and images reach the model as base64 text, which it cannot read.