|
4 | 4 |
|
5 | 5 | package io.modelcontextprotocol; |
6 | 6 |
|
| 7 | +import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA; |
| 8 | + |
7 | 9 | import java.net.URI; |
8 | 10 | import java.net.http.HttpClient; |
9 | 11 | import java.net.http.HttpRequest; |
@@ -105,7 +107,7 @@ void testCreateMessageWithoutSamplingCapabilities(String clientType) { |
105 | 107 | var clientBuilder = clientBuilders.get(clientType); |
106 | 108 |
|
107 | 109 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
108 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 110 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
109 | 111 | .callHandler((exchange, request) -> { |
110 | 112 | return exchange.createMessage(mock(McpSchema.CreateMessageRequest.class)) |
111 | 113 | .then(Mono.just(mock(CallToolResult.class))); |
@@ -155,7 +157,7 @@ void testCreateMessageSuccess(String clientType) { |
155 | 157 | AtomicReference<CreateMessageResult> samplingResult = new AtomicReference<>(); |
156 | 158 |
|
157 | 159 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
158 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 160 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
159 | 161 | .callHandler((exchange, request) -> { |
160 | 162 |
|
161 | 163 | var createMessageRequest = McpSchema.CreateMessageRequest.builder() |
@@ -234,7 +236,7 @@ void testCreateMessageWithRequestTimeoutSuccess(String clientType) throws Interr |
234 | 236 | AtomicReference<CreateMessageResult> samplingResult = new AtomicReference<>(); |
235 | 237 |
|
236 | 238 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
237 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 239 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
238 | 240 | .callHandler((exchange, request) -> { |
239 | 241 |
|
240 | 242 | var createMessageRequest = McpSchema.CreateMessageRequest.builder() |
@@ -309,7 +311,7 @@ void testCreateMessageWithRequestTimeoutFail(String clientType) throws Interrupt |
309 | 311 | .build(); |
310 | 312 |
|
311 | 313 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
312 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 314 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
313 | 315 | .callHandler((exchange, request) -> { |
314 | 316 |
|
315 | 317 | var createMessageRequest = McpSchema.CreateMessageRequest.builder() |
@@ -359,7 +361,7 @@ void testCreateElicitationWithoutElicitationCapabilities(String clientType) { |
359 | 361 | var clientBuilder = clientBuilders.get(clientType); |
360 | 362 |
|
361 | 363 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
362 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 364 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
363 | 365 | .callHandler((exchange, request) -> exchange.createElicitation(mock(ElicitRequest.class)) |
364 | 366 | .then(Mono.just(mock(CallToolResult.class)))) |
365 | 367 | .build(); |
@@ -405,7 +407,7 @@ void testCreateElicitationSuccess(String clientType) { |
405 | 407 | AtomicReference<McpSchema.ElicitResult> elicitResultRef = new AtomicReference<>(); |
406 | 408 |
|
407 | 409 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
408 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 410 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
409 | 411 | .callHandler((exchange, request) -> { |
410 | 412 |
|
411 | 413 | var elicitationRequest = McpSchema.ElicitRequest.builder() |
@@ -464,7 +466,7 @@ void testCreateElicitationWithRequestTimeoutSuccess(String clientType) { |
464 | 466 | AtomicReference<ElicitResult> resultRef = new AtomicReference<>(); |
465 | 467 |
|
466 | 468 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
467 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 469 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
468 | 470 | .callHandler((exchange, request) -> { |
469 | 471 |
|
470 | 472 | var elicitationRequest = McpSchema.ElicitRequest.builder() |
@@ -535,7 +537,7 @@ void testCreateElicitationWithRequestTimeoutFail(String clientType) { |
535 | 537 | AtomicReference<ElicitResult> resultRef = new AtomicReference<>(); |
536 | 538 |
|
537 | 539 | McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder() |
538 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 540 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
539 | 541 | .callHandler((exchange, request) -> { |
540 | 542 |
|
541 | 543 | var elicitationRequest = ElicitRequest.builder() |
@@ -633,7 +635,7 @@ void testRootsWithoutCapability(String clientType) { |
633 | 635 | var clientBuilder = clientBuilders.get(clientType); |
634 | 636 |
|
635 | 637 | McpServerFeatures.SyncToolSpecification tool = McpServerFeatures.SyncToolSpecification.builder() |
636 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 638 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
637 | 639 | .callHandler((exchange, request) -> { |
638 | 640 |
|
639 | 641 | exchange.listRoots(); // try to list roots |
@@ -775,7 +777,7 @@ void testToolCallSuccess(String clientType) { |
775 | 777 | .addContent(new McpSchema.TextContent("CALL RESPONSE; ctx=importantValue")) |
776 | 778 | .build(); |
777 | 779 | McpServerFeatures.SyncToolSpecification tool1 = McpServerFeatures.SyncToolSpecification.builder() |
778 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 780 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
779 | 781 | .callHandler((exchange, request) -> { |
780 | 782 |
|
781 | 783 | try { |
@@ -826,7 +828,11 @@ void testThrowingToolCallIsCaughtBeforeTimeout(String clientType) { |
826 | 828 | McpSyncServer mcpServer = prepareSyncServerBuilder() |
827 | 829 | .capabilities(ServerCapabilities.builder().tools(true).build()) |
828 | 830 | .tools(McpServerFeatures.SyncToolSpecification.builder() |
829 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 831 | + .tool(Tool.builder() |
| 832 | + .name("tool1") |
| 833 | + .description("tool1 description") |
| 834 | + .inputSchema(EMPTY_JSON_SCHEMA) |
| 835 | + .build()) |
830 | 836 | .callHandler((exchange, request) -> { |
831 | 837 | // We trigger a timeout on blocking read, raising an exception |
832 | 838 | Mono.never().block(Duration.ofSeconds(1)); |
@@ -864,7 +870,7 @@ void testToolCallSuccessWithTranportContextExtraction(String clientType) { |
864 | 870 | .addContent(new McpSchema.TextContent("CALL RESPONSE; ctx=value")) |
865 | 871 | .build(); |
866 | 872 | McpServerFeatures.SyncToolSpecification tool1 = McpServerFeatures.SyncToolSpecification.builder() |
867 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 873 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
868 | 874 | .callHandler((exchange, request) -> { |
869 | 875 |
|
870 | 876 | McpTransportContext transportContext = exchange.transportContext(); |
@@ -920,7 +926,7 @@ void testToolListChangeHandlingSuccess(String clientType) { |
920 | 926 | .build(); |
921 | 927 |
|
922 | 928 | McpServerFeatures.SyncToolSpecification tool1 = McpServerFeatures.SyncToolSpecification.builder() |
923 | | - .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(Map.of()).build()) |
| 929 | + .tool(Tool.builder().name("tool1").description("tool1 description").inputSchema(EMPTY_JSON_SCHEMA).build()) |
924 | 930 | .callHandler((exchange, request) -> { |
925 | 931 | // perform a blocking call to a remote service |
926 | 932 | try { |
@@ -986,7 +992,11 @@ void testToolListChangeHandlingSuccess(String clientType) { |
986 | 992 |
|
987 | 993 | // Add a new tool |
988 | 994 | McpServerFeatures.SyncToolSpecification tool2 = McpServerFeatures.SyncToolSpecification.builder() |
989 | | - .tool(Tool.builder().name("tool2").description("tool2 description").inputSchema(Map.of()).build()) |
| 995 | + .tool(Tool.builder() |
| 996 | + .name("tool2") |
| 997 | + .description("tool2 description") |
| 998 | + .inputSchema(EMPTY_JSON_SCHEMA) |
| 999 | + .build()) |
990 | 1000 | .callHandler((exchange, request) -> callResponse) |
991 | 1001 | .build(); |
992 | 1002 |
|
@@ -1037,7 +1047,7 @@ void testLoggingNotification(String clientType) throws InterruptedException { |
1037 | 1047 | .tool(Tool.builder() |
1038 | 1048 | .name("logging-test") |
1039 | 1049 | .description("Test logging notifications") |
1040 | | - .inputSchema(Map.of()) |
| 1050 | + .inputSchema(EMPTY_JSON_SCHEMA) |
1041 | 1051 | .build()) |
1042 | 1052 | .callHandler((exchange, request) -> { |
1043 | 1053 |
|
@@ -1154,7 +1164,7 @@ void testProgressNotification(String clientType) throws InterruptedException { |
1154 | 1164 | .tool(McpSchema.Tool.builder() |
1155 | 1165 | .name("progress-test") |
1156 | 1166 | .description("Test progress notifications") |
1157 | | - .inputSchema(Map.of()) |
| 1167 | + .inputSchema(EMPTY_JSON_SCHEMA) |
1158 | 1168 | .build()) |
1159 | 1169 | .callHandler((exchange, request) -> { |
1160 | 1170 |
|
@@ -1312,7 +1322,7 @@ void testPingSuccess(String clientType) { |
1312 | 1322 | .tool(Tool.builder() |
1313 | 1323 | .name("ping-async-test") |
1314 | 1324 | .description("Test ping async behavior") |
1315 | | - .inputSchema(Map.of()) |
| 1325 | + .inputSchema(EMPTY_JSON_SCHEMA) |
1316 | 1326 | .build()) |
1317 | 1327 | .callHandler((exchange, request) -> { |
1318 | 1328 |
|
|
0 commit comments