Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion internal/auth/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (a AuthService) validateOpaqueToken(ctx context.Context, tokenStr string) e

if resp.StatusCode != http.StatusOK {
logger.WarnContext(ctx, "introspection failed with status: %d", resp.StatusCode)
return &MCPAuthError{Code: http.StatusUnauthorized, Message: fmt.Sprintf("introspection failed with status: %d", resp.StatusCode), ScopesRequired: a.ScopesRequired}
return &MCPAuthError{Code: http.StatusInternalServerError, Message: fmt.Sprintf("introspection failed with status: %d", resp.StatusCode), ScopesRequired: a.ScopesRequired}
}

body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
Expand Down
15 changes: 15 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ func mcpAuthMiddleware(s *Server) func(http.Handler) http.Handler {
}
}

// Add logger to context
ctx := util.WithLogger(r.Context(), s.logger)
r = r.WithContext(ctx)

// MCP Auth not enabled
if mcpSvc == nil {
next.ServeHTTP(w, r)
Expand All @@ -525,8 +529,19 @@ func mcpAuthMiddleware(s *Server) func(http.Handler) http.Handler {
w.Header().Set("WWW-Authenticate", fmt.Sprintf(`Bearer error="insufficient_scope", scope="%s", resource_metadata="%s", error_description="%s"`, strings.Join(mcpErr.ScopesRequired, " "), s.toolboxUrl+"/.well-known/oauth-protected-resource", mcpErr.Message))
http.Error(w, mcpErr.Message, http.StatusForbidden)
return
default:
if mcpErr.Code >= 500 {
s.logger.ErrorContext(r.Context(), "internal authentication error", "error", mcpErr.Message)
http.Error(w, "internal server error during authentication", mcpErr.Code)
} else {
http.Error(w, mcpErr.Message, mcpErr.Code)
}
return
Comment thread
Deeven-Seru marked this conversation as resolved.
}
}
s.logger.ErrorContext(r.Context(), "unexpected error during authentication", "error", err)
http.Error(w, "internal server error during authentication", http.StatusInternalServerError)
return
Comment thread
Deeven-Seru marked this conversation as resolved.
}

next.ServeHTTP(w, r)
Expand Down