Protocol

Implements MCP protocol framing on top of a pluggable transport, including features like request/response linking, notifications, and progress.

Inheritors

Constructors

Link copied to clipboard
constructor(_options: ProtocolOptions?)

Properties

Link copied to clipboard
var fallbackNotificationHandler: suspend (notification: JSONRPCNotification) -> Unit?

A handler to invoke for any notification types that do not have their own handler installed.

Link copied to clipboard

A handler to invoke for any request types that do not have their own handler installed.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
abstract fun assertCapabilityForMethod(method: Method)

A method to check if a capability is supported by the remote side, for the given method to be called.

Link copied to clipboard

A method to check if a request handler is supported by the local side, for the given method to be handled.

Link copied to clipboard
suspend fun close()

Closes the connection.

Link copied to clipboard
open suspend fun connect(transport: Transport)

Attaches to the given transport, starts it, and starts listening for messages.

Link copied to clipboard
suspend fun notification(notification: SendNotificationT)

Emits a notification, which is a one-way message that does not expect a response.

Link copied to clipboard
open fun onclose()

Callback for when the connection is closed for any reason.

Link copied to clipboard
open fun onerror(error: Throwable)

Callback for when an error occurs.

Link copied to clipboard

Removes the notification handler for the given method.

Link copied to clipboard

Removes the request handler for the given method.

Link copied to clipboard
suspend fun <T : RequestResult> request(request: SendRequestT, options: RequestOptions? = null): T

Sends a request and wait for a response.

Link copied to clipboard
fun <T : Notification> setNotificationHandler(method: Method, handler: (notification: T) -> Deferred<Unit>)

Registers a handler to invoke when this protocol object receives a notification with the given method.

Link copied to clipboard
inline fun <T : Request> setRequestHandler(method: Method, noinline block: suspend (T, RequestHandlerExtra) -> SendResultT?)

Registers a handler to invoke when this protocol object receives a request with the given method.