Skip to content

Commit cecac51

Browse files
committed
Complete outgoing authentication integration in serve command
Finalizes the end-to-end authentication flow by connecting the authentication factory, backend discoverer, and HTTP client in the serve command. This enables vMCP proxy to authenticate requests to downstream MCP servers using configured authentication strategies. The serve command now: - Creates outgoing authenticator from configuration using the factory - Provides authentication config to backend discoverer for setup - Supplies authenticator to HTTP client for request signing - Uses factory for incoming authentication middleware (consistency) This completes the authentication architecture where configuration flows through the factory to create strategies that are applied by the client's round tripper to outgoing requests. Also simplifies redundant type annotation in client variable declaration for consistency with Go style conventions.
1 parent 536edb6 commit cecac51

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cmd/vmcp/app/commands.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/stacklok/toolhive/pkg/groups"
1313
"github.com/stacklok/toolhive/pkg/logger"
1414
"github.com/stacklok/toolhive/pkg/vmcp/aggregator"
15-
vmcpauth "github.com/stacklok/toolhive/pkg/vmcp/auth"
15+
"github.com/stacklok/toolhive/pkg/vmcp/auth/factory"
1616
vmcpclient "github.com/stacklok/toolhive/pkg/vmcp/client"
1717
"github.com/stacklok/toolhive/pkg/vmcp/config"
1818
vmcprouter "github.com/stacklok/toolhive/pkg/vmcp/router"
@@ -213,8 +213,15 @@ func runServe(cmd *cobra.Command, _ []string) error {
213213
return fmt.Errorf("failed to create groups manager: %w", err)
214214
}
215215

216+
// Create outgoing authentication registry from configuration
217+
logger.Info("Initializing outgoing authentication")
218+
outgoingRegistry, err := factory.NewOutgoingAuthRegistry(ctx, cfg.OutgoingAuth)
219+
if err != nil {
220+
return fmt.Errorf("failed to create outgoing authentication registry: %w", err)
221+
}
222+
216223
// Create backend discoverer
217-
discoverer := aggregator.NewCLIBackendDiscoverer(workloadsManager, groupsManager)
224+
discoverer := aggregator.NewCLIBackendDiscoverer(workloadsManager, groupsManager, cfg.OutgoingAuth)
218225

219226
// Discover backends from the configured group
220227
logger.Infof("Discovering backends in group: %s", cfg.GroupRef)
@@ -230,7 +237,10 @@ func runServe(cmd *cobra.Command, _ []string) error {
230237
logger.Infof("Discovered %d backends", len(backends))
231238

232239
// Create backend client
233-
backendClient := vmcpclient.NewHTTPBackendClient()
240+
backendClient, err := vmcpclient.NewHTTPBackendClient(outgoingRegistry)
241+
if err != nil {
242+
return fmt.Errorf("failed to create backend client: %w", err)
243+
}
234244

235245
// Create conflict resolver based on configuration
236246
// Use the factory method that handles all strategies
@@ -264,7 +274,7 @@ func runServe(cmd *cobra.Command, _ []string) error {
264274
// Setup authentication middleware
265275
logger.Infof("Setting up incoming authentication (type: %s)", cfg.IncomingAuth.Type)
266276

267-
authMiddleware, authInfoHandler, err := vmcpauth.NewIncomingAuthMiddleware(ctx, cfg.IncomingAuth)
277+
authMiddleware, authInfoHandler, err := factory.NewIncomingAuthMiddleware(ctx, cfg.IncomingAuth)
268278
if err != nil {
269279
return fmt.Errorf("failed to create authentication middleware: %w", err)
270280
}

pkg/vmcp/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (h *httpBackendClient) resolveAuthStrategy(target *vmcp.BackendTarget) (aut
130130
// defaultClientFactory creates mark3labs MCP clients for different transport types.
131131
func (h *httpBackendClient) defaultClientFactory(ctx context.Context, target *vmcp.BackendTarget) (*client.Client, error) {
132132
// Build transport chain: size limit → authentication → HTTP
133-
var baseTransport http.RoundTripper = http.DefaultTransport
133+
var baseTransport = http.DefaultTransport
134134

135135
// Resolve authentication strategy ONCE at client creation time
136136
authStrategy, err := h.resolveAuthStrategy(target)

0 commit comments

Comments
 (0)