Builder

class Builder

Builder for creating a Client instance.

Usage:

val client = Client.Builder()
.withClientInfo("MyCustomClient", "1.0.0")
.withRoot(Root(uri = "file:///home/user/project", name = "My Project"))
.withSamplingProvider { createMessageParams ->
// ...
}
.withTransport(StdioTransport()))
.withTransportLogger(
logIncoming = { msg -> println("CLIENT INCOMING: $msg") },
logOutgoing = { msg -> println("CLIENT OUTGOING: $msg") },
)
.build()

client.start()
client.initialize()

Roots capabilities is enabled by default and returns an empty list.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun build(): Client

Builds the Client instance.

Link copied to clipboard

Sets the client's name and version returned during initialization. Defaults to "MyClient" and "1.0.0" if not set.

Link copied to clipboard

Sets a coroutine dispatcher or context for the client's internal coroutines. Defaults to Dispatchers.Default.

Link copied to clipboard
fun withOnToolsChanged(onToolsChanged: suspend (List<Tool>) -> Unit): Client.Builder

Callback that is triggered when the server changes the list of tools. Useful for updating the tools when building a full client application.

Link copied to clipboard

Callback that should ask the user for permission to approve the given ClientApprovable. The callback should return true if the user approves the request, false otherwise.

Link copied to clipboard

Adds a Root the client.

Link copied to clipboard

Adds a list of Root instances to the client.

Link copied to clipboard

Adds a SamplingProvider to the client's capabilities.

Link copied to clipboard

Sets the Transport used by this client. This is mandatory and must be called before build.

Link copied to clipboard
fun withTransportLogger(logIncoming: suspend (String) -> Unit = {}, logOutgoing: suspend (String) -> Unit = {}): Client.Builder

Sets separate loggers for incoming and outgoing transport messages.