88import static org .junit .jupiter .api .Assertions .assertEquals ;
99import static org .junit .jupiter .api .Assertions .assertFalse ;
1010import 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 ;
1113import static org .junit .jupiter .api .Assertions .assertTrue ;
1214
1315import java .math .BigDecimal ;
1416import java .math .BigInteger ;
1517import java .nio .charset .StandardCharsets ;
18+ import java .time .Duration ;
1619import java .util .List ;
1720import java .util .Map ;
1821import java .util .concurrent .atomic .AtomicReference ;
@@ -59,9 +62,48 @@ public void afterEach() {
5962 }
6063 }
6164
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+
62103 @ Test
63104 public void validateToolsList () {
64105 server = McpServer .builder ()
106+ .name ("smithy-mcp-server" )
65107 .input (input )
66108 .output (output )
67109 .addService ("test-mcp" ,
@@ -74,6 +116,7 @@ public void validateToolsList() {
74116
75117 server .start ();
76118
119+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
77120 write ("tools/list" , Document .of (Map .of ()));
78121 var response = read ();
79122 var result = response .getResult ().asStringMap ();
@@ -94,6 +137,7 @@ public void validateToolsList() {
94137 @ Test
95138 public void validateNoIOOperationTool () {
96139 server = McpServer .builder ()
140+ .name ("smithy-mcp-server" )
97141 .input (input )
98142 .output (output )
99143 .addService ("test-mcp" ,
@@ -106,6 +150,7 @@ public void validateNoIOOperationTool() {
106150
107151 server .start ();
108152
153+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
109154 write ("tools/list" , Document .of (Map .of ()));
110155 var response = read ();
111156 var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -126,6 +171,7 @@ public void validateNoIOOperationTool() {
126171 @ Test
127172 public void validateNoOutputOperationTool () {
128173 server = McpServer .builder ()
174+ .name ("smithy-mcp-server" )
129175 .input (input )
130176 .output (output )
131177 .addService ("test-mcp" ,
@@ -138,6 +184,7 @@ public void validateNoOutputOperationTool() {
138184
139185 server .start ();
140186
187+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
141188 write ("tools/list" , Document .of (Map .of ()));
142189 var response = read ();
143190 var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -167,6 +214,7 @@ public void validateNoOutputOperationTool() {
167214 @ Test
168215 public void validateNoInputOperationTool () {
169216 server = McpServer .builder ()
217+ .name ("smithy-mcp-server" )
170218 .input (input )
171219 .output (output )
172220 .addService ("test-mcp" ,
@@ -179,6 +227,7 @@ public void validateNoInputOperationTool() {
179227
180228 server .start ();
181229
230+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
182231 write ("tools/list" , Document .of (Map .of ()));
183232 var response = read ();
184233 var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -208,6 +257,7 @@ public void validateNoInputOperationTool() {
208257 @ Test
209258 public void validateTestOperationTool () {
210259 server = McpServer .builder ()
260+ .name ("smithy-mcp-server" )
211261 .input (input )
212262 .output (output )
213263 .addService ("test-mcp" ,
@@ -220,6 +270,7 @@ public void validateTestOperationTool() {
220270
221271 server .start ();
222272
273+ initializeWithProtocolVersion (ProtocolVersion .v2025_06_18 .INSTANCE );
223274 write ("tools/list" , Document .of (Map .of ()));
224275 var response = read ();
225276 var tools = response .getResult ().asStringMap ().get ("tools" ).asList ();
@@ -240,6 +291,7 @@ public void validateTestOperationTool() {
240291 @ Test
241292 void testNumberAndStringIds () {
242293 server = McpServer .builder ()
294+ .name ("smithy-mcp-server" )
243295 .input (input )
244296 .output (output )
245297 .addService ("test-mcp" ,
@@ -285,6 +337,7 @@ void testNumberAndStringIds() {
285337 @ Test
286338 void testInvalidIds () {
287339 server = McpServer .builder ()
340+ .name ("smithy-mcp-server" )
288341 .input (input )
289342 .output (output )
290343 .addService ("test-mcp" ,
@@ -327,6 +380,7 @@ void testInvalidIds() {
327380 @ Test
328381 void testRequestsRequireIds () {
329382 server = McpServer .builder ()
383+ .name ("smithy-mcp-server" )
330384 .input (input )
331385 .output (output )
332386 .addService ("test-mcp" ,
@@ -350,6 +404,7 @@ void testRequestsRequireIds() {
350404 void testInputAdaptation () {
351405 AtomicReference <StructDocument > capturedInput = new AtomicReference <>();
352406 server = McpServer .builder ()
407+ .name ("smithy-mcp-server" )
353408 .input (input )
354409 .output (output )
355410 .addService ("test-mcp" ,
@@ -456,6 +511,7 @@ public void readBeforeSerialization(InputHook<?, ?> hook) {
456511 @ Test
457512 void testNotificationsDoNotRequireRequestId () {
458513 server = McpServer .builder ()
514+ .name ("smithy-mcp-server" )
459515 .input (input )
460516 .output (output )
461517 .addService ("test-mcp" ,
@@ -485,6 +541,7 @@ void testNotificationsDoNotRequireRequestId() {
485541 @ Test
486542 void testPromptsList () {
487543 server = McpServer .builder ()
544+ .name ("smithy-mcp-server" )
488545 .input (input )
489546 .output (output )
490547 .addService ("test-mcp" ,
@@ -528,6 +585,7 @@ void testPromptsList() {
528585 @ Test
529586 void testPromptsGetWithValidPrompt () {
530587 server = McpServer .builder ()
588+ .name ("smithy-mcp-server" )
531589 .input (input )
532590 .output (output )
533591 .addService ("test-mcp" ,
@@ -561,6 +619,7 @@ void testPromptsGetWithValidPrompt() {
561619 @ Test
562620 void testPromptsGetWithDifferentCasing () {
563621 server = McpServer .builder ()
622+ .name ("smithy-mcp-server" )
564623 .input (input )
565624 .output (output )
566625 .addService ("test-mcp" ,
@@ -631,6 +690,7 @@ void testPromptsGetWithDifferentCasing() {
631690 @ Test
632691 void testPromptsGetWithInvalidPrompt () {
633692 server = McpServer .builder ()
693+ .name ("smithy-mcp-server" )
634694 .input (input )
635695 .output (output )
636696 .addService ("test-mcp" ,
@@ -670,6 +730,7 @@ void testPromptsGetWithTemplateArguments() {
670730 .unwrap ();
671731
672732 server = McpServer .builder ()
733+ .name ("smithy-mcp-server" )
673734 .input (input )
674735 .output (output )
675736 .addService ("test-mcp" ,
@@ -711,6 +772,7 @@ void testPromptsGetWithMissingRequiredArguments() {
711772 .unwrap ();
712773
713774 server = McpServer .builder ()
775+ .name ("smithy-mcp-server" )
714776 .input (input )
715777 .output (output )
716778 .addService ("test-mcp" ,
@@ -748,6 +810,7 @@ void testApplyTemplateArgumentsEdgeCases() {
748810 .unwrap ();
749811
750812 server = McpServer .builder ()
813+ .name ("smithy-mcp-server" )
751814 .input (input )
752815 .output (output )
753816 .addService ("test-mcp" ,
@@ -942,7 +1005,7 @@ private void write(String method, Document document, Document requestId) {
9421005 }
9431006
9441007 private JsonRpcResponse read () {
945- var line = output . read ( );
1008+ var line = assertTimeoutPreemptively ( Duration . ofSeconds ( 1 ), output :: read , "No response within one second" );
9461009 return CODEC .deserializeShape (line , JsonRpcResponse .builder ());
9471010 }
9481011
0 commit comments