ToolResponse

The outcome of a tool call: either the final CallToolResult, or — on a stateless (MRTR) request — a set of InputRequests the client must satisfy and resubmit. There is no suspension or shared state: inputRequired simply ends this request, and the client opens a fresh one carrying the answers.

Members

Functions

forVersion
ToolResponse forVersion(ProtocolVersion v)

Project the final CallToolResult to the negotiated protocol version so version-gated fields are not emitted to peers that don't understand them. CallToolResult.structuredContent is a 2025-06-18+ field and is stripped for 2024-11-05 / 2025-03-26. An InputRequiredResult is draft-only (MRTR): its {inputRequests, [requestState]} shape carries no content and exists only on versions whose schema permits it. Emitting it to a non-MRTR peer, whose CallToolResult requires content, is a programming error (a handler ignoring the documented stateless contract), so reject it rather than projecting an off-schema result onto the wire.

Static functions

complete
ToolResponse complete(T value)

Convenience: build a final result from a typed value. Serialises value to JSON and uses it as the result's structuredContent, defaulting the human-readable content to a single text block holding that same JSON. The serialisation is done inline here (independent of any CallToolResult.structured!T helper) so this overload stays compilable on its own.

complete
ToolResponse complete(CallToolResult r)

The handler is done; r is the final result.

inputRequired
ToolResponse inputRequired(InputRequest[] requests, T state)

As inputRequired, but encodes a typed state as the opaque requestState. Serialises state to JSON and stores its string form. ENCODING CONTRACT: the stored value is serializeToJson(state).toString(), which RequestContext.requestStateAs!T() decodes via deserializeJson!T(parseJsonString(state)). Constrained off string so it does not collide with the verbatim-string overload above.

Mixed In Members

From mixin InputRequiredPart ireq

inputRequired
typeof(this) inputRequired(InputRequest[] requests)

The handler needs input; the client must gather it and resubmit with the matching inputResponses.

inputRequired
typeof(this) inputRequired(InputRequest[] requests, string requestState)

As inputRequired, but also attaches an opaque requestState (SEP-2322): a stateless draft server encodes whatever context it needs to resume the call into this blob, which the client echoes verbatim on the retry and the handler reads back via RequestContext.requestState.

needsInput
bool needsInput()

Whether this outcome asks the client for more input.

inputRequests
const(InputRequest)[] inputRequests()

The MRTR inputRequests this outcome carries (empty unless needsInput). Read by the dispatch path so it can drop requests whose kind the client never declared.

requestState
string requestState()

The opaque MRTR requestState this outcome carries (empty unless set).

withInputRequests
typeof(this) withInputRequests(InputRequest[] reqs)

Return a copy of this input-required outcome with its inputRequests replaced by reqs (preserving requestState). Used by the dispatch path after filtering out unsupported request kinds.

toJson
Json toJson()

The JSON-RPC result payload (the final result, or an InputRequiredResult).