Skip to content

Commit da6863f

Browse files
committed
pass profile to the CLI
1 parent 01922aa commit da6863f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

experimental/apps-mcp/lib/middlewares/databricks_client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
)
1616

1717
const (
18-
DatabricksClientKey = "databricks_client"
18+
DatabricksClientKey = "databricks_client"
19+
DatabricksProfileKey = "databricks_profile"
1920
)
2021

2122
func NewDatabricksClientMiddleware(unauthorizedToolNames []string) mcp.Middleware {
@@ -40,6 +41,18 @@ func NewDatabricksClientMiddleware(unauthorizedToolNames []string) mcp.Middlewar
4041
})
4142
}
4243

44+
func MustGetDatabricksProfile(ctx context.Context) string {
45+
sess, err := session.GetSession(ctx)
46+
if err != nil {
47+
panic(err)
48+
}
49+
profile, ok := sess.Get(DatabricksProfileKey)
50+
if !ok {
51+
return ""
52+
}
53+
return profile.(string)
54+
}
55+
4356
func MustGetApiClient(ctx context.Context) (*httpclient.ApiClient, error) {
4457
w := MustGetDatabricksClient(ctx)
4558
clientCfg, err := config.HTTPClientConfigFromConfig(w.Config)

experimental/apps-mcp/lib/providers/clitools/configure_auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func ConfigureAuth(ctx context.Context, sess *session.Session, host, profile *st
5555
// Store client in session data
5656
sess.Set(middlewares.DatabricksClientKey, client)
5757

58+
if profile == nil {
59+
sess.Set(middlewares.DatabricksProfileKey, client.Config.Profile)
60+
}
61+
5862
return client, nil
5963
}
6064

experimental/apps-mcp/lib/providers/clitools/invoke_databricks_cli.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ func InvokeDatabricksCLI(ctx context.Context, command []string, workingDirectory
2525
cmd := exec.CommandContext(ctx, cliPath, command...)
2626
cmd.Dir = workingDirectory
2727
env := os.Environ()
28-
env = append(env, "DATABRICKS_HOST="+host)
28+
29+
profile := middlewares.MustGetDatabricksProfile(ctx)
30+
if profile != "" {
31+
env = append(env, "DATABRICKS_CONFIG_PROFILE="+profile)
32+
}
33+
if host != "" {
34+
env = append(env, "DATABRICKS_HOST="+host)
35+
}
2936
cmd.Env = env
3037

3138
output, err := cmd.CombinedOutput()

0 commit comments

Comments
 (0)