Interface ToolResult
- All Known Implementing Classes:
ToolResult.Deferred,ToolResult.Error,ToolResult.InputRequired,ToolResult.Success,ToolResult.WithMeta
public sealed interface ToolResult
permits ToolResult.Success, ToolResult.Error, ToolResult.WithMeta, ToolResult.InputRequired, ToolResult.Deferred
Outcome of a tool invocation: success, error, input-required, or deferred.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordSentinel returned by a task-augmented handler that defers completion to the caller.static final recordA failed invocation carrying a human-readable error message.static final recordSignals that completing the tool call requires additional input from the caller.static final recordA successful invocation, carrying an optional structured value and its content blocks.static final recordWraps another result with request-level_metaentries. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolResultblocks(ContentBlock... blocks) Deprecated, for removal: This API element is subject to removal in a future version.static ToolResultcontent(ContentBlock... blocks) Creates a successful result containing the given content blocks.static ToolResultempty()Creates a successful result with no structured value and no content.static ToolResultCreates a failed result with the given error message.static ToolResultinputRequired(Map<String, ? extends InputRequest> reqs, @Nullable String state) Creates a result that requests additional input from the caller before the tool call can complete.static ToolResultCreates a success result carryingpayloadas structured content with no text block.static ToolResultCreates a success result carryingpayloadas structured content plus an explicit human-readable text block.static ToolResultCreates a success result with a pre-serialized JSON payload.static ToolResultstructured(Object payload) Alias forof(Object)with a name that states what the payload becomes (structured content) rather than how it's constructed.static ToolResultstructured(Object payload, String text) Alias forof(Object, String)with a name that states what the payload becomes (structured content) rather than how it's constructed.static ToolResultCreates a successful result containing a single text content block.default ToolResultReturns a copy of this result with a single_metaentry set.default ToolResultReturns a copy of this result withmmerged into its_metaentries; returns this unchanged whenmis empty.
-
Method Details
-
withMeta
Returns a copy of this result withmmerged into its_metaentries; returns this unchanged whenmis empty.- Parameters:
m- the_metaentries to merge in- Returns:
- a result carrying the merged metadata
-
withMeta
Returns a copy of this result with a single_metaentry set.- Parameters:
key- the_metakeyvalue- the_metavalue- Returns:
- a result carrying the added metadata entry
-
text
Creates a successful result containing a single text content block.- Parameters:
t- the text- Returns:
- a successful tool result
-
content
Creates a successful result containing the given content blocks.- Parameters:
blocks- the content blocks- Returns:
- a successful tool result
-
blocks
@Deprecated(since="1.0.0-beta.15", forRemoval=true) static ToolResult blocks(ContentBlock... blocks) Deprecated, for removal: This API element is subject to removal in a future version.Creates a successful result containing the given content blocks.- Parameters:
blocks- the content blocks- Returns:
- a successful tool result
-
of
Creates a success result carryingpayloadas structured content plus an explicit human-readable text block.- Parameters:
payload- the structured payloadtext- the text content for the content block- Returns:
- a successful tool result
-
structured
Alias forof(Object, String)with a name that states what the payload becomes (structured content) rather than how it's constructed.- Parameters:
payload- the structured payloadtext- the text content for the content block- Returns:
- a successful tool result
-
of
Creates a success result carryingpayloadas structured content with no text block.The server emits the serialized JSON of
payloadas the text content at encode time (MCP backwards-compat for structured results). Useof(Object, String)to supply an explicit human-readable text block instead. -
structured
Alias forof(Object)with a name that states what the payload becomes (structured content) rather than how it's constructed.- Parameters:
payload- the structured payload- Returns:
- a successful tool result
-
error
Creates a failed result with the given error message.- Parameters:
message- the error message- Returns:
- a failed tool result
-
empty
Creates a successful result with no structured value and no content. -
raw
Creates a success result with a pre-serialized JSON payload. The bytes skip the Jackson value-to-tree conversion of ordinary structured values and are parsed once at envelope encoding (plus once more when output schema validation is active).- Parameters:
json- a pre-serialized JSON object stringtext- the text content for the content block
-
inputRequired
Creates a result that requests additional input from the caller before the tool call can complete.- Parameters:
reqs- the requested inputs, keyed by request idstate- an opaque state token to echo back with the caller's response, ornull- Returns:
- a result signaling that input is required
-
content(ContentBlock...)