From 9da193463fa321a09958f1a918da754718b1fa94 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 16:50:22 +0000 Subject: [PATCH 1/2] Bump com.anthropic:anthropic-java from 0.8.0 to 2.6.0 Bumps [com.anthropic:anthropic-java](https://github.com/anthropics/anthropic-sdk-java) from 0.8.0 to 2.6.0. - [Release notes](https://github.com/anthropics/anthropic-sdk-java/releases) - [Changelog](https://github.com/anthropics/anthropic-sdk-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/anthropics/anthropic-sdk-java/compare/v0.8.0...v2.6.0) --- updated-dependencies: - dependency-name: com.anthropic:anthropic-java dependency-version: 2.6.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 01ebe92a..c099a094 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ awaitility = "4.3.0" # Samples mcp-kotlin = "0.7.0" -anthropic = "0.8.0" +anthropic = "2.7.0" shadow = "8.1.1" [libraries] From f11c644aa0d7da6825df40e191e1e8f239fc93fa Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com> Date: Thu, 11 Sep 2025 21:13:42 +0300 Subject: [PATCH 2/2] Upgrade to Claude 4 model and improve tool handling in MCP client - Updated to use `Model.CLAUDE_4_SONNET_20250514`. - Enhanced tool processing by removing optional null checks and ensuring consistent formatting. --- .../sample/client/MCPClient.kt | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/samples/kotlin-mcp-client/src/main/kotlin/io/modelcontextprotocol/sample/client/MCPClient.kt b/samples/kotlin-mcp-client/src/main/kotlin/io/modelcontextprotocol/sample/client/MCPClient.kt index 6221b471..d9d482df 100644 --- a/samples/kotlin-mcp-client/src/main/kotlin/io/modelcontextprotocol/sample/client/MCPClient.kt +++ b/samples/kotlin-mcp-client/src/main/kotlin/io/modelcontextprotocol/sample/client/MCPClient.kt @@ -2,7 +2,11 @@ package io.modelcontextprotocol.sample.client import com.anthropic.client.okhttp.AnthropicOkHttpClient import com.anthropic.core.JsonValue -import com.anthropic.models.messages.* +import com.anthropic.models.messages.MessageCreateParams +import com.anthropic.models.messages.MessageParam +import com.anthropic.models.messages.Model +import com.anthropic.models.messages.Tool +import com.anthropic.models.messages.ToolUnion import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper import io.modelcontextprotocol.kotlin.sdk.Implementation @@ -24,7 +28,7 @@ class MCPClient : AutoCloseable { private val mcp: Client = Client(clientInfo = Implementation(name = "mcp-client-cli", version = "1.0.0")) private val messageParamsBuilder: MessageCreateParams.Builder = MessageCreateParams.builder() - .model(Model.CLAUDE_3_5_SONNET_20241022) + .model(Model.CLAUDE_4_SONNET_20250514) .maxTokens(1024) // List of tools offered by the server @@ -56,7 +60,7 @@ class MCPClient : AutoCloseable { // Setup I/O transport using the process streams val transport = StdioClientTransport( input = process.inputStream.asSource().buffered(), - output = process.outputStream.asSink().buffered() + output = process.outputStream.asSink().buffered(), ) // Connect the MCP client to the server using the transport @@ -64,7 +68,7 @@ class MCPClient : AutoCloseable { // Request the list of available tools from the server val toolsResult = mcp.listTools() - tools = toolsResult?.tools?.map { tool -> + tools = toolsResult.tools.map { tool -> ToolUnion.ofTool( Tool.builder() .name(tool.name) @@ -74,11 +78,11 @@ class MCPClient : AutoCloseable { .type(JsonValue.from(tool.inputSchema.type)) .properties(tool.inputSchema.properties.toJsonValue()) .putAdditionalProperty("required", JsonValue.from(tool.inputSchema.required)) - .build() + .build(), ) - .build() + .build(), ) - } ?: emptyList() + } println("Connected to server with tools: ${tools.joinToString(", ") { it.tool().get().name() }}") } catch (e: Exception) { println("Failed to connect to MCP server: $e") @@ -93,7 +97,7 @@ class MCPClient : AutoCloseable { MessageParam.builder() .role(MessageParam.Role.USER) .content(query) - .build() + .build(), ) // Send the query to the Anthropic model and get the response @@ -101,7 +105,7 @@ class MCPClient : AutoCloseable { messageParamsBuilder .messages(messages) .tools(tools) - .build() + .build(), ) val finalText = mutableListOf() @@ -119,7 +123,7 @@ class MCPClient : AutoCloseable { // Call the tool with provided arguments val result = mcp.callTool( name = toolName, - arguments = toolArgs ?: emptyMap() + arguments = toolArgs ?: emptyMap(), ) finalText.add("[Calling tool $toolName with args $toolArgs]") @@ -131,17 +135,19 @@ class MCPClient : AutoCloseable { """ "type": "tool_result", "tool_name": $toolName, - "result": ${result?.content?.joinToString("\n") { (it as TextContent).text ?: "" }} - """.trimIndent() + "result": ${result?.content?.joinToString("\n") { + (it as TextContent).text ?: "" + }} + """.trimIndent(), ) - .build() + .build(), ) // Retrieve an updated response after tool execution val aiResponse = anthropic.messages().create( messageParamsBuilder .messages(messages) - .build() + .build(), ) // Append the updated response to final text @@ -160,7 +166,7 @@ class MCPClient : AutoCloseable { while (true) { print("\nQuery: ") - val message = readLine() ?: break + val message = readlnOrNull() ?: break if (message.lowercase() == "quit") break val response = processQuery(message) println("\n$response") @@ -173,4 +179,4 @@ class MCPClient : AutoCloseable { anthropic.close() } } -} \ No newline at end of file +}