JSONRPCResponse

Represents a JSON-RPC 2.0 response.

Per the specification, a response contains either a result on success or an error on failure — never both and never neither. This sealed hierarchy makes that invariant unrepresentable at compile time.

Type Parameters

T

The type of the successful result value.

E

The type of the error's optional data field.

Example:

val success: JSONRPCResponse<Int, Nothing> = JSONRPCResponse.Success(
id = RequestId(1),
result = 42,
)
val failure: JSONRPCResponse<Nothing, Nothing> = JSONRPCResponse.Error(
id = RequestId(1),
error = JSONRPCError.methodNotFound("tools/call"),
)

See also

Inheritors

Types

Link copied to clipboard
data class Error<out E>(val id: RequestId?, val error: JSONRPCError<E>) : JSONRPCResponse<Nothing, E>

A failed JSON-RPC 2.0 response carrying an error object.

Link copied to clipboard
data class Success<out T>(val id: RequestId, val result: T) : JSONRPCResponse<T, Nothing>

A successful JSON-RPC 2.0 response carrying a result value.

Properties

Link copied to clipboard
@SerialName(value = "id")
abstract val id: RequestId?

The request identifier echoed back from the original request.

Link copied to clipboard
@SerialName(value = "jsonrpc")
val jsonrpc: String

The JSON-RPC version string. Always "2.0".