Skip to content
Merged
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
92 changes: 73 additions & 19 deletions kotlin-sdk-core/api/kotlin-sdk-core.api
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
public final class io/modelcontextprotocol/kotlin/sdk/Annotations {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/Annotations$Companion;
public fun <init> (Ljava/util/List;Lkotlin/time/Instant;Ljava/lang/Double;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Lkotlin/time/Instant;
public final fun component3 ()Ljava/lang/Double;
public final fun copy (Ljava/util/List;Lkotlin/time/Instant;Ljava/lang/Double;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/Annotations;Ljava/util/List;Lkotlin/time/Instant;Ljava/lang/Double;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public fun equals (Ljava/lang/Object;)Z
public final fun getAudience ()Ljava/util/List;
public final fun getLastModified ()Lkotlin/time/Instant;
public final fun getPriority ()Ljava/lang/Double;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final synthetic class io/modelcontextprotocol/kotlin/sdk/Annotations$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lio/modelcontextprotocol/kotlin/sdk/Annotations$$serializer;
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class io/modelcontextprotocol/kotlin/sdk/Annotations$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class io/modelcontextprotocol/kotlin/sdk/AudioContent : io/modelcontextprotocol/kotlin/sdk/PromptMessageContentMultimodal {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/AudioContent$Companion;
public static final field TYPE Ljava/lang/String;
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Lio/modelcontextprotocol/kotlin/sdk/AudioContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/AudioContent;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/AudioContent;
public final fun component3 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/AudioContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/AudioContent;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/AudioContent;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getData ()Ljava/lang/String;
public final fun getMimeType ()Ljava/lang/String;
public fun getType ()Ljava/lang/String;
Expand Down Expand Up @@ -671,11 +705,14 @@ public final class io/modelcontextprotocol/kotlin/sdk/CustomRequest$Companion {
public final class io/modelcontextprotocol/kotlin/sdk/EmbeddedResource : io/modelcontextprotocol/kotlin/sdk/PromptMessageContent {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource$Companion;
public static final field TYPE Ljava/lang/String;
public fun <init> (Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;)V
public fun <init> (Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;
public final fun copy (Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;)Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;
public final fun component2 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/EmbeddedResource;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getResource ()Lio/modelcontextprotocol/kotlin/sdk/ResourceContents;
public fun getType ()Ljava/lang/String;
public fun hashCode ()I
Expand Down Expand Up @@ -841,12 +878,15 @@ public final class io/modelcontextprotocol/kotlin/sdk/GetPromptResult$Companion
public final class io/modelcontextprotocol/kotlin/sdk/ImageContent : io/modelcontextprotocol/kotlin/sdk/PromptMessageContentMultimodal {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/ImageContent$Companion;
public static final field TYPE Ljava/lang/String;
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Lio/modelcontextprotocol/kotlin/sdk/ImageContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/ImageContent;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/ImageContent;
public final fun component3 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/ImageContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/ImageContent;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/ImageContent;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getData ()Ljava/lang/String;
public final fun getMimeType ()Ljava/lang/String;
public fun getType ()Ljava/lang/String;
Expand Down Expand Up @@ -2180,17 +2220,24 @@ public final class io/modelcontextprotocol/kotlin/sdk/RequestResult$Companion {

public final class io/modelcontextprotocol/kotlin/sdk/Resource {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/Resource$Companion;
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/modelcontextprotocol/kotlin/sdk/Resource;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/Resource;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/Resource;
public final fun component5 ()Ljava/lang/String;
public final fun component6 ()Ljava/lang/Long;
public final fun component7 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/Resource;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/Resource;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/Resource;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getDescription ()Ljava/lang/String;
public final fun getMimeType ()Ljava/lang/String;
public final fun getName ()Ljava/lang/String;
public final fun getSize ()Ljava/lang/Long;
public final fun getTitle ()Ljava/lang/String;
public final fun getUri ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -2283,17 +2330,22 @@ public final class io/modelcontextprotocol/kotlin/sdk/ResourceListChangedNotific

public final class io/modelcontextprotocol/kotlin/sdk/ResourceTemplate {
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate$Companion;
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;
public final fun component5 ()Ljava/lang/String;
public final fun component6 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/ResourceTemplate;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getDescription ()Ljava/lang/String;
public final fun getMimeType ()Ljava/lang/String;
public final fun getName ()Ljava/lang/String;
public final fun getTitle ()Ljava/lang/String;
public final fun getUriTemplate ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -2775,12 +2827,14 @@ public final class io/modelcontextprotocol/kotlin/sdk/TextContent : io/modelcont
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/TextContent$Companion;
public static final field TYPE Ljava/lang/String;
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)V
public synthetic fun <init> (Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;)Lio/modelcontextprotocol/kotlin/sdk/TextContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/TextContent;Ljava/lang/String;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/TextContent;
public final fun component2 ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun copy (Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;)Lio/modelcontextprotocol/kotlin/sdk/TextContent;
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/TextContent;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/Annotations;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/TextContent;
public fun equals (Ljava/lang/Object;)Z
public final fun getAnnotations ()Lio/modelcontextprotocol/kotlin/sdk/Annotations;
public final fun getText ()Ljava/lang/String;
public fun getType ()Ljava/lang/String;
public fun hashCode ()I
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import kotlin.concurrent.atomics.AtomicLong
import kotlin.concurrent.atomics.ExperimentalAtomicApi
import kotlin.concurrent.atomics.incrementAndFetch
import kotlin.jvm.JvmInline
import kotlin.time.ExperimentalTime
import kotlin.time.Instant

public const val LATEST_PROTOCOL_VERSION: String = "2025-03-26"

Expand Down Expand Up @@ -710,6 +712,18 @@ public data class Resource(
* The MIME type of this resource, if known.
*/
val mimeType: String?,
/**
* The optional human-readable name of this resource for display purposes.
*/
val title: String? = null,
/**
* The optional size of this resource in bytes, if known.
*/
val size: Long? = null,
/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
)

/**
Expand Down Expand Up @@ -738,6 +752,14 @@ public data class ResourceTemplate(
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
*/
val mimeType: String?,
/**
* The optional human-readable name of this resource for display purposes.
*/
val title: String? = null,
/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
)

/**
Expand Down Expand Up @@ -971,6 +993,11 @@ public data class TextContent(
* The text content of the message.
*/
val text: String? = null,

/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
) : PromptMessageContentMultimodal {
override val type: String = TYPE

Expand All @@ -993,6 +1020,11 @@ public data class ImageContent(
* The MIME type of the image. Different providers may support different image types.
*/
val mimeType: String,

/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
) : PromptMessageContentMultimodal {
override val type: String = TYPE

Expand All @@ -1015,6 +1047,11 @@ public data class AudioContent(
* The MIME type of the audio. Different providers may support different audio types.
*/
val mimeType: String,

/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
) : PromptMessageContentMultimodal {
override val type: String = TYPE

Expand All @@ -1033,7 +1070,17 @@ public data class UnknownContent(override val type: String) : PromptMessageConte
* The contents of a resource, embedded into a prompt or tool call result.
*/
@Serializable
public data class EmbeddedResource(val resource: ResourceContents) : PromptMessageContent {
public data class EmbeddedResource(
/**
* The contents of the embedded resource.
*/
val resource: ResourceContents,

/**
* Optional annotations for the client.
*/
val annotations: Annotations? = null,
) : PromptMessageContent {
override val type: String = TYPE

public companion object {
Expand All @@ -1051,6 +1098,34 @@ public enum class Role {
assistant,
}

/**
* Optional annotations for the client.
* The client can use annotations to inform how objects are used or displayed.
*/
@Serializable
public data class Annotations(
/**
* Describes who the intended customer of this object or data is.
*/
val audience: List<Role>?,
/**
* The moment the resource was last modified.
*/
@OptIn(ExperimentalTime::class)
val lastModified: Instant?,
/**
* Describes how important this data is for operating the server.
*
* A value of 1.0 means "most important", and indicates that the data is effectively required,
* while 0.0 means "less important", and indicates that the data is entirely optional.
*/
val priority: Double?,
) {
init {
require(priority == null || priority in 0.0..1.0) { "Priority must be between 0.0 and 1.0" }
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The validation logic could be more explicit about inclusive bounds. Consider using a more descriptive error message that clarifies both bounds are inclusive: "Priority must be between 0.0 and 1.0 (inclusive)"

Suggested change
require(priority == null || priority in 0.0..1.0) { "Priority must be between 0.0 and 1.0" }
require(priority == null || priority in 0.0..1.0) { "Priority must be between 0.0 and 1.0 (inclusive)" }

Copilot uses AI. Check for mistakes.

}
}

/**
* Describes a message returned as part of a prompt.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime
import kotlin.time.Instant

class TypesTest {

Expand Down Expand Up @@ -236,6 +238,23 @@ class TypesTest {
assertEquals("text/x-rust", textResource.mimeType)
}

@OptIn(ExperimentalTime::class)
@Test
fun `should serialize and deserialize annotations correctly`() {
val annotations = Annotations(
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(Instant.parse("2025-06-18T00:00:00Z"), decoded.lastModified)
assertEquals(0.5, decoded.priority)
}

@Test
fun `should serialize and deserialize prompt message correctly`() {
val imageContent = ImageContent(
Expand Down
Loading