@@ -11,8 +11,10 @@ import (
1111
1212 "github.com/stacklok/toolhive/pkg/auth"
1313 "github.com/stacklok/toolhive/pkg/client"
14+ "github.com/stacklok/toolhive/pkg/config"
1415 "github.com/stacklok/toolhive/pkg/logger"
1516 "github.com/stacklok/toolhive/pkg/process"
17+ "github.com/stacklok/toolhive/pkg/secrets"
1618 "github.com/stacklok/toolhive/pkg/transport"
1719 "github.com/stacklok/toolhive/pkg/transport/types"
1820)
@@ -24,9 +26,9 @@ type Runner struct {
2426}
2527
2628// NewRunner creates a new Runner with the provided configuration
27- func NewRunner (config * RunConfig ) * Runner {
29+ func NewRunner (runConfig * RunConfig ) * Runner {
2830 return & Runner {
29- Config : config ,
31+ Config : runConfig ,
3032 }
3133}
3234
@@ -83,6 +85,31 @@ func (r *Runner) Run(ctx context.Context) error {
8385 return fmt .Errorf ("failed to create transport: %v" , err )
8486 }
8587
88+ // Save the configuration to the state store
89+ if err := r .SaveState (ctx ); err != nil {
90+ logger .Warnf ("Warning: Failed to save run configuration: %v" , err )
91+ }
92+
93+ // Process secrets if provided
94+ // NOTE: This MUST happen after we save the run config to avoid storing
95+ // the secrets in the state store.
96+ if len (r .Config .Secrets ) > 0 {
97+ providerType , err := config .GetConfig ().Secrets .GetProviderType ()
98+ if err != nil {
99+ return fmt .Errorf ("error determining secrets provider type: %w" , err )
100+ }
101+
102+ secretManager , err := secrets .CreateSecretProvider (providerType )
103+ if err != nil {
104+ return fmt .Errorf ("error instantiating secret manager %v" , err )
105+ }
106+
107+ // Process secrets
108+ if _ , err = r .Config .WithSecrets (secretManager ); err != nil {
109+ return err
110+ }
111+ }
112+
86113 // Set up the transport
87114 logger .Infof ("Setting up %s transport..." , r .Config .Transport )
88115 if err := transportHandler .Setup (
@@ -100,11 +127,6 @@ func (r *Runner) Run(ctx context.Context) error {
100127
101128 logger .Infof ("MCP server %s started successfully" , r .Config .ContainerName )
102129
103- // Save the configuration to the state store
104- if err := r .SaveState (ctx ); err != nil {
105- logger .Warnf ("Warning: Failed to save run configuration: %v" , err )
106- }
107-
108130 // Update client configurations with the MCP server URL.
109131 // Note that this function checks the configuration to determine which
110132 // clients should be updated, if any.
@@ -199,12 +221,12 @@ func (r *Runner) Run(ctx context.Context) error {
199221// updateClientConfigurations updates client configuration files with the MCP server URL
200222func updateClientConfigurations (containerName , host string , port int ) error {
201223 // Find client configuration files
202- configs , err := client .FindClientConfigs ()
224+ clientConfigs , err := client .FindClientConfigs ()
203225 if err != nil {
204226 return fmt .Errorf ("failed to find client configurations: %w" , err )
205227 }
206228
207- if len (configs ) == 0 {
229+ if len (clientConfigs ) == 0 {
208230 logger .Infof ("No client configuration files found" )
209231 return nil
210232 }
@@ -213,15 +235,15 @@ func updateClientConfigurations(containerName, host string, port int) error {
213235 url := client .GenerateMCPServerURL (host , port , containerName )
214236
215237 // Update each configuration file
216- for _ , config := range configs {
217- logger .Infof ("Updating client configuration: %s" , config .Path )
238+ for _ , clientConfig := range clientConfigs {
239+ logger .Infof ("Updating client configuration: %s" , clientConfig .Path )
218240
219- if err := client .Upsert (config , containerName , url ); err != nil {
220- fmt .Printf ("Warning: Failed to update MCP server configuration in %s: %v\n " , config .Path , err )
241+ if err := client .Upsert (clientConfig , containerName , url ); err != nil {
242+ fmt .Printf ("Warning: Failed to update MCP server configuration in %s: %v\n " , clientConfig .Path , err )
221243 continue
222244 }
223245
224- logger .Infof ("Successfully updated client configuration: %s" , config .Path )
246+ logger .Infof ("Successfully updated client configuration: %s" , clientConfig .Path )
225247 }
226248
227249 return nil
0 commit comments