Skip to content

Commit eb99347

Browse files
committed
fix exception propgation
1 parent baa84bf commit eb99347

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerAnnotations.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.modelcontextprotocol.kotlin.sdk.server
22

3+
import io.ktor.util.rootCause
34
import io.modelcontextprotocol.kotlin.sdk.CallToolRequest
45
import io.modelcontextprotocol.kotlin.sdk.CallToolResult
56
import io.modelcontextprotocol.kotlin.sdk.TextContent
@@ -9,6 +10,7 @@ import kotlinx.serialization.json.JsonPrimitive
910
import kotlinx.serialization.json.buildJsonObject
1011
import kotlinx.serialization.json.put
1112
import kotlinx.serialization.json.putJsonObject
13+
import java.lang.reflect.InvocationTargetException
1214
import kotlin.reflect.KCallable
1315
import kotlin.reflect.KClass
1416
import kotlin.reflect.KFunction
@@ -127,8 +129,10 @@ public fun <T : Any> Server.registerToolFromAnnotatedFunction(
127129

128130
// Call the function using callBy
129131
function.callBy(arguments)
130-
} catch (e: Exception) {
132+
} catch (e: IllegalArgumentException) {
131133
throw IllegalArgumentException("Error invoking function ${function.name}: ${e.message}", e)
134+
} catch (e: InvocationTargetException) {
135+
throw e.targetException
132136
}
133137

134138
// Handle the result

0 commit comments

Comments
 (0)