Skip to content

Commit 7cdee38

Browse files
committed
test(mcp-test): await the full request assertion, drop null-safe extractor
Review follow-up: the header is never absent with the clients used here, so the contextExtractor stays as on main; the whole size-3 assertion now runs inside await() so a late POST is covered as well as the async GET. Claude-Session: https://claude.ai/code/session_01WtjUifqJuzJdfxc1zjcZrL
1 parent 926a0d3 commit 7cdee38

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

mcp-test/src/test/java/io/modelcontextprotocol/common/HttpClientStreamableHttpVersionNegotiationIntegrationTests.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.time.Duration;
88
import java.util.List;
99
import java.util.Map;
10-
import java.util.Objects;
1110
import java.util.function.BiFunction;
1211

1312
import io.modelcontextprotocol.client.McpClient;
@@ -40,10 +39,8 @@ class HttpClientStreamableHttpVersionNegotiationIntegrationTests {
4039

4140
private final HttpServletStreamableServerTransportProvider transport = HttpServletStreamableServerTransportProvider
4241
.builder()
43-
// The MCP-Protocol-Version header may legitimately be absent on initialize
44-
// requests, so a missing header must not break context extraction.
45-
.contextExtractor(req -> McpTransportContext
46-
.create(Map.of("protocol-version", Objects.requireNonNullElse(req.getHeader("MCP-protocol-version"), ""))))
42+
.contextExtractor(
43+
req -> McpTransportContext.create(Map.of("protocol-version", req.getHeader("MCP-protocol-version"))))
4744
.build();
4845

4946
private final McpSchema.Tool toolSpec = McpSchema.Tool.builder("test-tool")
@@ -79,18 +76,15 @@ void usesLatestVersion() {
7976

8077
// The GET /mcp stream is opened asynchronously once the initialize response
8178
// creates the session, so wait for it to be recorded before asserting.
82-
await().atMost(Duration.ofSeconds(5))
83-
.untilAsserted(() -> assertThat(requestRecordingFilter.getCalls()).filteredOn(c -> "GET".equals(c.method()))
84-
.hasSize(1));
85-
86-
var calls = requestRecordingFilter.getCalls();
87-
88-
assertThat(calls).filteredOn(c -> !c.body().contains("\"method\":\"initialize\""))
89-
// GET /mcp ; POST notification/initialized ; POST tools/call
90-
.hasSize(3)
91-
.map(McpTestRequestRecordingServletFilter.Call::headers)
92-
.allSatisfy(headers -> assertThat(headers).containsEntry("mcp-protocol-version",
93-
ProtocolVersions.MCP_2025_11_25));
79+
await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> {
80+
var calls = requestRecordingFilter.getCalls();
81+
assertThat(calls).filteredOn(c -> !c.body().contains("\"method\":\"initialize\""))
82+
// GET /mcp ; POST notification/initialized ; POST tools/call
83+
.hasSize(3)
84+
.map(McpTestRequestRecordingServletFilter.Call::headers)
85+
.allSatisfy(headers -> assertThat(headers).containsEntry("mcp-protocol-version",
86+
ProtocolVersions.MCP_2025_11_25));
87+
});
9488

9589
assertThat(response).isNotNull();
9690
assertThat(response.content()).hasSize(1)

0 commit comments

Comments
 (0)