Skip to content

Commit

Permalink
✨ Add context support to client CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
wesen committed Jan 21, 2025
1 parent 58da7aa commit 7ea65a6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/mcp-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-go-golems/go-go-mcp/pkg/client"
"github.com/go-go-golems/go-go-mcp/pkg/protocol"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -331,24 +332,29 @@ func createClient(ctx context.Context) (*client.Client, error) {
if len(cmdArgs) == 0 {
return nil, fmt.Errorf("command is required for command transport")
}
log.Debug().Msgf("Creating command transport with args: %v", cmdArgs)
t, err = client.NewCommandStdioTransport(cmdArgs[0], cmdArgs[1:]...)
if err != nil {
return nil, fmt.Errorf("failed to create command transport: %w", err)
}
case "sse":
log.Debug().Msgf("Creating SSE transport with server URL: %s", serverURL)
t = client.NewSSETransport(serverURL)
default:
return nil, fmt.Errorf("invalid transport type: %s", transport)
}

// Create and initialize client
c := client.NewClient(logger, t)
log.Debug().Msgf("Initializing client")
err = c.Initialize(ctx, protocol.ClientCapabilities{
Sampling: &protocol.SamplingCapability{},
})
if err != nil {
return nil, fmt.Errorf("failed to initialize client: %w", err)
}

log.Debug().Msgf("Client initialized")

return c, nil
}

0 comments on commit 7ea65a6

Please sign in to comment.