Server
A Model Context Protocol (MCP) server implementation that handles MCP requests from a connected client via a specified Transport.
Example usage:
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()Tools and prompts can be added at build time via Builder.withTool, Builder.withTools, Builder.withPrompt, and Builder.withPrompts. They can also be added or removed dynamically at runtime if needed.
Functions
Dynamically adds a new tool to the server at runtime and sends a ToolListChangedNotification
Dynamically removes a previously added prompt by its @McpPrompt-annotated function reference.
Dynamically removes a previously added tool by its @McpTool-annotated function reference and sends a ToolListChangedNotification
Sends a notification (fire-and-forget).
Sends a request and suspends until a corresponding response is received or this coroutine is cancelled.