Files
1745d6fdd2 feat: be able to pass api key over authorization header (#27)
## Before

it needs `SIGNOZ_API_KEY` as env variable when running the mcp server

## After

it could pass `SIGNOZ_API_KEY` over the `Authorization` header so that
it could manage access to this mcp server at application level.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2025-10-12 23:13:05 -07:00

19 lines
457 B
Go

package util
import "context"
type contextKey string
const apiKeyContextKey contextKey = "api_key"
// SetAPIKey stores the API key in the context
func SetAPIKey(ctx context.Context, apiKey string) context.Context {
return context.WithValue(ctx, apiKeyContextKey, apiKey)
}
// GetAPIKey retrieves the API key from the context
func GetAPIKey(ctx context.Context) (string, bool) {
apiKey, ok := ctx.Value(apiKeyContextKey).(string)
return apiKey, ok
}