Skip to content

Commit eb49f5c

Browse files
committed
fix(core): rethrow CancellationException to avoid unintended suppression
Add specific handling for `CancellationException` in `Protocol.kt` to ensure it is rethrown instead of being suppressed by the generic `Throwable` catch block.
1 parent d6c6cf2 commit eb49f5c

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/Protocol.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ public abstract class Protocol(@PublishedApi internal val options: ProtocolOptio
324324
result = result ?: EmptyResult(),
325325
),
326326
)
327+
} catch (e: CancellationException) {
328+
throw e
327329
} catch (cause: Throwable) {
328330
logger.error(cause) { "Error handling request: ${request.method} (id: ${request.id})" }
329331

kotlin-sdk-server/api/kotlin-sdk-server.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class io/modelcontextprotocol/kotlin/sdk/server/Server {
116116
protected final fun getInstructionsProvider ()Lkotlin/jvm/functions/Function0;
117117
protected final fun getOptions ()Lio/modelcontextprotocol/kotlin/sdk/server/ServerOptions;
118118
public final fun getPrompts ()Ljava/util/Map;
119-
public final fun getResourceTemplates ()Ljava/util/Map;
119+
public final fun getResourceTemplates ()Ljava/util/List;
120120
public final fun getResources ()Ljava/util/Map;
121121
protected final fun getServerInfo ()Lio/modelcontextprotocol/kotlin/sdk/types/Implementation;
122122
public final fun getSessions ()Ljava/util/Map;

0 commit comments

Comments
 (0)