Package org.mcpjava.server.tools
Interface ToolResponse
- All Superinterfaces:
MetaCarrier
The response to a tool call
The result can represent either success or an error. In both cases it can contain structured and unstructured content.
Returning a ToolResponse from a Tool-annotated method gives more control over the
response that's returned to the client.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder for creating tool responses -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolResponse.Builderbuilder()Create a builder for a newToolResponsecontent()The unstructured result data.booleanisError()Whether or not the tool call resulted in an error.static ToolResponseCreates a new errorToolResponsewith a single text content block containing the error message.static ToolResponseofStructured(Object structuredContent) Creates a new successfulToolResponsewith structured content.static ToolResponseCreates a new successfulToolResponsewith a single text content block.The structured response data.Methods inherited from interface org.mcpjava.server.MetaCarrier
metadata
-
Method Details
-
content
List<ContentBlock> content()The unstructured result data.A tool call can return one or more unstructured
contentobjects as the result of a tool call.- Returns:
- the result contents
-
structuredContent
The structured response data.Tools which declare an output schema return structured content. The structured content will be converted to JSON using a platform-specific mechanism.
- Returns:
- the structured content, or an empty
Optionalif there is no structured content
-
isError
boolean isError()Whether or not the tool call resulted in an error.When a tool call results in an error, the content should describe the error.
- Returns:
trueif the response represents an error,falseotherwise
-
builder
Create a builder for a newToolResponse- Returns:
- the new
ToolResponsebuilder
-
ofText
Creates a new successfulToolResponsewith a single text content block.- Parameters:
text- the text content- Returns:
- the new tool response
-
ofError
Creates a new errorToolResponsewith a single text content block containing the error message.- Parameters:
error- the error message- Returns:
- the new tool response
-
ofStructured
Creates a new successfulToolResponsewith structured content.- Parameters:
structuredContent- the structured content- Returns:
- the new tool response
-