Skip to content

Commit e6432db

Browse files
authored
Replace Instant with String for lastModified in Annotations (#383)
Replace `Instant` with `String` for `lastModified` in `Annotations` ## Motivation and Context To fix serialization/kotlin library version conflicts ## How Has This Been Tested? Unit test ## Breaking Changes Yes ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions -->
1 parent 33b5fc3 commit e6432db

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

kotlin-sdk-core/api/kotlin-sdk-core.api

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
public final class io/modelcontextprotocol/kotlin/sdk/Annotations {
22
public static final field Companion Lio/modelcontextprotocol/kotlin/sdk/Annotations$Companion;
3-
public fun <init> (Ljava/util/List;Lkotlin/time/Instant;Ljava/lang/Double;)V
3+
public fun <init> (Ljava/util/List;Ljava/lang/String;Ljava/lang/Double;)V
44
public final fun component1 ()Ljava/util/List;
5-
public final fun component2 ()Lkotlin/time/Instant;
5+
public final fun component2 ()Ljava/lang/String;
66
public final fun component3 ()Ljava/lang/Double;
7-
public final fun copy (Ljava/util/List;Lkotlin/time/Instant;Ljava/lang/Double;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
8-
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;
7+
public final fun copy (Ljava/util/List;Ljava/lang/String;Ljava/lang/Double;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
8+
public static synthetic fun copy$default (Lio/modelcontextprotocol/kotlin/sdk/Annotations;Ljava/util/List;Ljava/lang/String;Ljava/lang/Double;ILjava/lang/Object;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
99
public fun equals (Ljava/lang/Object;)Z
1010
public final fun getAudience ()Ljava/util/List;
11-
public final fun getLastModified ()Lkotlin/time/Instant;
11+
public final fun getLastModified ()Ljava/lang/String;
1212
public final fun getPriority ()Ljava/lang/Double;
1313
public fun hashCode ()I
1414
public fun toString ()Ljava/lang/String;

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import kotlin.concurrent.atomics.AtomicLong
1717
import kotlin.concurrent.atomics.ExperimentalAtomicApi
1818
import kotlin.concurrent.atomics.incrementAndFetch
1919
import kotlin.jvm.JvmInline
20-
import kotlin.time.ExperimentalTime
21-
import kotlin.time.Instant
2220

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

@@ -302,6 +300,7 @@ public data class JSONRPCError(val code: ErrorCode, val message: String, val dat
302300
public sealed interface NotificationParams : WithMeta
303301

304302
/* Cancellation */
303+
305304
/**
306305
* This notification can be sent by either side to indicate that it is cancelling a previously issued request.
307306
*
@@ -334,6 +333,7 @@ public data class CancelledNotification(override val params: Params) :
334333
}
335334

336335
/* Initialization */
336+
337337
/**
338338
* Describes the name and version of an MCP implementation.
339339
*/
@@ -531,6 +531,7 @@ public data class InitializedNotification(override val params: Params = Params()
531531
}
532532

533533
/* Ping */
534+
534535
/**
535536
* A ping, issued by either the server or the client, to check that the other party is still alive.
536537
* The receiver must promptly respond, or else it may be disconnected.
@@ -564,6 +565,7 @@ public sealed interface ProgressBase {
564565
}
565566

566567
/* Progress notifications */
568+
567569
/**
568570
* Represents a progress notification.
569571
*
@@ -623,6 +625,7 @@ public data class ProgressNotification(override val params: Params) :
623625
}
624626

625627
/* Pagination */
628+
626629
/**
627630
* Represents a request supporting pagination.
628631
*/
@@ -650,6 +653,7 @@ public sealed interface PaginatedResult : RequestResult {
650653
}
651654

652655
/* Resources */
656+
653657
/**
654658
* The contents of a specific resource or sub-resource.
655659
*/
@@ -892,6 +896,7 @@ public data class ResourceUpdatedNotification(override val params: Params) : Ser
892896
}
893897

894898
/* Prompts */
899+
895900
/**
896901
* Describes an argument that a prompt can accept.
897902
*/
@@ -1115,8 +1120,7 @@ public data class Annotations(
11151120
/**
11161121
* The moment the resource was last modified.
11171122
*/
1118-
@OptIn(ExperimentalTime::class)
1119-
val lastModified: Instant?,
1123+
val lastModified: String?,
11201124
/**
11211125
* Describes how important this data is for operating the server.
11221126
*
@@ -1162,6 +1166,7 @@ public data class PromptListChangedNotification(override val params: Params = Pa
11621166
}
11631167

11641168
/* Tools */
1169+
11651170
/**
11661171
* Additional properties describing a Tool to clients.
11671172
*
@@ -1345,6 +1350,7 @@ public data class ToolListChangedNotification(override val params: Params = Para
13451350
}
13461351

13471352
/* Logging */
1353+
13481354
/**
13491355
* The severity of a log message.
13501356
*/
@@ -1404,6 +1410,7 @@ public data class LoggingMessageNotification(override val params: Params) : Serv
14041410
}
14051411

14061412
/* Sampling */
1413+
14071414
/**
14081415
* Hints to use for model selection.
14091416
*/
@@ -1648,6 +1655,7 @@ public data class CompleteResult(val completion: Completion, override val _meta:
16481655
}
16491656

16501657
/* Roots */
1658+
16511659
/**
16521660
* Represents a root directory or file that the server can operate on.
16531661
*/

kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/TypesTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import kotlin.test.assertIs
77
import kotlin.test.assertNotEquals
88
import kotlin.test.assertTrue
99
import kotlin.time.ExperimentalTime
10-
import kotlin.time.Instant
1110

1211
class TypesTest {
1312

@@ -243,15 +242,15 @@ class TypesTest {
243242
fun `should serialize and deserialize annotations correctly`() {
244243
val annotations = Annotations(
245244
audience = listOf(Role.assistant),
246-
lastModified = Instant.parse("2025-06-18T00:00:00Z"),
245+
lastModified = "2025-06-18T00:00:00Z",
247246
priority = 0.5,
248247
)
249248

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

253252
assertEquals(listOf(Role.assistant), decoded.audience)
254-
assertEquals(Instant.parse("2025-06-18T00:00:00Z"), decoded.lastModified)
253+
assertEquals("2025-06-18T00:00:00Z", decoded.lastModified)
255254
assertEquals(0.5, decoded.priority)
256255
}
257256

kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/WebSocketMcpKtorServerExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal suspend fun WebSocketServerSession.mcpWebSocketEndpoint(block: () -> Se
7171
try {
7272
session = server.createSession(transport)
7373
awaitCancellation()
74-
} catch (e: CancellationException) {
74+
} catch (_: CancellationException) {
7575
session?.close()
7676
}
7777
}

0 commit comments

Comments
 (0)