8
8
import static org .junit .jupiter .api .Assertions .assertEquals ;
9
9
import static org .junit .jupiter .api .Assertions .assertFalse ;
10
10
import static org .junit .jupiter .api .Assertions .assertNotNull ;
11
+ import static org .junit .jupiter .api .Assertions .assertNull ;
12
+ import static org .junit .jupiter .api .Assertions .assertTimeoutPreemptively ;
11
13
import static org .junit .jupiter .api .Assertions .assertTrue ;
12
14
13
15
import java .math .BigDecimal ;
14
16
import java .math .BigInteger ;
15
17
import java .nio .charset .StandardCharsets ;
18
+ import java .time .Duration ;
16
19
import java .util .List ;
17
20
import java .util .Map ;
18
21
import java .util .concurrent .atomic .AtomicReference ;
@@ -59,9 +62,48 @@ public void afterEach() {
59
62
}
60
63
}
61
64
65
+ private void initializeWithProtocolVersion (ProtocolVersion protocolVersion ) {
66
+ write ("initialize" , Document .of (Map .of ("protocolVersion" , Document .of (protocolVersion .identifier ()))));
67
+ var pv = read ().getResult ().getMember ("protocolVersion" ).asString ();
68
+ assertEquals (protocolVersion .identifier (), pv );
69
+ }
70
+
71
+ @ Test
72
+ public void noOutputSchemaWithUnsupportedProtocolVersion () {
73
+ server = McpServer .builder ()
74
+ .name ("smithy-mcp-server" )
75
+ .input (input )
76
+ .output (output )
77
+ .addService ("test-mcp" ,
78
+ ProxyService .builder ()
79
+ .service (ShapeId .from ("smithy.test#TestService" ))
80
+ .proxyEndpoint ("http://localhost" )
81
+ .model (MODEL )
82
+ .build ())
83
+ .build ();
84
+
85
+ server .start ();
86
+
87
+ initializeWithProtocolVersion (ProtocolVersion .v2025_03_26 .INSTANCE );
88
+ write ("tools/list" , Document .of (Map .of ()));
89
+ var response = read ();
90
+ var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
91
+
92
+ var tool = tools .stream ()
93
+ .filter (t -> t .asStringMap ().get ("name" ).asString ().equals ("NoInputOperation" ))
94
+ .findFirst ()
95
+ .orElseThrow ()
96
+ .asStringMap ();
97
+
98
+ assertEquals ("NoInputOperation" , tool .get ("name" ).asString ());
99
+ assertNotNull (tool .get ("inputSchema" ));
100
+ assertNull (tool .get ("outputSchema" ));
101
+ }
102
+
62
103
@ Test
63
104
public void validateToolsList () {
64
105
server = McpServer .builder ()
106
+ .name ("smithy-mcp-server" )
65
107
.input (input )
66
108
.output (output )
67
109
.addService ("test-mcp" ,
@@ -74,6 +116,7 @@ public void validateToolsList() {
74
116
75
117
server .start ();
76
118
119
+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
77
120
write ("tools/list" , Document .of (Map .of ()));
78
121
var response = read ();
79
122
var result = response .getResult ().asStringMap ();
@@ -94,6 +137,7 @@ public void validateToolsList() {
94
137
@ Test
95
138
public void validateNoIOOperationTool () {
96
139
server = McpServer .builder ()
140
+ .name ("smithy-mcp-server" )
97
141
.input (input )
98
142
.output (output )
99
143
.addService ("test-mcp" ,
@@ -106,6 +150,7 @@ public void validateNoIOOperationTool() {
106
150
107
151
server .start ();
108
152
153
+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
109
154
write ("tools/list" , Document .of (Map .of ()));
110
155
var response = read ();
111
156
var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -126,6 +171,7 @@ public void validateNoIOOperationTool() {
126
171
@ Test
127
172
public void validateNoOutputOperationTool () {
128
173
server = McpServer .builder ()
174
+ .name ("smithy-mcp-server" )
129
175
.input (input )
130
176
.output (output )
131
177
.addService ("test-mcp" ,
@@ -138,6 +184,7 @@ public void validateNoOutputOperationTool() {
138
184
139
185
server .start ();
140
186
187
+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
141
188
write ("tools/list" , Document .of (Map .of ()));
142
189
var response = read ();
143
190
var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -167,6 +214,7 @@ public void validateNoOutputOperationTool() {
167
214
@ Test
168
215
public void validateNoInputOperationTool () {
169
216
server = McpServer .builder ()
217
+ .name ("smithy-mcp-server" )
170
218
.input (input )
171
219
.output (output )
172
220
.addService ("test-mcp" ,
@@ -179,6 +227,7 @@ public void validateNoInputOperationTool() {
179
227
180
228
server .start ();
181
229
230
+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
182
231
write ("tools/list" , Document .of (Map .of ()));
183
232
var response = read ();
184
233
var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -208,6 +257,7 @@ public void validateNoInputOperationTool() {
208
257
@ Test
209
258
public void validateTestOperationTool () {
210
259
server = McpServer .builder ()
260
+ .name ("smithy-mcp-server" )
211
261
.input (input )
212
262
.output (output )
213
263
.addService ("test-mcp" ,
@@ -220,6 +270,7 @@ public void validateTestOperationTool() {
220
270
221
271
server .start ();
222
272
273
+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
223
274
write ("tools/list" , Document .of (Map .of ()));
224
275
var response = read ();
225
276
var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -240,6 +291,7 @@ public void validateTestOperationTool() {
240
291
@ Test
241
292
void testNumberAndStringIds () {
242
293
server = McpServer .builder ()
294
+ .name ("smithy-mcp-server" )
243
295
.input (input )
244
296
.output (output )
245
297
.addService ("test-mcp" ,
@@ -285,6 +337,7 @@ void testNumberAndStringIds() {
285
337
@ Test
286
338
void testInvalidIds () {
287
339
server = McpServer .builder ()
340
+ .name ("smithy-mcp-server" )
288
341
.input (input )
289
342
.output (output )
290
343
.addService ("test-mcp" ,
@@ -327,6 +380,7 @@ void testInvalidIds() {
327
380
@ Test
328
381
void testRequestsRequireIds () {
329
382
server = McpServer .builder ()
383
+ .name ("smithy-mcp-server" )
330
384
.input (input )
331
385
.output (output )
332
386
.addService ("test-mcp" ,
@@ -350,6 +404,7 @@ void testRequestsRequireIds() {
350
404
void testInputAdaptation () {
351
405
AtomicReference <StructDocument > capturedInput = new AtomicReference <>();
352
406
server = McpServer .builder ()
407
+ .name ("smithy-mcp-server" )
353
408
.input (input )
354
409
.output (output )
355
410
.addService ("test-mcp" ,
@@ -456,6 +511,7 @@ public void readBeforeSerialization(InputHook<?, ?> hook) {
456
511
@ Test
457
512
void testNotificationsDoNotRequireRequestId () {
458
513
server = McpServer .builder ()
514
+ .name ("smithy-mcp-server" )
459
515
.input (input )
460
516
.output (output )
461
517
.addService ("test-mcp" ,
@@ -485,6 +541,7 @@ void testNotificationsDoNotRequireRequestId() {
485
541
@ Test
486
542
void testPromptsList () {
487
543
server = McpServer .builder ()
544
+ .name ("smithy-mcp-server" )
488
545
.input (input )
489
546
.output (output )
490
547
.addService ("test-mcp" ,
@@ -528,6 +585,7 @@ void testPromptsList() {
528
585
@ Test
529
586
void testPromptsGetWithValidPrompt () {
530
587
server = McpServer .builder ()
588
+ .name ("smithy-mcp-server" )
531
589
.input (input )
532
590
.output (output )
533
591
.addService ("test-mcp" ,
@@ -561,6 +619,7 @@ void testPromptsGetWithValidPrompt() {
561
619
@ Test
562
620
void testPromptsGetWithDifferentCasing () {
563
621
server = McpServer .builder ()
622
+ .name ("smithy-mcp-server" )
564
623
.input (input )
565
624
.output (output )
566
625
.addService ("test-mcp" ,
@@ -631,6 +690,7 @@ void testPromptsGetWithDifferentCasing() {
631
690
@ Test
632
691
void testPromptsGetWithInvalidPrompt () {
633
692
server = McpServer .builder ()
693
+ .name ("smithy-mcp-server" )
634
694
.input (input )
635
695
.output (output )
636
696
.addService ("test-mcp" ,
@@ -670,6 +730,7 @@ void testPromptsGetWithTemplateArguments() {
670
730
.unwrap ();
671
731
672
732
server = McpServer .builder ()
733
+ .name ("smithy-mcp-server" )
673
734
.input (input )
674
735
.output (output )
675
736
.addService ("test-mcp" ,
@@ -711,6 +772,7 @@ void testPromptsGetWithMissingRequiredArguments() {
711
772
.unwrap ();
712
773
713
774
server = McpServer .builder ()
775
+ .name ("smithy-mcp-server" )
714
776
.input (input )
715
777
.output (output )
716
778
.addService ("test-mcp" ,
@@ -748,6 +810,7 @@ void testApplyTemplateArgumentsEdgeCases() {
748
810
.unwrap ();
749
811
750
812
server = McpServer .builder ()
813
+ .name ("smithy-mcp-server" )
751
814
.input (input )
752
815
.output (output )
753
816
.addService ("test-mcp" ,
@@ -942,7 +1005,7 @@ private void write(String method, Document document, Document requestId) {
942
1005
}
943
1006
944
1007
private JsonRpcResponse read () {
945
- var line = output . read ( );
1008
+ var line = assertTimeoutPreemptively ( Duration . ofSeconds ( 1 ), output :: read , "No response within one second" );
946
1009
return CODEC .deserializeShape (line , JsonRpcResponse .builder ());
947
1010
}
948
1011
0 commit comments