mcp: make transports open structs
As described in #272, there is really no reason for transports to be closed structs with constructors, since their state must be established by a call to Connect. Making them open structs simplifies their APIs, and means that all transports can be extended in the future: we don't have to create empty Options structs just for the purpose of future compatibility. For now, the related constructors and options structs are simply deprecated (with go:fix directives where possible). A future CL will remove them prior to the v1.0.0 release. For #272
This commit is contained in:
parent
679f777825
commit
e097918484
1 changed files with 307 additions and 251 deletions
|
|
@ -44,7 +44,7 @@ func TestStreamableTransports(t *testing.T) {
|
|||
// 2. Start an httptest.Server with the StreamableHTTPHandler, wrapped in a
|
||||
// cookie-checking middleware.
|
||||
handler := NewStreamableHTTPHandler(func(req *http.Request) *Server { return server }, &StreamableHTTPOptions{
|
||||
transportOptions: &StreamableServerTransportOptions{jsonResponse: useJSON},
|
||||
jsonResponse: useJSON,
|
||||
})
|
||||
|
||||
var (
|
||||
|
|
@ -77,9 +77,10 @@ func TestStreamableTransports(t *testing.T) {
|
|||
}
|
||||
jar.SetCookies(u, []*http.Cookie{{Name: "test-cookie", Value: "test-value"}})
|
||||
httpClient := &http.Client{Jar: jar}
|
||||
transport := NewStreamableClientTransport(httpServer.URL, &StreamableClientTransportOptions{
|
||||
transport := &StreamableClientTransport{
|
||||
Endpoint: httpServer.URL,
|
||||
HTTPClient: httpClient,
|
||||
})
|
||||
}
|
||||
client := NewClient(testImpl, nil)
|
||||
session, err := client.Connect(ctx, transport, nil)
|
||||
if err != nil {
|
||||
|
|
@ -173,7 +174,7 @@ func TestClientReplay(t *testing.T) {
|
|||
notifications <- params.Message
|
||||
},
|
||||
})
|
||||
clientSession, err := client.Connect(ctx, NewStreamableClientTransport(proxy.URL, nil), nil)
|
||||
clientSession, err := client.Connect(ctx, &StreamableClientTransport{Endpoint: proxy.URL}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("client.Connect() failed: %v", err)
|
||||
}
|
||||
|
|
@ -239,7 +240,7 @@ func TestServerInitiatedSSE(t *testing.T) {
|
|||
notifications <- "toolListChanged"
|
||||
},
|
||||
})
|
||||
clientSession, err := client.Connect(ctx, NewStreamableClientTransport(httpServer.URL, nil), nil)
|
||||
clientSession, err := client.Connect(ctx, &StreamableClientTransport{Endpoint: httpServer.URL}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("client.Connect() failed: %v", err)
|
||||
}
|
||||
|
|
@ -765,7 +766,7 @@ func TestStreamableClientTransportApplicationJSON(t *testing.T) {
|
|||
httpServer := httptest.NewServer(http.HandlerFunc(serverHandler))
|
||||
defer httpServer.Close()
|
||||
|
||||
transport := NewStreamableClientTransport(httpServer.URL, nil)
|
||||
transport := &StreamableClientTransport{Endpoint: httpServer.URL}
|
||||
client := NewClient(testImpl, nil)
|
||||
session, err := client.Connect(ctx, transport, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue