Skip to content

Commit d14869c

Browse files
committed
feat(server): export SignalUnauthorized for use by external packages
Allows consumers such as remote-mcp-server to call SignalUnauthorized from their own middleware without reimplementing the context key logic.
1 parent 11231d4 commit d14869c

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/server/mcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func unauthorizedMiddleware(cb func()) mcp.Middleware {
5252
result, err := next(ctx, method, req)
5353
if err != nil && errors.Is(err, buildkite.ErrUnauthorized) {
5454
log.Ctx(ctx).Warn().Msg("Buildkite API returned 401 unauthorized; token may be invalid or expired")
55-
signalUnauthorized(ctx)
55+
SignalUnauthorized(ctx)
5656
if cb != nil {
5757
cb()
5858
}

pkg/server/unauthorized.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88

99
type unauthorizedContextKey struct{}
1010

11-
// signalUnauthorized sets the unauthorized flag in the context, if present.
11+
// SignalUnauthorized sets the unauthorized flag in the context, if present.
1212
// It is a no-op when not running in HTTP mode (i.e., when the context key is absent).
13-
func signalUnauthorized(ctx context.Context) {
13+
func SignalUnauthorized(ctx context.Context) {
1414
if flag, ok := ctx.Value(unauthorizedContextKey{}).(*atomic.Bool); ok {
1515
flag.Store(true)
1616
}

pkg/server/unauthorized_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestNewHTTPUnauthorizedHandler_UnauthorizedSignal(t *testing.T) {
3030
// An inner handler that signals unauthorized via the context flag.
3131
inner := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3232
// Simulate the MCP middleware detecting ErrUnauthorized.
33-
signalUnauthorized(r.Context())
33+
SignalUnauthorized(r.Context())
3434
// The interceptingWriter will discard these writes.
3535
w.Header().Set("Content-Type", "application/json")
3636
w.WriteHeader(http.StatusOK)
@@ -52,7 +52,7 @@ func TestNewHTTPUnauthorizedHandler_UnauthorizedSignal(t *testing.T) {
5252
func TestSignalUnauthorized_NoopWithoutContext(t *testing.T) {
5353
// Should not panic when the context key is absent.
5454
require.NotPanics(t, func() {
55-
signalUnauthorized(context.Background())
55+
SignalUnauthorized(context.Background())
5656
})
5757
}
5858

@@ -61,7 +61,7 @@ func TestSignalUnauthorized_SetsFlag(t *testing.T) {
6161
ctx := context.WithValue(context.Background(), unauthorizedContextKey{}, flag)
6262

6363
require.False(t, flag.Load())
64-
signalUnauthorized(ctx)
64+
SignalUnauthorized(ctx)
6565
require.True(t, flag.Load())
6666
}
6767

0 commit comments

Comments
 (0)