ToolResult

data class ToolResult(val isSuccess: Boolean, val data: Map<String, Any?>?, val errorMessage: String?, val images: List<ToolImage> = emptyList())

The outcome of an McpTool.execute call. Exactly one of data / errorMessage is meaningful, selected by isSuccess. The protocol layer maps a result onto the MCP tools/call response: success becomes content, failure becomes an isError: true payload.

Construct via the success / error factories rather than the primary constructor.

Constructors

Link copied to clipboard
constructor(isSuccess: Boolean, data: Map<String, Any?>?, errorMessage: String?, images: List<ToolImage> = emptyList())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val data: Map<String, Any?>?

Result map on success; its keys are part of the tool's wire contract. Null on failure.

Link copied to clipboard

Failure description on error; null on success. See the error overloads for the prose vs. short-form (code: detail) conventions.

Link copied to clipboard

Images to send to MCP clients as image content blocks. Attach them with withImage; in-process callers still read the base64 from data.

Link copied to clipboard

Whether the tool completed its work.

Functions

Link copied to clipboard
fun withImage(dataKey: String, mimeType: String): ToolResult

Marks the base64 string at data[dataKey] as an image of mimeType. Over MCP it is sent as an image content block and dataKey is left out of the JSON text and structuredContent, so the payload travels once and clients render it as a picture. data is unchanged, so in-process callers keep reading data[dataKey]. No-op if the key isn't a string.