Skip to content

Commit a4bb582

Browse files
add user email to google mcp
Signed-off-by: Michael Clifford <mcliffor@redhat.com>
1 parent 6b33b78 commit a4bb582

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

components/backend/handlers/sessions.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ func CreateSession(c *gin.Context) {
663663
displayName = s
664664
}
665665
}
666+
667+
// Extract email from authenticated user
668+
email := ""
669+
if v, ok := c.Get("userEmail"); ok {
670+
if s, ok2 := v.(string); ok2 {
671+
email = strings.TrimSpace(s)
672+
}
673+
}
674+
// Fallback to userID if no explicit email (userID is often the email)
675+
if email == "" {
676+
email = uid
677+
}
678+
666679
groups := []string{}
667680
if v, ok := c.Get("userGroups"); ok {
668681
if gg, ok2 := v.([]string); ok2 {
@@ -679,6 +692,7 @@ func CreateSession(c *gin.Context) {
679692
session["spec"].(map[string]interface{})["userContext"] = map[string]interface{}{
680693
"userId": uid,
681694
"displayName": displayName,
695+
"email": email,
682696
"groups": groups,
683697
}
684698
}

components/backend/types/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type GitRepository struct {
1212
type UserContext struct {
1313
UserID string `json:"userId" binding:"required"`
1414
DisplayName string `json:"displayName" binding:"required"`
15+
Email string `json:"email,omitempty"`
1516
Groups []string `json:"groups" binding:"required"`
1617
}
1718

components/operator/internal/handlers/sessions.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,15 +982,19 @@ func handleAgenticSessionEvent(obj *unstructured.Unstructured) error {
982982
// Extract userContext for observability and auditing
983983
userID := ""
984984
userName := ""
985+
userEmail := ""
985986
if userContext, found, _ := unstructured.NestedMap(spec, "userContext"); found {
986987
if v, ok := userContext["userId"].(string); ok {
987988
userID = strings.TrimSpace(v)
988989
}
989990
if v, ok := userContext["displayName"].(string); ok {
990991
userName = strings.TrimSpace(v)
991992
}
993+
if v, ok := userContext["email"].(string); ok {
994+
userEmail = strings.TrimSpace(v)
995+
}
992996
}
993-
log.Printf("Session %s initiated by user: %s (userId: %s)", name, userName, userID)
997+
log.Printf("Session %s initiated by user: %s (userId: %s, email: %s)", name, userName, userID, userEmail)
994998

995999
// Create the Job
9961000
job := &batchv1.Job{
@@ -1131,6 +1135,10 @@ func handleAgenticSessionEvent(obj *unstructured.Unstructured) error {
11311135
if userName != "" {
11321136
base = append(base, corev1.EnvVar{Name: "USER_NAME", Value: userName})
11331137
}
1138+
// Pass email for Google Workspace MCP tools
1139+
if userEmail != "" {
1140+
base = append(base, corev1.EnvVar{Name: "USER_GOOGLE_EMAIL", Value: userEmail})
1141+
}
11341142

11351143
// Add per-repo environment variables (simplified format)
11361144
for i, repo := range repos {

components/runners/claude-code-runner/.mcp.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"GOOGLE_MCP_CREDENTIALS_DIR": "${GOOGLE_MCP_CREDENTIALS_DIR}",
2323
"MCP_SINGLE_USER_MODE": "1",
2424
"GOOGLE_OAUTH_CLIENT_ID": "${GOOGLE_OAUTH_CLIENT_ID}",
25-
"GOOGLE_OAUTH_CLIENT_SECRET": "${GOOGLE_OAUTH_CLIENT_SECRET}"
25+
"GOOGLE_OAUTH_CLIENT_SECRET": "${GOOGLE_OAUTH_CLIENT_SECRET}",
26+
"USER_GOOGLE_EMAIL": "${USER_GOOGLE_EMAIL}"
2627
}
2728
}
2829
}

0 commit comments

Comments
 (0)