Client
A client implementation that communicates using the MCP protocol.
The Client is responsible for connecting to an MCP server, performing initialization, and then participating in the MCP lifecycle (sending requests, handling responses and notifications).
Typical 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()
// Now the client can send requests and handle responses.Functions
Repeatedly calls a paginated endpoint, emitting one set of ITEMS per page until PaginatedResult.nextCursor is null or an error is thrown.
Fetches all available tools from the server using pagination.
Initiates the MCP lifecycle by sending an initialize request with the specified client info and capabilities, and then sending an initialized notification once the server responds. Returns an InitializeResult containing information about the server.
Checks if the client has completed the initialization phase.
Removes a Root from the client.
Removes a Root from the client.
Removes a Root from the client.
Sends a notification (fire-and-forget).
Sends a request and suspends until a corresponding response is received or this coroutine is cancelled.