mcp: remove deprecated transport constructors
In #272, we made transports open structs and deprecated their constructors. However, we left the constructors in place to allow go:fix directives to facilitate migration. Now let's remove the constructors before cutting the release. Fixes #305
This commit is contained in:
parent
5bbca40032
commit
b1c75f04d8
5 changed files with 1 additions and 124 deletions
13
mcp/cmd.go
13
mcp/cmd.go
|
|
@ -27,19 +27,6 @@ type CommandTransport struct {
|
||||||
TerminateDuration time.Duration
|
TerminateDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommandTransport returns a [CommandTransport] that runs the given command
|
|
||||||
// and communicates with it over stdin/stdout.
|
|
||||||
//
|
|
||||||
// The resulting transport takes ownership of the command, starting it during
|
|
||||||
// [CommandTransport.Connect], and stopping it when the connection is closed.
|
|
||||||
//
|
|
||||||
// Deprecated: use a CommandTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewCommandTransport(cmd *exec.Cmd) *CommandTransport {
|
|
||||||
return &CommandTransport{Command: cmd}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect starts the command, and connects to it over stdin/stdout.
|
// Connect starts the command, and connects to it over stdin/stdout.
|
||||||
func (t *CommandTransport) Connect(ctx context.Context) (Connection, error) {
|
func (t *CommandTransport) Connect(ctx context.Context) (Connection, error) {
|
||||||
stdout, err := t.Command.StdoutPipe()
|
stdout, err := t.Command.StdoutPipe()
|
||||||
|
|
|
||||||
37
mcp/sse.go
37
mcp/sse.go
|
|
@ -114,19 +114,6 @@ type SSEServerTransport struct {
|
||||||
done chan struct{} // closed when the connection is closed
|
done chan struct{} // closed when the connection is closed
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSSEServerTransport creates a new SSE transport for the given messages
|
|
||||||
// endpoint, and hanging GET response.
|
|
||||||
//
|
|
||||||
// Deprecated: use an SSEServerTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewSSEServerTransport(endpoint string, w http.ResponseWriter) *SSEServerTransport {
|
|
||||||
return &SSEServerTransport{
|
|
||||||
Endpoint: endpoint,
|
|
||||||
Response: w,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeHTTP handles POST requests to the transport endpoint.
|
// ServeHTTP handles POST requests to the transport endpoint.
|
||||||
func (t *SSEServerTransport) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (t *SSEServerTransport) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
if t.incoming == nil {
|
if t.incoming == nil {
|
||||||
|
|
@ -334,30 +321,6 @@ type SSEClientTransport struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSEClientTransportOptions provides options for the [NewSSEClientTransport]
|
|
||||||
// constructor.
|
|
||||||
//
|
|
||||||
// Deprecated: use an SSEClientTransport literal.
|
|
||||||
type SSEClientTransportOptions struct {
|
|
||||||
// HTTPClient is the client to use for making HTTP requests. If nil,
|
|
||||||
// http.DefaultClient is used.
|
|
||||||
HTTPClient *http.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSSEClientTransport returns a new client transport that connects to the
|
|
||||||
// SSE server at the provided URL.
|
|
||||||
//
|
|
||||||
// Deprecated: use an SSEClientTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewSSEClientTransport(endpoint string, opts *SSEClientTransportOptions) *SSEClientTransport {
|
|
||||||
t := &SSEClientTransport{Endpoint: endpoint}
|
|
||||||
if opts != nil {
|
|
||||||
t.HTTPClient = opts.HTTPClient
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect connects through the client endpoint.
|
// Connect connects through the client endpoint.
|
||||||
func (c *SSEClientTransport) Connect(ctx context.Context) (Connection, error) {
|
func (c *SSEClientTransport) Connect(ctx context.Context) (Connection, error) {
|
||||||
parsedURL, err := url.Parse(c.Endpoint)
|
parsedURL, err := url.Parse(c.Endpoint)
|
||||||
|
|
|
||||||
|
|
@ -323,15 +323,6 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
|
||||||
transport.ServeHTTP(w, req)
|
transport.ServeHTTP(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamableServerTransportOptions configures the stramable server transport.
|
|
||||||
//
|
|
||||||
// Deprecated: use a StreamableServerTransport literal.
|
|
||||||
type StreamableServerTransportOptions struct {
|
|
||||||
// Storage for events, to enable stream resumption.
|
|
||||||
// If nil, a [MemoryEventStore] with the default maximum size will be used.
|
|
||||||
EventStore EventStore
|
|
||||||
}
|
|
||||||
|
|
||||||
// A StreamableServerTransport implements the server side of the MCP streamable
|
// A StreamableServerTransport implements the server side of the MCP streamable
|
||||||
// transport.
|
// transport.
|
||||||
//
|
//
|
||||||
|
|
@ -385,22 +376,6 @@ type StreamableServerTransport struct {
|
||||||
connection *streamableServerConn
|
connection *streamableServerConn
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStreamableServerTransport returns a new [StreamableServerTransport] with
|
|
||||||
// the given session ID and options.
|
|
||||||
//
|
|
||||||
// Deprecated: use a StreamableServerTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline.
|
|
||||||
func NewStreamableServerTransport(sessionID string, opts *StreamableServerTransportOptions) *StreamableServerTransport {
|
|
||||||
t := &StreamableServerTransport{
|
|
||||||
SessionID: sessionID,
|
|
||||||
}
|
|
||||||
if opts != nil {
|
|
||||||
t.EventStore = opts.EventStore
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect implements the [Transport] interface.
|
// Connect implements the [Transport] interface.
|
||||||
func (t *StreamableServerTransport) Connect(ctx context.Context) (Connection, error) {
|
func (t *StreamableServerTransport) Connect(ctx context.Context) (Connection, error) {
|
||||||
if t.connection != nil {
|
if t.connection != nil {
|
||||||
|
|
@ -1025,34 +1000,6 @@ const (
|
||||||
reconnectMaxDelay = 30 * time.Second
|
reconnectMaxDelay = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// StreamableClientTransportOptions provides options for the
|
|
||||||
// [NewStreamableClientTransport] constructor.
|
|
||||||
//
|
|
||||||
// Deprecated: use a StremableClientTransport literal.
|
|
||||||
type StreamableClientTransportOptions struct {
|
|
||||||
// HTTPClient is the client to use for making HTTP requests. If nil,
|
|
||||||
// http.DefaultClient is used.
|
|
||||||
HTTPClient *http.Client
|
|
||||||
// MaxRetries is the maximum number of times to attempt a reconnect before giving up.
|
|
||||||
// It defaults to 5. To disable retries, use a negative number.
|
|
||||||
MaxRetries int
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewStreamableClientTransport returns a new client transport that connects to
|
|
||||||
// the streamable HTTP server at the provided URL.
|
|
||||||
//
|
|
||||||
// Deprecated: use a StreamableClientTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewStreamableClientTransport(url string, opts *StreamableClientTransportOptions) *StreamableClientTransport {
|
|
||||||
t := &StreamableClientTransport{Endpoint: url}
|
|
||||||
if opts != nil {
|
|
||||||
t.HTTPClient = opts.HTTPClient
|
|
||||||
t.MaxRetries = opts.MaxRetries
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect implements the [Transport] interface.
|
// Connect implements the [Transport] interface.
|
||||||
//
|
//
|
||||||
// The resulting [Connection] writes messages via POST requests to the
|
// The resulting [Connection] writes messages via POST requests to the
|
||||||
|
|
|
||||||
|
|
@ -1211,7 +1211,7 @@ func TestTokenInfo(t *testing.T) {
|
||||||
httpServer := httptest.NewServer(handler)
|
httpServer := httptest.NewServer(handler)
|
||||||
defer httpServer.Close()
|
defer httpServer.Close()
|
||||||
|
|
||||||
transport := NewStreamableClientTransport(httpServer.URL, nil)
|
transport := &StreamableClientTransport{Endpoint: httpServer.URL}
|
||||||
client := NewClient(testImpl, nil)
|
client := NewClient(testImpl, nil)
|
||||||
session, err := client.Connect(ctx, transport, nil)
|
session, err := client.Connect(ctx, transport, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -93,16 +93,6 @@ func (*StdioTransport) Connect(context.Context) (Connection, error) {
|
||||||
return newIOConn(rwc{os.Stdin, os.Stdout}), nil
|
return newIOConn(rwc{os.Stdin, os.Stdout}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStdioTransport constructs a transport that communicates over
|
|
||||||
// stdin/stdout.
|
|
||||||
//
|
|
||||||
// Deprecated: use a StdioTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewStdioTransport() *StdioTransport {
|
|
||||||
return &StdioTransport{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// An InMemoryTransport is a [Transport] that communicates over an in-memory
|
// An InMemoryTransport is a [Transport] that communicates over an in-memory
|
||||||
// network connection, using newline-delimited JSON.
|
// network connection, using newline-delimited JSON.
|
||||||
type InMemoryTransport struct {
|
type InMemoryTransport struct {
|
||||||
|
|
@ -215,16 +205,6 @@ type LoggingTransport struct {
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLoggingTransport creates a new LoggingTransport that delegates to the
|
|
||||||
// provided transport, writing RPC logs to the provided io.Writer.
|
|
||||||
//
|
|
||||||
// Deprecated: use a LoggingTransport literal.
|
|
||||||
//
|
|
||||||
//go:fix inline
|
|
||||||
func NewLoggingTransport(delegate Transport, w io.Writer) *LoggingTransport {
|
|
||||||
return &LoggingTransport{Transport: delegate, Writer: w}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect connects the underlying transport, returning a [Connection] that writes
|
// Connect connects the underlying transport, returning a [Connection] that writes
|
||||||
// logs to the configured destination.
|
// logs to the configured destination.
|
||||||
func (t *LoggingTransport) Connect(ctx context.Context) (Connection, error) {
|
func (t *LoggingTransport) Connect(ctx context.Context) (Connection, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue