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
-->
This commit is contained in:
Konstantin Pavlov 2025-11-10 17:56:59 +02:00 • committed by GitHub
commit e6432dbf26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 13 deletions

View file

@ -1,14 +1,14 @@
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 fun <init> (Ljava/util/List;Ljava/lang/String;Ljava/lang/Double;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Lkotlin/time/Instant;
public final fun component2 ()Ljava/lang/String;
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 final fun copy (Ljava/util/List;Ljava/lang/String;Ljava/lang/Double;)Lio/modelcontextprotocol/kotlin/sdk/Annotations;
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;
public fun equals (Ljava/lang/Object;)Z
public final fun getAudience ()Ljava/util/List;
public final fun getLastModified ()Lkotlin/time/Instant;
public final fun getLastModified ()Ljava/lang/String;
public final fun getPriority ()Ljava/lang/Double;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;

View file

@ -17,8 +17,6 @@ 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"
@ -302,6 +300,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.
*
@ -334,6 +333,7 @@ public data class CancelledNotification(override val params: Params) :
}
/* Initialization */
/**
* Describes the name and version of an MCP implementation.
*/
@ -531,6 +531,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.
@ -564,6 +565,7 @@ public sealed interface ProgressBase {
}
/* Progress notifications */
/**
* Represents a progress notification.
*
@ -623,6 +625,7 @@ public data class ProgressNotification(override val params: Params) :
}
/* Pagination */
/**
* Represents a request supporting pagination.
*/
@ -650,6 +653,7 @@ public sealed interface PaginatedResult : RequestResult {
}
/* Resources */
/**
* The contents of a specific resource or sub-resource.
*/
@ -892,6 +896,7 @@ public data class ResourceUpdatedNotification(override val params: Params) : Ser
}
/* Prompts */
/**
* Describes an argument that a prompt can accept.
*/
@ -1115,8 +1120,7 @@ public data class Annotations(
/**
* The moment the resource was last modified.
*/
@OptIn(ExperimentalTime::class)
val lastModified: Instant?,
val lastModified: String?,
/**
* Describes how important this data is for operating the server.
*
@ -1162,6 +1166,7 @@ public data class PromptListChangedNotification(override val params: Params = Pa
}
/* Tools */
/**
* Additional properties describing a Tool to clients.
*
@ -1345,6 +1350,7 @@ public data class ToolListChangedNotification(override val params: Params = Para
}
/* Logging */
/**
* The severity of a log message.
*/
@ -1404,6 +1410,7 @@ public data class LoggingMessageNotification(override val params: Params) : Serv
}
/* Sampling */
/**
* Hints to use for model selection.
*/
@ -1648,6 +1655,7 @@ public data class CompleteResult(val completion: Completion, override val _meta:
}
/* Roots */
/**
* Represents a root directory or file that the server can operate on.
*/

View file

@ -7,7 +7,6 @@ import kotlin.test.assertIs
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
import kotlin.time.ExperimentalTime
import kotlin.time.Instant
class TypesTest {
@ -243,7 +242,7 @@ class TypesTest {
fun `should serialize and deserialize annotations correctly`() {
val annotations = Annotations(
audience = listOf(Role.assistant),
lastModified = Instant.parse("2025-06-18T00:00:00Z"),
lastModified = "2025-06-18T00:00:00Z",
priority = 0.5,
)
@ -251,7 +250,7 @@ class TypesTest {
val decoded = McpJson.decodeFromString<Annotations>(json)
assertEquals(listOf(Role.assistant), decoded.audience)
assertEquals(Instant.parse("2025-06-18T00:00:00Z"), decoded.lastModified)
assertEquals("2025-06-18T00:00:00Z", decoded.lastModified)
assertEquals(0.5, decoded.priority)
}

View file

@ -71,7 +71,7 @@ internal suspend fun WebSocketServerSession.mcpWebSocketEndpoint(block: () -> Se
try {
session = server.createSession(transport)
awaitCancellation()
} catch (e: CancellationException) {
} catch (_: CancellationException) {
session?.close()
}
}