There might be a better way to do this I'm not thinking of, but one option would be to rely on the script context threadlocal:
This will obviously only work in scenarios where we actually know the project and therefore default provider to provide it before your script runs.