@@ -679,6 +679,51 @@ func mustMarshal(t *testing.T, v any) json.RawMessage {
679679 return data
680680}
681681
682+ func TestStreamableClientTransportApplicationJSON (t * testing.T ) {
683+ // Test handling of application/json responses.
684+ ctx := context .Background ()
685+ resp := func (id int64 , result any , err error ) * jsonrpc.Response {
686+ return & jsonrpc.Response {
687+ ID : jsonrpc2 .Int64ID (id ),
688+ Result : mustMarshal (t , result ),
689+ Error : err ,
690+ }
691+ }
692+ initResult := & InitializeResult {
693+ Capabilities : & serverCapabilities {
694+ Completions : & completionCapabilities {},
695+ Logging : & loggingCapabilities {},
696+ Tools : & toolCapabilities {ListChanged : true },
697+ },
698+ ProtocolVersion : latestProtocolVersion ,
699+ ServerInfo : & Implementation {Name : "testServer" , Version : "v1.0.0" },
700+ }
701+ initResp := resp (1 , initResult , nil )
702+
703+ serverHandler := func (w http.ResponseWriter , r * http.Request ) {
704+ data , err := jsonrpc2 .EncodeMessage (initResp )
705+ if err != nil {
706+ t .Fatal (err )
707+ }
708+ w .Header ().Set ("Content-Type" , "application/json" )
709+ w .Write (data )
710+ }
711+
712+ httpServer := httptest .NewServer (http .HandlerFunc (serverHandler ))
713+ defer httpServer .Close ()
714+
715+ transport := NewStreamableClientTransport (httpServer .URL , nil )
716+ client := NewClient (testImpl , nil )
717+ session , err := client .Connect (ctx , transport )
718+ if err != nil {
719+ t .Fatalf ("client.Connect() failed: %v" , err )
720+ }
721+ defer session .Close ()
722+ if diff := cmp .Diff (initResult , session .initializeResult ); diff != "" {
723+ t .Errorf ("mismatch (-want, +got):\n %s" , diff )
724+ }
725+ }
726+
682727func TestEventID (t * testing.T ) {
683728 tests := []struct {
684729 sid StreamID
0 commit comments