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
4 changed files with 307 additions and 251 deletions
|
|
@ -41,7 +41,7 @@ func main() {
|
|||
ctx := context.Background()
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil)
|
||||
cs, err := client.Connect(ctx, mcp.NewCommandTransport(cmd), nil)
|
||||
cs, err := client.Connect(ctx, &mcp.CommandTransport{Command: cmd}, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func main() {
|
|||
log.Printf("MCP handler listening at %s", *httpAddr)
|
||||
http.ListenAndServe(*httpAddr, handler)
|
||||
} else {
|
||||
t := mcp.NewLoggingTransport(mcp.NewStdioTransport(), os.Stderr)
|
||||
t := &mcp.LoggingTransport{Transport: &mcp.StdioTransport{}, Writer: os.Stderr}
|
||||
if err := server.Run(context.Background(), t); err != nil {
|
||||
log.Printf("Server failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ func main() {
|
|||
log.Printf("MCP handler listening at %s", *httpAddr)
|
||||
http.ListenAndServe(*httpAddr, handler)
|
||||
} else {
|
||||
t := mcp.NewLoggingTransport(mcp.NewStdioTransport(), os.Stderr)
|
||||
t := &mcp.LoggingTransport{Transport: &mcp.StdioTransport{}, Writer: os.Stderr}
|
||||
if err := server.Run(context.Background(), t); err != nil {
|
||||
log.Printf("Server failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -536,7 +536,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
t := mcp.NewLoggingTransport(mcp.NewStdioTransport(), os.Stderr)
|
||||
t := &mcp.LoggingTransport{Transport: &mcp.StdioTransport{}, Writer: os.Stderr}
|
||||
if err := server.Run(context.Background(), t); err != nil {
|
||||
log.Printf("Server failed: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue