Skip to content

Commit 29a925c

Browse files
committed
Avoid exposing raw response to exception message
1 parent 5900d09 commit 29a925c

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/serializers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private fun JsonElement.getType(): String = requireNotNull(getTypeOrNull()) { "M
4444
@Throws(SerializationException::class)
4545
private fun JsonElement.asJsonObject(): JsonObject {
4646
if (this !is JsonObject) {
47-
throw SerializationException("Invalid response. JsonObject expected, got: $this")
47+
throw SerializationException("Invalid response. JsonObject expected, got: ${this::class.simpleName}")
4848
}
4949
val jsonObject = this.jsonObject
5050
return jsonObject

kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/types/JsonRpcTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class JsonRpcTest {
417417
McpJson.decodeFromString<JSONRPCMessage>("[\"just a string\"]")
418418
}
419419

420-
exception.message shouldBe "Invalid response. JsonObject expected, got: [\"just a string\"]"
420+
exception.message shouldBe "Invalid response. JsonObject expected, got: JsonArray"
421421
}
422422

423423
@Test

kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/types/ResourcesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class ResourcesTest {
259259
McpJson.decodeFromString<ResourceContents>("\"just a string\"")
260260
}
261261

262-
exception.message shouldBe "Invalid response. JsonObject expected, got: \"just a string\""
262+
exception.message shouldBe "Invalid response. JsonObject expected, got: JsonLiteral"
263263
}
264264

265265
@Test

0 commit comments

Comments
 (0)