Skip to content

Commit f6a7ffa

Browse files
committed
Fix notification timestamp comparison
1 parent 272c2e3 commit f6a7ffa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import io.modelcontextprotocol.kotlin.sdk.types.ResourceListChangedNotification
77
import io.modelcontextprotocol.kotlin.sdk.types.ResourceUpdatedNotification
88
import io.modelcontextprotocol.kotlin.sdk.types.ResourceUpdatedNotificationParams
99
import io.modelcontextprotocol.kotlin.sdk.types.ToolListChangedNotification
10+
import kotlin.time.Clock
11+
import kotlin.time.ExperimentalTime
1012
import kotlinx.atomicfu.atomic
1113
import kotlinx.atomicfu.getAndUpdate
1214
import kotlinx.collections.immutable.persistentMapOf
@@ -23,8 +25,6 @@ import kotlinx.coroutines.flow.SharedFlow
2325
import kotlinx.coroutines.flow.takeWhile
2426
import kotlinx.coroutines.joinAll
2527
import kotlinx.coroutines.launch
26-
import kotlin.time.Clock
27-
import kotlin.time.ExperimentalTime
2828

2929
/** Represents an event for notification service. */
3030
private sealed class Event
@@ -66,7 +66,7 @@ private class SessionNotificationJob {
6666
events.takeWhile { it !is EndEvent }.collect { event ->
6767
when (event) {
6868
is NotificationEvent -> {
69-
if (event.timestamp > fromTimestamp) {
69+
if (event.timestamp >= fromTimestamp) {
7070
when (val notification = event.notification) {
7171
is PromptListChangedNotification -> {
7272
logger.info {
@@ -91,22 +91,24 @@ private class SessionNotificationJob {
9191

9292
is ResourceUpdatedNotification -> {
9393
resourceSubscriptions.value[notification.params.uri]?.let { resourceFromTimestamp ->
94-
if (event.timestamp > resourceFromTimestamp) {
94+
if (event.timestamp >= resourceFromTimestamp) {
9595
logger.info {
96-
"Sending notification for resource ${notification.params.uri} " +
96+
"Sending resource updated notification for resource " +
97+
"${notification.params.uri} " +
9798
"to sessionId: ${session.sessionId}"
9899
}
99100
session.notification(notification)
100101
} else {
101102
logger.info {
102-
"Skipping notification for resource ${notification.params.uri} " +
103+
"Skipping resource updated notification for resource " +
104+
"${notification.params.uri} " +
103105
"as it is older than subscription timestamp $resourceFromTimestamp"
104106
}
105107
}
106108
} ?: run {
107109
logger.info {
108110
"No subscription for resource ${notification.params.uri}. " +
109-
"Skipping notification."
111+
"Skipping notification: $notification"
110112
}
111113
}
112114
}
@@ -118,7 +120,7 @@ private class SessionNotificationJob {
118120
} else {
119121
logger.info {
120122
"Skipping event with id: ${event.timestamp} " +
121-
"as it is older than startingEventId $fromTimestamp"
123+
"as it is older than startingEventId $fromTimestamp: $event"
122124
}
123125
}
124126
}

0 commit comments

Comments
 (0)