Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/guard/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import (
"context"

"github.com/githubnext/gh-aw-mcpg/internal/auth"
"github.com/githubnext/gh-aw-mcpg/internal/logger"
)

var log = logger.New("guard:context")

// ContextKey is used for storing values in context
type ContextKey string

Expand All @@ -43,13 +46,16 @@ const (
// Returns "default" if not found
func GetAgentIDFromContext(ctx context.Context) string {
if agentID, ok := ctx.Value(AgentIDContextKey).(string); ok && agentID != "" {
log.Printf("Retrieved agent ID from context: %s", agentID)
return agentID
}
log.Print("Agent ID not found in context, returning default")
return "default"
}

// SetAgentIDInContext sets the agent ID in the context
func SetAgentIDInContext(ctx context.Context, agentID string) context.Context {
log.Printf("Setting agent ID in context: %s", agentID)
return context.WithValue(ctx, AgentIDContextKey, agentID)
}

Expand All @@ -60,18 +66,24 @@ func SetAgentIDInContext(ctx context.Context, agentID string) context.Context {
//
// For MCP spec 7.1 compliant parsing with full error handling, use auth.ParseAuthHeader().
func ExtractAgentIDFromAuthHeader(authHeader string) string {
return auth.ExtractAgentID(authHeader)
log.Print("Extracting agent ID from auth header (deprecated path)")
agentID := auth.ExtractAgentID(authHeader)
log.Printf("Extracted agent ID: %s", agentID)
return agentID
}

// GetRequestStateFromContext retrieves guard request state from context
func GetRequestStateFromContext(ctx context.Context) RequestState {
if state, ok := ctx.Value(RequestStateContextKey).(RequestState); ok {
log.Print("Retrieved request state from context")
return state
}
log.Print("Request state not found in context")
return nil
}

// SetRequestStateInContext stores guard request state in context
func SetRequestStateInContext(ctx context.Context, state RequestState) context.Context {
log.Print("Setting request state in context")
return context.WithValue(ctx, RequestStateContextKey, state)
}