@@ -12,21 +12,34 @@ import (
1212 "github.com/stretchr/testify/require"
1313)
1414
15- // newMinimalTestServer returns an httptest server that responds with a minimal
16- // JSON-RPC initialize result so NewHTTPConnection can complete its handshake.
15+ // newMinimalTestServer returns an httptest server that responds with the
16+ // minimal HTTP semantics needed for NewHTTPConnection to complete its SDK
17+ // transport handshake reliably.
1718func newMinimalTestServer (t * testing.T ) * httptest.Server {
1819 t .Helper ()
1920 return httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
20- resp := map [string ]interface {}{
21- "jsonrpc" : "2.0" ,
22- "id" : 1 ,
23- "result" : map [string ]interface {}{
24- "protocolVersion" : "2024-11-05" ,
25- "serverInfo" : map [string ]interface {}{"name" : "test" },
26- },
21+ switch r .Method {
22+ case http .MethodGet :
23+ w .Header ().Set ("Content-Type" , "text/event-stream" )
24+ w .WriteHeader (http .StatusOK )
25+ return
26+ case http .MethodPost :
27+ resp := map [string ]interface {}{
28+ "jsonrpc" : "2.0" ,
29+ "id" : 1 ,
30+ "result" : map [string ]interface {}{
31+ "protocolVersion" : "2024-11-05" ,
32+ "serverInfo" : map [string ]interface {}{"name" : "test" },
33+ },
34+ }
35+ w .Header ().Set ("Content-Type" , "application/json" )
36+ w .Header ().Set ("Mcp-Session-Id" , "test-session" )
37+ json .NewEncoder (w ).Encode (resp ) //nolint:errcheck
38+ return
39+ default :
40+ w .WriteHeader (http .StatusMethodNotAllowed )
41+ return
2742 }
28- w .Header ().Set ("Content-Type" , "application/json" )
29- json .NewEncoder (w ).Encode (resp ) //nolint:errcheck
3043 }))
3144}
3245
0 commit comments