Skip to content

Commit 1a17136

Browse files
committed
fix SSE client start
Signed-off-by: Donnie Adams <[email protected]>
1 parent acdf274 commit 1a17136

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/mcp/loader.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/getkin/kin-openapi/openapi3"
1414
"github.com/gptscript-ai/gptscript/pkg/hash"
15+
"github.com/gptscript-ai/gptscript/pkg/mvl"
1516
"github.com/gptscript-ai/gptscript/pkg/types"
1617
"github.com/gptscript-ai/gptscript/pkg/version"
1718
"github.com/mark3labs/mcp-go/client"
@@ -21,6 +22,8 @@ import (
2122
var (
2223
DefaultLoader = &Local{}
2324
DefaultRunner = DefaultLoader
25+
26+
logger = mvl.Package()
2427
)
2528

2629
type Local struct {
@@ -116,6 +119,7 @@ func (l *Local) Close() error {
116119

117120
var errs []error
118121
for id, session := range l.sessions {
122+
logger.Infof("closing MCP session %s", id)
119123
if err := session.Client.Close(); err != nil {
120124
errs = append(errs, fmt.Errorf("failed to close MCP client %s: %w", id, err))
121125
}
@@ -229,7 +233,7 @@ func (l *Local) loadSession(ctx context.Context, server ServerConfig) (*Session,
229233
}
230234

231235
var (
232-
c client.MCPClient
236+
c *client.Client
233237
err error
234238
)
235239
if server.Command != "" {
@@ -248,10 +252,16 @@ func (l *Local) loadSession(ctx context.Context, server ServerConfig) (*Session,
248252
k, v, _ := strings.Cut(h, "=")
249253
headers[k] = v
250254
}
255+
251256
c, err = client.NewSSEMCPClient(url, client.WithHeaders(headers))
252257
if err != nil {
253258
return nil, fmt.Errorf("failed to create MCP HTTP client: %w", err)
254259
}
260+
261+
// We expect the client to outlive this one request.
262+
if err = c.Start(context.Background()); err != nil {
263+
return nil, fmt.Errorf("failed to start MCP client: %w", err)
264+
}
255265
}
256266

257267
var initRequest mcp.InitializeRequest

0 commit comments

Comments
 (0)