Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ kover {
reports {
filters {
includes.classes("io.modelcontextprotocol.kotlin.sdk.*")
excludes.classes("io.modelcontextprotocol.kotlin.sdk.models.*") // temporary
excludes.classes("io.modelcontextprotocol.kotlin.sdk.models.infrastructure.*") // generated
}
total {
log {
Expand Down
41 changes: 24 additions & 17 deletions kotlin-sdk-core/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
## Do not generate most API and supporting files
**/auth/**
**/infrastructure/**
!**/Base64ByteArray.kt
!**/Bytes.kt
#!**/Base64ByteArray.kt
#!**/Bytes.kt


## Exclude Models which are causing problems
**/JSONRPCResponse.kt
**/Result.kt
**/ListToolsResult.kt
**/InitializeRequest.kt
**/InitializeResult.kt
**/ServerCapabilities.kt
**/InitializeRequestParams.kt
**/CreateMessageRequest.kt
**/CreateMessageRequestParams.kt
**/ClientCapabilities.kt
**/Tool.kt
**/ToolInputSchema.kt
**/ToolOutputSchema.kt
**/models/*.kt

#**/JSONRPCResponse.kt
#**/Result.kt
#**/ListToolsResult.kt
#**/InitializeRequest.kt
#**/InitializeResult.kt
#**/ServerCapabilities.kt
#**/InitializeRequestParams.kt
#**/CreateMessageRequest.kt
#**/CreateMessageRequestParams.kt
#**/ClientCapabilities.kt
#**/Tool.kt
#**/ToolInputSchema.kt
#**/ToolOutputSchema.kt

## Explicitly whitelist models
!**/Role.kt
!**/Prompt.kt
!**/PromptArgument.kt
!**/ToolAnnotations.kt

2,589 changes: 82 additions & 2,507 deletions kotlin-sdk-core/api/kotlin-sdk-core.api

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kotlin-sdk-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ openApiGenerate {
apiPackage = "io.modelcontextprotocol.kotlin.sdk.api"
generateModelTests = false
generateModelDocumentation = false
cleanupOutput = false
cleanupOutput = true
skipValidateSpec = true // do not validate spec
library = "multiplatform"
ignoreFileOverride = "${layout.projectDirectory}/.openapi-generator-ignore"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public data class JSONRPCError(val code: ErrorCode, val message: String, val dat
public sealed interface NotificationParams : WithMeta

/* Cancellation */

/**
* This notification can be sent by either side to indicate that it is cancelling a previously issued request.
*
Expand Down Expand Up @@ -334,6 +335,7 @@ public data class CancelledNotification(override val params: Params) :
}

/* Initialization */

/**
* Describes the name and version of an MCP implementation.
*/
Expand Down Expand Up @@ -527,6 +529,7 @@ public data class InitializedNotification(override val params: Params = Params()
}

/* Ping */

/**
* A ping, issued by either the server or the client, to check that the other party is still alive.
* The receiver must promptly respond, or else it may be disconnected.
Expand Down Expand Up @@ -560,6 +563,7 @@ public sealed interface ProgressBase {
}

/* Progress notifications */

/**
* Represents a progress notification.
*
Expand Down Expand Up @@ -619,6 +623,7 @@ public data class ProgressNotification(override val params: Params) :
}

/* Pagination */

/**
* Represents a request supporting pagination.
*/
Expand Down Expand Up @@ -646,6 +651,7 @@ public sealed interface PaginatedResult : RequestResult {
}

/* Resources */

/**
* The contents of a specific resource or sub-resource.
*/
Expand Down Expand Up @@ -888,43 +894,10 @@ public data class ResourceUpdatedNotification(override val params: Params) : Ser
}

/* Prompts */
/**
* Describes an argument that a prompt can accept.
*/
@Serializable
public data class PromptArgument(
/**
* The name of the argument.
*/
val name: String,
/**
* A human-readable description of the argument.
*/
val description: String?,
/**
* Whether this argument must be provided.
*/
val required: Boolean?,
)

/**
* A prompt or prompt template that the server offers.
*/
@Serializable
public class Prompt(
/**
* The name of the prompt or prompt template.
*/
public val name: String,
/**
* An optional description of what this prompt provides
*/
public val description: String?,
/**
* A list of arguments to use for templating the prompt.
*/
public val arguments: List<PromptArgument>?,
)
public typealias PromptArgument = io.modelcontextprotocol.kotlin.sdk.models.PromptArgument

public typealias Prompt = io.modelcontextprotocol.kotlin.sdk.models.Prompt

/**
* Sent from the client to request a list of prompts and prompt templates the server has.
Expand Down Expand Up @@ -1088,15 +1061,7 @@ public data class EmbeddedResource(
}
}

/**
* Enum representing the role of a participant.
*/
@Suppress("EnumEntryName")
@Serializable
public enum class Role {
user,
assistant,
}
public typealias Role = io.modelcontextprotocol.kotlin.sdk.models.Role

/**
* Optional annotations for the client.
Expand Down Expand Up @@ -1158,56 +1123,8 @@ public data class PromptListChangedNotification(override val params: Params = Pa
}

/* Tools */
/**
* Additional properties describing a Tool to clients.
*
* NOTE: all properties in ToolAnnotations are **hints**.
* They are not guaranteed to provide a faithful description of
* tool behavior (including descriptive properties like `title`).
*
* Clients should never make tool use decisions based on ToolAnnotations
* received from untrusted servers.
*/
@Serializable
public data class ToolAnnotations(
/**
* A human-readable title for the tool.
*/
val title: String?,
/**
* If true, the tool does not modify its environment.
*
* Default: false
*/
val readOnlyHint: Boolean? = false,
/**
* If true, the tool may perform destructive updates to its environment.
* If false, the tool performs only additive updates.
*
* (This property is meaningful only when `readOnlyHint == false`)
*
* Default: true
*/
val destructiveHint: Boolean? = true,
/**
* If true, calling the tool repeatedly with the same arguments
* will have no additional effect on the its environment.
*
* (This property is meaningful only when `readOnlyHint == false`)
*
* Default: false
*/
val idempotentHint: Boolean? = false,
/**
* If true, this tool may interact with an "open world" of external
* entities. If false, the tool's domain of interaction is closed.
* For example, the world of a web search tool is open, whereas that
* of a memory tool is not.
*
* Default: true
*/
val openWorldHint: Boolean? = true,
)

public typealias ToolAnnotations = io.modelcontextprotocol.kotlin.sdk.models.ToolAnnotations

/**
* Definition for a tool the client can call.
Expand Down Expand Up @@ -1336,6 +1253,7 @@ public data class ToolListChangedNotification(override val params: Params = Para
}

/* Logging */

/**
* The severity of a log message.
*/
Expand Down Expand Up @@ -1395,6 +1313,7 @@ public data class LoggingMessageNotification(override val params: Params) : Serv
}

/* Sampling */

/**
* Hints to use for model selection.
*/
Expand Down Expand Up @@ -1639,6 +1558,7 @@ public data class CompleteResult(val completion: Completion, override val _meta:
}

/* Roots */

/**
* Represents a root directory or file that the server can operate on.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RequestSerializerTest {

assertIs<CreateMessageResult>(decoded)
assertEquals("test-model", decoded.model)
assertEquals(Role.assistant, decoded.role)
assertEquals(Role.ASSISTANT, decoded.role)
assertEquals(StopReason.EndTurn, decoded.stopReason)
}

Expand Down Expand Up @@ -200,7 +200,7 @@ class RequestSerializerTest {
assertIs<GetPromptResult>(decoded)
assertEquals("A test prompt", decoded.description)
assertEquals(1, decoded.messages.size)
assertEquals(Role.user, decoded.messages[0].role)
assertEquals(Role.USER, decoded.messages[0].role)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ class TypesTest {
fun `should validate prompt message with text content`() {
val textContent = TextContent(text = "Hello, assistant!")
val promptMessage = PromptMessage(
role = Role.user,
role = Role.USER,
content = textContent,
)

assertEquals(Role.user, promptMessage.role)
assertEquals(Role.USER, promptMessage.role)
assertEquals(textContent, promptMessage.content)
assertEquals("text", promptMessage.content.type)
}
Expand All @@ -225,11 +225,11 @@ class TypesTest {
)
val embeddedResource = EmbeddedResource(resource = resource)
val promptMessage = PromptMessage(
role = Role.assistant,
role = Role.ASSISTANT,
content = embeddedResource,
)

assertEquals(Role.assistant, promptMessage.role)
assertEquals(Role.ASSISTANT, promptMessage.role)
assertEquals("resource", promptMessage.content.type)
val content = promptMessage.content as EmbeddedResource
val textResource = content.resource as TextResourceContents
Expand All @@ -242,15 +242,15 @@ class TypesTest {
@Test
fun `should serialize and deserialize annotations correctly`() {
val annotations = Annotations(
audience = listOf(Role.assistant),
audience = listOf(Role.ASSISTANT),
lastModified = Instant.parse("2025-06-18T00:00:00Z"),
priority = 0.5,
)

val json = McpJson.encodeToString(annotations)
val decoded = McpJson.decodeFromString<Annotations>(json)

assertEquals(listOf(Role.assistant), decoded.audience)
assertEquals(listOf(Role.ASSISTANT), decoded.audience)
assertEquals(Instant.parse("2025-06-18T00:00:00Z"), decoded.lastModified)
assertEquals(0.5, decoded.priority)
}
Expand All @@ -262,14 +262,14 @@ class TypesTest {
mimeType = "image/png",
)
val promptMessage = PromptMessage(
role = Role.assistant,
role = Role.ASSISTANT,
content = imageContent,
)

val json = McpJson.encodeToString(promptMessage)
val decoded = McpJson.decodeFromString<PromptMessage>(json)

assertEquals(Role.assistant, decoded.role)
assertEquals(Role.ASSISTANT, decoded.role)
assertIs<ImageContent>(decoded.content)
val decodedContent = decoded.content
assertEquals("aW1hZ2VkYXRh", decodedContent.data)
Expand Down
16 changes: 8 additions & 8 deletions kotlin-sdk-server/api/kotlin-sdk-server.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ public final class io/modelcontextprotocol/kotlin/sdk/server/KtorServerKt {
}

public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt {
public fun <init> (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)V
public final fun component1 ()Lio/modelcontextprotocol/kotlin/sdk/Prompt;
public fun <init> (Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;Lkotlin/jvm/functions/Function2;)V
public final fun component1 ()Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;
public final fun component2 ()Lkotlin/jvm/functions/Function2;
public final fun copy (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;
public final fun copy (Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;Lkotlin/jvm/functions/Function2;)Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt;
public fun equals (Ljava/lang/Object;)Z
public final fun getMessageProvider ()Lkotlin/jvm/functions/Function2;
public final fun getPrompt ()Lio/modelcontextprotocol/kotlin/sdk/Prompt;
public final fun getPrompt ()Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand Down Expand Up @@ -46,16 +46,16 @@ public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredTool {

public class io/modelcontextprotocol/kotlin/sdk/server/Server {
public fun <init> (Lio/modelcontextprotocol/kotlin/sdk/Implementation;Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;)V
public final fun addPrompt (Lio/modelcontextprotocol/kotlin/sdk/Prompt;Lkotlin/jvm/functions/Function2;)V
public final fun addPrompt (Lio/modelcontextprotocol/kotlin/sdk/models/Prompt;Lkotlin/jvm/functions/Function2;)V
public final fun addPrompt (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun addPrompt$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public final fun addPrompts (Ljava/util/List;)V
public final fun addResource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun addResource$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public final fun addResources (Ljava/util/List;)V
public final fun addTool (Lio/modelcontextprotocol/kotlin/sdk/Tool;Lkotlin/jvm/functions/Function2;)V
public final fun addTool (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun addTool$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/ToolAnnotations;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public final fun addTool (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/models/ToolAnnotations;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun addTool$default (Lio/modelcontextprotocol/kotlin/sdk/server/Server;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Input;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Tool$Output;Lio/modelcontextprotocol/kotlin/sdk/models/ToolAnnotations;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public final fun addTools (Ljava/util/List;)V
public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun connect (Lio/modelcontextprotocol/kotlin/sdk/shared/Transport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
Loading
Loading