This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mcp-server.git
The following commit(s) were added to refs/heads/master by this push:
new 9faaef1 chore: simplify MCP client initialisation in McpServerIT (#20)
9faaef1 is described below
commit 9faaef19471d1183b0284f22f6cff0e51a717b4a
Author: Robert Munteanu <[email protected]>
AuthorDate: Fri May 22 17:12:27 2026 +0200
chore: simplify MCP client initialisation in McpServerIT (#20)
---
.../org/apache/sling/mcp/server/McpServerIT.java | 32 ++++++++++------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/test/java/org/apache/sling/mcp/server/McpServerIT.java
b/src/test/java/org/apache/sling/mcp/server/McpServerIT.java
index 0a360ee..c4c5637 100644
--- a/src/test/java/org/apache/sling/mcp/server/McpServerIT.java
+++ b/src/test/java/org/apache/sling/mcp/server/McpServerIT.java
@@ -24,8 +24,8 @@ import java.nio.file.Path;
import java.time.Duration;
import java.util.Base64;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicReference;
import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
@@ -79,26 +79,24 @@ class McpServerIT {
}
private McpSyncClient initializeMcpClient(String basicAuthHeader) {
- AtomicReference<McpSyncClient> initializedClient = new
AtomicReference<>();
- await("mcp client initializes")
+ return await("mcp client initializes")
.atMost(AWAIT_TIMEOUT)
.pollInterval(AWAIT_POLL_INTERVAL)
.ignoreExceptions()
- .until(() -> {
- McpSyncClient candidate = buildMcpClient(basicAuthHeader);
-
- try {
- candidate.initialize();
- initializedClient.set(candidate);
- return true;
- } catch (RuntimeException e) {
- candidate.close();
- throw e;
- }
- });
-
- return initializedClient.get();
+ .until(
+ () -> {
+ McpSyncClient candidate =
buildMcpClient(basicAuthHeader);
+
+ try {
+ candidate.initialize();
+ return candidate;
+ } catch (RuntimeException e) {
+ candidate.close();
+ throw e;
+ }
+ },
+ Objects::nonNull);
}
private McpSyncClient buildMcpClient(String basicAuthHeader) {