Skip to content

Commit 845bdc4

Browse files
author
MAERYO
committed
feat: Add meta parameter support to callTool method
1 parent 7e45708 commit 845bdc4

File tree

1 file changed

+16
-10
lines changed
  • kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client

1 file changed

+16
-10
lines changed

kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/Client.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,17 @@ public open class Client(private val clientInfo: Implementation, options: Client
406406
public suspend fun callTool(
407407
name: String,
408408
arguments: Map<String, Any?>,
409+
meta: Map<String, Any?> = emptyMap(),
409410
compatibility: Boolean = false,
410411
options: RequestOptions? = null,
411412
): CallToolResultBase? {
412-
val jsonArguments = arguments.mapValues { (_, value) ->
413-
when (value) {
414-
is String -> JsonPrimitive(value)
415-
is Number -> JsonPrimitive(value)
416-
is Boolean -> JsonPrimitive(value)
417-
is JsonElement -> value
418-
null -> JsonNull
419-
else -> JsonPrimitive(value.toString())
420-
}
421-
}
413+
val jsonArguments = convertToJsonMap(arguments)
414+
val jsonMeta = convertToJsonMap(meta)
422415

423416
val request = CallToolRequest(
424417
name = name,
425418
arguments = JsonObject(jsonArguments),
419+
_meta = JsonObject(jsonMeta),
426420
)
427421
return callTool(request, compatibility, options)
428422
}
@@ -577,4 +571,16 @@ public open class Client(private val clientInfo: Implementation, options: Client
577571
val rootList = roots.value.values.toList()
578572
return ListRootsResult(rootList)
579573
}
574+
575+
private fun convertToJsonMap(map: Map<String, Any?>): Map<String, JsonElement> =
576+
map.mapValues { (_, value) ->
577+
when (value) {
578+
is String -> JsonPrimitive(value)
579+
is Number -> JsonPrimitive(value)
580+
is Boolean -> JsonPrimitive(value)
581+
is JsonElement -> value
582+
null -> JsonNull
583+
else -> JsonPrimitive(value.toString())
584+
}
585+
}
580586
}

0 commit comments

Comments
 (0)