@@ -402,6 +402,64 @@ void getIsRejected() throws Exception {
402402 assertThat (response .statusCode ()).isEqualTo (405 );
403403 }
404404
405+ @ Test
406+ void legacyInitializeIsAnsweredWithSupportedVersions () throws Exception {
407+ // What a 2025-era Streamable HTTP client sends: no Mcp-* headers, no _meta.
408+ HttpRequest request = HttpRequest .newBuilder ()
409+ .uri (URI .create ("http://localhost:" + PORT + ENDPOINT ))
410+ .header ("Content-Type" , "application/json" )
411+ .header ("Accept" , "application/json, text/event-stream" )
412+ .POST (HttpRequest .BodyPublishers .ofString ("""
413+ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25",\
414+ "capabilities":{},"clientInfo":{"name":"legacy-client","version":"1.0.0"}}}""" ))
415+ .build ();
416+ HttpResponse <String > response = HttpClient .newHttpClient ().send (request , HttpResponse .BodyHandlers .ofString ());
417+
418+ assertThat (response .statusCode ()).isEqualTo (400 );
419+ assertThatJson (response .body ()).inPath ("$.error.code" ).isEqualTo (ErrorCodes .UNSUPPORTED_PROTOCOL_VERSION );
420+ assertThatJson (response .body ()).inPath ("$.error.message" )
421+ .asString ()
422+ .contains (McpSchema .LATEST_PROTOCOL_VERSION );
423+ assertThatJson (response .body ()).inPath ("$.error.data" ).isEqualTo ("""
424+ {"supported": ["%s"], "requested": "2025-11-25"}""" .formatted (McpSchema .LATEST_PROTOCOL_VERSION ));
425+ }
426+
427+ @ Test
428+ void initializeWithBlankMetaVersionIsAnsweredWithSupportedVersions () throws Exception {
429+ // A blank _meta version names no revision: no header is required, and the server
430+ // rejects it like a legacy initialize.
431+ HttpRequest request = HttpRequest .newBuilder ()
432+ .uri (URI .create ("http://localhost:" + PORT + ENDPOINT ))
433+ .header ("Content-Type" , "application/json" )
434+ .header ("Accept" , "application/json, text/event-stream" )
435+ .POST (HttpRequest .BodyPublishers .ofString ("""
436+ {"jsonrpc":"2.0","id":1,"method":"initialize",\
437+ "params":{"_meta":{"io.modelcontextprotocol/protocolVersion":""}}}""" ))
438+ .build ();
439+ HttpResponse <String > response = HttpClient .newHttpClient ().send (request , HttpResponse .BodyHandlers .ofString ());
440+
441+ assertThat (response .statusCode ()).isEqualTo (400 );
442+ assertThatJson (response .body ()).inPath ("$.error.code" ).isEqualTo (ErrorCodes .UNSUPPORTED_PROTOCOL_VERSION );
443+ assertThatJson (response .body ()).inPath ("$.error.data" ).isEqualTo ("""
444+ {"supported": ["%s"], "requested": ""}""" .formatted (McpSchema .LATEST_PROTOCOL_VERSION ));
445+ }
446+
447+ @ Test
448+ void initializeWithModernMetaStillRequiresHeaders () throws Exception {
449+ Map <String , Object > body = Map .of ("jsonrpc" , "2.0" , "id" , 1 , "method" , "initialize" , "params" ,
450+ Map .of ("_meta" , meta ()));
451+ HttpRequest request = HttpRequest .newBuilder ()
452+ .uri (URI .create ("http://localhost:" + PORT + ENDPOINT ))
453+ .header ("Content-Type" , "application/json" )
454+ .header ("Accept" , "application/json, text/event-stream" )
455+ .POST (HttpRequest .BodyPublishers .ofString (JSON_MAPPER .writeValueAsString (body )))
456+ .build ();
457+ HttpResponse <String > response = HttpClient .newHttpClient ().send (request , HttpResponse .BodyHandlers .ofString ());
458+
459+ assertThat (response .statusCode ()).isEqualTo (400 );
460+ assertThat (errorCode (response )).isEqualTo (ErrorCodes .HEADER_MISMATCH );
461+ }
462+
405463 @ Test
406464 void headerMismatchIsRejected () throws Exception {
407465 Map <String , Object > params = new HashMap <>();
0 commit comments