Skip to content

Commit d7a6858

Browse files
committed
Make ToolInputValidationIntegrationTests not dependend on abstract class
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
1 parent b9d8ff3 commit d7a6858

2 files changed

Lines changed: 17 additions & 37 deletions

File tree

mcp-core/src/main/java/io/modelcontextprotocol/server/McpServer.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,9 @@ public AsyncSpecification<S> strictToolNameValidation(boolean strict) {
424424
}
425425

426426
/**
427-
* Sets whether to validate tool inputs against the tool's input schema. When set,
428-
* this takes priority over the system property
429-
* {@code io.modelcontextprotocol.validateToolInputs}.
430-
* @param validate true to validate inputs and return error on validation failure
427+
* Sets whether to validate tool inputs against the tool's input schema.
428+
* @param validate true to validate inputs and return error on validation failure,
429+
* false to skip validation. Defaults to true.
431430
* @return This builder instance for method chaining
432431
*/
433432
public AsyncSpecification<S> validateToolInputs(boolean validate) {
@@ -1022,10 +1021,9 @@ public SyncSpecification<S> strictToolNameValidation(boolean strict) {
10221021
}
10231022

10241023
/**
1025-
* Sets whether to validate tool inputs against the tool's input schema. When set,
1026-
* this takes priority over the system property
1027-
* {@code io.modelcontextprotocol.validateToolInputs}.
1028-
* @param validate true to validate inputs and return error on validation failure
1024+
* Sets whether to validate tool inputs against the tool's input schema.
1025+
* @param validate true to validate inputs and return error on validation failure,
1026+
* false to skip validation. Defaults to true.
10291027
* @return This builder instance for method chaining
10301028
*/
10311029
public SyncSpecification<S> validateToolInputs(boolean validate) {
@@ -1562,10 +1560,9 @@ public StatelessAsyncSpecification strictToolNameValidation(boolean strict) {
15621560
}
15631561

15641562
/**
1565-
* Sets whether to validate tool inputs against the tool's input schema. When set,
1566-
* this takes priority over the system property
1567-
* {@code io.modelcontextprotocol.validateToolInputs}.
1568-
* @param validate true to validate inputs and return error on validation failure
1563+
* Sets whether to validate tool inputs against the tool's input schema.
1564+
* @param validate true to validate inputs and return error on validation failure,
1565+
* false to skip validation. Defaults to true.
15691566
* @return This builder instance for method chaining
15701567
*/
15711568
public StatelessAsyncSpecification validateToolInputs(boolean validate) {
@@ -2060,10 +2057,9 @@ public StatelessSyncSpecification strictToolNameValidation(boolean strict) {
20602057
}
20612058

20622059
/**
2063-
* Sets whether to validate tool inputs against the tool's input schema. When set,
2064-
* this takes priority over the system property
2065-
* {@code io.modelcontextprotocol.validateToolInputs}.
2066-
* @param validate true to validate inputs and return error on validation failure
2060+
* Sets whether to validate tool inputs against the tool's input schema.
2061+
* @param validate true to validate inputs and return error on validation failure,
2062+
* false to skip validation. Defaults to true.
20672063
* @return This builder instance for method chaining
20682064
*/
20692065
public StatelessSyncSpecification validateToolInputs(boolean validate) {

mcp-test/src/test/java/io/modelcontextprotocol/server/ToolInputValidationIntegrationTests.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Map;
1010
import java.util.stream.Stream;
1111

12-
import io.modelcontextprotocol.AbstractMcpClientServerIntegrationTests;
1312
import io.modelcontextprotocol.client.McpClient;
1413
import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport;
1514
import io.modelcontextprotocol.common.McpTransportContext;
@@ -42,7 +41,7 @@
4241
* @author Andrei Shakirin
4342
*/
4443
@Timeout(15)
45-
class ToolInputValidationIntegrationTests extends AbstractMcpClientServerIntegrationTests {
44+
class ToolInputValidationIntegrationTests {
4645

4746
private static final int PORT = TomcatTestUtil.findAvailablePort();
4847

@@ -61,10 +60,6 @@ class ToolInputValidationIntegrationTests extends AbstractMcpClientServerIntegra
6160

6261
private Tomcat tomcat;
6362

64-
static Stream<Arguments> clientsForTesting() {
65-
return Stream.of(Arguments.of("httpclient"));
66-
}
67-
6863
static Stream<Arguments> validInputTestCases() {
6964
return Stream.of(
7065
// serverType, validationEnabled, inputArgs, expectedOutput
@@ -82,6 +77,10 @@ static Stream<Arguments> invalidInputTestCases() {
8277
// value
8378
}
8479

80+
private final McpClient.SyncSpec clientBuilder = McpClient
81+
.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT).endpoint(MESSAGE_ENDPOINT).build())
82+
.requestTimeout(Duration.ofSeconds(10));
83+
8584
@BeforeEach
8685
public void before() {
8786
mcpServerTransportProvider = HttpServletStreamableServerTransportProvider.builder()
@@ -97,20 +96,12 @@ public void before() {
9796
catch (Exception e) {
9897
throw new RuntimeException("Failed to start Tomcat", e);
9998
}
100-
101-
clientBuilders
102-
.put("httpclient",
103-
McpClient.sync(HttpClientStreamableHttpTransport.builder("http://localhost:" + PORT)
104-
.endpoint(MESSAGE_ENDPOINT)
105-
.build()).requestTimeout(Duration.ofSeconds(10)));
10699
}
107100

108-
@Override
109101
protected McpServer.AsyncSpecification<?> prepareAsyncServerBuilder() {
110102
return McpServer.async(this.mcpServerTransportProvider);
111103
}
112104

113-
@Override
114105
protected McpServer.SyncSpecification<?> prepareSyncServerBuilder() {
115106
return McpServer.sync(this.mcpServerTransportProvider);
116107
}
@@ -131,10 +122,6 @@ public void after() {
131122
}
132123
}
133124

134-
@Override
135-
protected void prepareClients(int port, String mcpEndpoint) {
136-
}
137-
138125
private McpServerFeatures.SyncToolSpecification createSyncTool() {
139126
Tool tool = Tool.builder()
140127
.name(TOOL_NAME)
@@ -173,7 +160,6 @@ private McpServerFeatures.AsyncToolSpecification createAsyncTool() {
173160
@MethodSource("validInputTestCases")
174161
void validInput_shouldSucceed(String serverType, boolean validationEnabled, Map<String, Object> input,
175162
String expectedOutput) {
176-
var clientBuilder = clientBuilders.get("httpclient");
177163
Object server = createServer(serverType, validationEnabled);
178164

179165
try (var client = clientBuilder.clientInfo(new McpSchema.Implementation("test-client", "1.0.0")).build()) {
@@ -192,7 +178,6 @@ void validInput_shouldSucceed(String serverType, boolean validationEnabled, Map<
192178
@MethodSource("invalidInputTestCases")
193179
void invalidInput_withDefaultValidation_shouldReturnToolError(String serverType, Map<String, Object> input,
194180
String expectedErrorSubstring) {
195-
var clientBuilder = clientBuilders.get("httpclient");
196181
Object server = createServerWithDefaultValidation(serverType);
197182

198183
try (var client = clientBuilder.clientInfo(new McpSchema.Implementation("test-client", "1.0.0")).build()) {
@@ -212,7 +197,6 @@ void invalidInput_withDefaultValidation_shouldReturnToolError(String serverType,
212197
@MethodSource("invalidInputTestCases")
213198
void invalidInput_withValidationDisabled_shouldSucceed(String serverType, Map<String, Object> input,
214199
String ignored) {
215-
var clientBuilder = clientBuilders.get("httpclient");
216200
Object server = createServer(serverType, false);
217201

218202
try (var client = clientBuilder.clientInfo(new McpSchema.Implementation("test-client", "1.0.0")).build()) {

0 commit comments

Comments
 (0)