Builder

class Builder

Builder for constructing a Server instance.

All configuration is done via fluent API calls, and once build is called, you get a fully configured Server ready to be started with Server.start.

Example:

val server = Server.Builder()
.withPageSize(25)
.withPrompt(::myPromptFunction)
.withResourceProvider(myLocalFileProvider)
.withServerInfo("MyServer", "1.0.0")
.withTool(::myToolFunction)
.withTransport(myTransport)
.withTransportLogger(
logIncoming = { msg -> println("SERVER INCOMING: $msg") },
logOutgoing = { msg -> println("SERVER OUTGOING: $msg") },
)
.build()

server.start()

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun build(): Server

Builds the Server instance.

Link copied to clipboard
Link copied to clipboard

Sets the coroutine context (or dispatcher) for the server's internal coroutines. Defaults to Dispatchers.Default if not set.

Link copied to clipboard

Sets the default page size for paginated responses. Defaults to 20.

Link copied to clipboard
fun withPrompt(promptFunction: KFunction<*>): Server.Builder

Registers a prompt by referencing its @McpPrompt-annotated function.

Link copied to clipboard
fun withPrompts(vararg promptFunctions: KFunction<*>): Server.Builder

Registers multiple prompts by referencing their @McpPrompt-annotated functions.

Link copied to clipboard

Registers a resource provider that can list/read resources.

Link copied to clipboard

Sets the server's name and version, reported in the initialize response. Defaults to "MyServer" and "1.0.0" if not provided.

Link copied to clipboard
fun withTool(toolFunction: KFunction<*>): Server.Builder

Registers a tool by referencing its @McpTool-annotated function.

Link copied to clipboard
fun withTools(vararg toolFunctions: KFunction<*>): Server.Builder

Registers multiple tools by referencing their @McpTool-annotated functions.

Link copied to clipboard

Sets the Transport used by the server to communicate with clients. This must be called before build, or an error is thrown.

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

Sets separate loggers for incoming and outgoing transport messages.