docs: add missing KDoc comments for public functions, properties, and classes (#621)
This commit is contained in:
parent
c77ebe0c00
commit
bd4cf0c948
9 changed files with 21 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ public class ReadBuffer {
|
||||||
|
|
||||||
private val buffer: Buffer = Buffer()
|
private val buffer: Buffer = Buffer()
|
||||||
|
|
||||||
|
/** Appends raw bytes to the internal buffer for subsequent message parsing. */
|
||||||
public fun append(chunk: ByteArray) {
|
public fun append(chunk: ByteArray) {
|
||||||
buffer.write(chunk)
|
buffer.write(chunk)
|
||||||
}
|
}
|
||||||
|
|
@ -86,6 +87,7 @@ public class ReadBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Clears all buffered data, discarding any partially received messages. */
|
||||||
public fun clear() {
|
public fun clear() {
|
||||||
buffer.clear()
|
buffer.clear()
|
||||||
}
|
}
|
||||||
|
|
@ -93,4 +95,5 @@ public class ReadBuffer {
|
||||||
|
|
||||||
internal fun deserializeMessage(line: String): JSONRPCMessage = McpJson.decodeFromString<JSONRPCMessage>(line)
|
internal fun deserializeMessage(line: String): JSONRPCMessage = McpJson.decodeFromString<JSONRPCMessage>(line)
|
||||||
|
|
||||||
|
/** Serializes a [JSONRPCMessage] to its JSON string representation with a trailing newline. */
|
||||||
public fun serializeMessage(message: JSONRPCMessage): String = McpJson.encodeToString(message) + "\n"
|
public fun serializeMessage(message: JSONRPCMessage): String = McpJson.encodeToString(message) + "\n"
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,7 @@ public class ClientCapabilitiesBuilder @PublishedApi internal constructor() {
|
||||||
*/
|
*/
|
||||||
public fun experimental(block: JsonObjectBuilder.() -> Unit): Unit = experimental(buildJsonObject(block))
|
public fun experimental(block: JsonObjectBuilder.() -> Unit): Unit = experimental(buildJsonObject(block))
|
||||||
|
|
||||||
|
/** Constructs the [ClientCapabilities] instance from the current builder state. */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun build(): ClientCapabilities = ClientCapabilities(
|
internal fun build(): ClientCapabilities = ClientCapabilities(
|
||||||
sampling = sampling,
|
sampling = sampling,
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,10 @@ public sealed interface WithMeta {
|
||||||
*/
|
*/
|
||||||
public typealias ProgressToken = RequestId
|
public typealias ProgressToken = RequestId
|
||||||
|
|
||||||
|
/** Creates a [ProgressToken] from a string value. */
|
||||||
public fun ProgressToken(value: String): ProgressToken = RequestId(value)
|
public fun ProgressToken(value: String): ProgressToken = RequestId(value)
|
||||||
|
|
||||||
|
/** Creates a [ProgressToken] from a numeric value. */
|
||||||
public fun ProgressToken(value: Long): ProgressToken = RequestId(value)
|
public fun ProgressToken(value: Long): ProgressToken = RequestId(value)
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
@ -127,6 +129,7 @@ public sealed interface Reference {
|
||||||
public val type: ReferenceType
|
public val type: ReferenceType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Discriminator for [Reference] subtypes used in completion and other operations. */
|
||||||
@Serializable
|
@Serializable
|
||||||
public enum class ReferenceType(public val value: String) {
|
public enum class ReferenceType(public val value: String) {
|
||||||
@SerialName("ref/prompt")
|
@SerialName("ref/prompt")
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ public abstract class MediaContentBuilder {
|
||||||
meta = buildJsonObject(block)
|
meta = buildJsonObject(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constructs the [MediaContent] instance from the current builder state. */
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal abstract fun build(): MediaContent
|
internal abstract fun build(): MediaContent
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
|
/** Discriminator values for the polymorphic [ContentBlock] hierarchy. */
|
||||||
@Serializable
|
@Serializable
|
||||||
public enum class ContentTypes(public val value: String) {
|
public enum class ContentTypes(public val value: String) {
|
||||||
@SerialName("text")
|
@SerialName("text")
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,12 @@ public fun RequestId(value: Long): RequestId = RequestId.NumberId(value)
|
||||||
@Serializable(with = RequestIdPolymorphicSerializer::class)
|
@Serializable(with = RequestIdPolymorphicSerializer::class)
|
||||||
public sealed interface RequestId {
|
public sealed interface RequestId {
|
||||||
|
|
||||||
|
/** A string-based request identifier. */
|
||||||
@JvmInline
|
@JvmInline
|
||||||
@Serializable
|
@Serializable
|
||||||
public value class StringId(public val value: String) : RequestId
|
public value class StringId(public val value: String) : RequestId
|
||||||
|
|
||||||
|
/** A numeric request identifier. */
|
||||||
@JvmInline
|
@JvmInline
|
||||||
@Serializable
|
@Serializable
|
||||||
public value class NumberId(public val value: Long) : RequestId
|
public value class NumberId(public val value: Long) : RequestId
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,7 @@ public data class CreateMessageResult(
|
||||||
override val meta: JsonObject? = null,
|
override val meta: JsonObject? = null,
|
||||||
) : ClientResult
|
) : ClientResult
|
||||||
|
|
||||||
|
/** The reason why the LLM stopped generating tokens. */
|
||||||
@JvmInline
|
@JvmInline
|
||||||
@Serializable
|
@Serializable
|
||||||
public value class StopReason(public val value: String) {
|
public value class StopReason(public val value: String) {
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ public open class Server(
|
||||||
block(this)
|
block(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Closes this server, shutting down the notification service and all active sessions. */
|
||||||
public suspend fun close() {
|
public suspend fun close() {
|
||||||
logger.debug { "Closing MCP server" }
|
logger.debug { "Closing MCP server" }
|
||||||
notificationService.close()
|
notificationService.close()
|
||||||
|
|
@ -718,6 +719,7 @@ public open class Server(
|
||||||
|
|
||||||
// Start the ServerSession / ClientConnection redirection section
|
// Start the ServerSession / ClientConnection redirection section
|
||||||
|
|
||||||
|
/** Returns the [ClientConnection] for the session identified by [sessionId]. */
|
||||||
public fun clientConnection(sessionId: String): ClientConnection =
|
public fun clientConnection(sessionId: String): ClientConnection =
|
||||||
sessionRegistry.getSession(sessionId).clientConnection
|
sessionRegistry.getSession(sessionId).clientConnection
|
||||||
|
|
||||||
|
|
@ -827,18 +829,22 @@ public open class Server(
|
||||||
// End the ServerSession / ClientConnection redirection section
|
// End the ServerSession / ClientConnection redirection section
|
||||||
|
|
||||||
// Start the notification handling section
|
// Start the notification handling section
|
||||||
|
|
||||||
|
/** Registers a notification [handler] for the given [method] on all active sessions. */
|
||||||
public fun <T : Notification> setNotificationHandler(method: Method, handler: (notification: T) -> Deferred<Unit>) {
|
public fun <T : Notification> setNotificationHandler(method: Method, handler: (notification: T) -> Deferred<Unit>) {
|
||||||
sessions.forEach { (_, session) ->
|
sessions.forEach { (_, session) ->
|
||||||
session.setNotificationHandler(method, handler)
|
session.setNotificationHandler(method, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes the notification handler for the given [method] from all active sessions. */
|
||||||
public fun removeNotificationHandler(method: Method) {
|
public fun removeNotificationHandler(method: Method) {
|
||||||
sessions.forEach { (_, session) ->
|
sessions.forEach { (_, session) ->
|
||||||
session.removeNotificationHandler(method)
|
session.removeNotificationHandler(method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Registers a notification [handler] for the given [method] on a specific session. */
|
||||||
public fun <T : Notification> setNotificationHandler(
|
public fun <T : Notification> setNotificationHandler(
|
||||||
sessionId: String,
|
sessionId: String,
|
||||||
method: Method,
|
method: Method,
|
||||||
|
|
@ -847,6 +853,7 @@ public open class Server(
|
||||||
sessionRegistry.getSessionOrNull(sessionId)?.setNotificationHandler(method, handler)
|
sessionRegistry.getSessionOrNull(sessionId)?.setNotificationHandler(method, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes the notification handler for the given [method] from a specific session. */
|
||||||
public fun removeNotificationHandler(sessionId: String, method: Method) {
|
public fun removeNotificationHandler(sessionId: String, method: Method) {
|
||||||
sessionRegistry.getSessionOrNull(sessionId)?.removeNotificationHandler(method)
|
sessionRegistry.getSessionOrNull(sessionId)?.removeNotificationHandler(method)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -418,6 +418,7 @@ public class StreamableHttpServerTransport(private val configuration: Configurat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handles an HTTP GET request by establishing a standalone SSE stream for server-initiated notifications. */
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount")
|
||||||
public suspend fun handleGetRequest(session: ServerSSESession?, call: ApplicationCall) {
|
public suspend fun handleGetRequest(session: ServerSSESession?, call: ApplicationCall) {
|
||||||
// NOTE: enableJsonResponse only controls how POST responses are delivered (JSON vs. SSE).
|
// NOTE: enableJsonResponse only controls how POST responses are delivered (JSON vs. SSE).
|
||||||
|
|
@ -465,6 +466,7 @@ public class StreamableHttpServerTransport(private val configuration: Configurat
|
||||||
awaitCancellation()
|
awaitCancellation()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handles an HTTP DELETE request by closing the session and the transport. */
|
||||||
public suspend fun handleDeleteRequest(call: ApplicationCall) {
|
public suspend fun handleDeleteRequest(call: ApplicationCall) {
|
||||||
if (!validateSession(call) || !validateProtocolVersion(call)) return
|
if (!validateSession(call) || !validateProtocolVersion(call)) return
|
||||||
sessionId?.let { onSessionClosed?.invoke(it) }
|
sessionId?.let { onSessionClosed?.invoke(it) }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue