Skip to content

Commit 9931b1e

Browse files
authored
Fix the difference in error handling between Kotlin and Typescript implementations in onClose (#31)
Makes the error handling behavior consistent between Kotlin and TypeScript implementations when handling connection closure events.
1 parent d8a8f89 commit 9931b1e

File tree

1 file changed

+5
-5
lines changed
  • src/main/kotlin/io/modelcontextprotocol/kotlin/sdk/shared

1 file changed

+5
-5
lines changed

src/main/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/Protocol.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ public abstract class Protocol<SendRequestT : Request, SendNotificationT : Notif
191191
}
192192

193193
private fun onClose() {
194-
val error = McpError(ErrorCode.Defined.ConnectionClosed.code, "Connection closed")
195-
for (handler in responseHandlers.values) {
196-
handler(null, error)
197-
}
198-
199194
responseHandlers.clear()
200195
progressHandlers.clear()
201196
transport = null
202197
onclose()
198+
199+
val error = McpError(ErrorCode.Defined.ConnectionClosed.code, "Connection closed")
200+
for (handler in responseHandlers.values) {
201+
handler(null, error)
202+
}
203203
}
204204

205205
private fun onError(error: Throwable) {

0 commit comments

Comments
 (0)