@@ -204,6 +204,27 @@ void testInvalidIds() {
204204 assertTrue (response .getError ().getMessage ().contains ("Request id is of invalid type" ));
205205 }
206206
207+ @ Test
208+ void testRequestsRequireIds () {
209+ server = McpServer .builder ()
210+ .input (input )
211+ .output (output )
212+ .addService (ProxyService .builder ()
213+ .service (ShapeId .from ("smithy.test#TestService" ))
214+ .proxyEndpoint ("http://localhost" )
215+ .model (MODEL )
216+ .build ())
217+ .build ();
218+
219+ server .start ();
220+
221+ // Test regular request without ID (should fail with specific message)
222+ write ("tools/list" , Document .of (Map .of ()), null );
223+ var response = read ();
224+ assertNotNull (response .getError ());
225+ assertTrue (response .getError ().getMessage ().contains ("Requests are expected to have ids" ));
226+ }
227+
207228 @ Test
208229 void testInputAdaptation () {
209230 AtomicReference <StructDocument > capturedInput = new AtomicReference <>();
@@ -309,6 +330,34 @@ public void readBeforeSerialization(InputHook<?, ?> hook) {
309330 server .shutdown ().join ();
310331 }
311332
333+ @ Test
334+ void testNotificationsDoNotRequireRequestId () {
335+ server = McpServer .builder ()
336+ .input (input )
337+ .output (output )
338+ .addService (ProxyService .builder ()
339+ .service (ShapeId .from ("smithy.test#TestService" ))
340+ .proxyEndpoint ("http://localhost" )
341+ .model (MODEL )
342+ .build ())
343+ .build ();
344+
345+ server .start ();
346+
347+ // Test notifications/initialized without ID (should not produce any error response)
348+ writeNotification ("notifications/initialized" , Document .of (Map .of ()));
349+ output .assertNoOutput ();
350+
351+ // Test another notification to ensure it's consistently handled
352+ writeNotification ("notifications/progress" , Document .of (Map .of ("progressToken" , Document .of ("test" ))));
353+ output .assertNoOutput ();
354+
355+ // Send a regular request to verify the server is still functioning
356+ write ("tools/list" , Document .of (Map .of ()));
357+ var response = read ();
358+ assertNotNull (response .getResult ());
359+ }
360+
312361 private void validateNestedStructure (Map <String , Document > properties ) {
313362 var nestedStr = properties .get ("nestedStr" ).asStringMap ();
314363 assertEquals ("string" , nestedStr .get ("type" ).asString ());
@@ -348,6 +397,16 @@ private JsonRpcResponse read() {
348397 return CODEC .deserializeShape (line , JsonRpcResponse .builder ());
349398 }
350399
400+ private void writeNotification (String method , Document params ) {
401+ var request = JsonRpcRequest .builder ()
402+ .method (method )
403+ .params (params )
404+ .jsonrpc ("2.0" )
405+ .build ();
406+ input .write (CODEC .serializeToString (request ));
407+ input .write ("\n " );
408+ }
409+
351410 private static final String MODEL_STR = """
352411 $version: "2"
353412
0 commit comments