Skip to content

Commit 30d41ea

Browse files
committed
use 403 in the response
Signed-off-by: Huabing Zhao <[email protected]>
1 parent e2d6c2c commit 30d41ea

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

internal/mcpproxy/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func (m *MCPProxy) handleToolCallRequest(ctx context.Context, s *session, w http
543543
// Enforce authentication if required by the route.
544544
if route.authorization != nil {
545545
if !m.authorizeRequest(route.authorization, headers, backendName, toolName, p.Arguments) {
546-
onErrorResponse(w, http.StatusUnauthorized, "authorization failed")
546+
onErrorResponse(w, http.StatusForbidden, "authorization failed")
547547
return fmt.Errorf("authorization failed")
548548
}
549549
}

tests/e2e/mcp_route_authorization_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestMCPRouteAuthorization(t *testing.T) {
138138
})
139139
require.Error(t, err)
140140
errMsg := strings.ToLower(err.Error())
141-
require.True(t, strings.Contains(errMsg, "401") || strings.Contains(errMsg, "authorization"), "unexpected error: %v", err)
141+
require.True(t, strings.Contains(errMsg, "403") || strings.Contains(errMsg, "authorization"), "unexpected error: %v", err)
142142
})
143143

144144
t.Run("missing scopes fall back to deny", func(t *testing.T) {
@@ -165,7 +165,7 @@ func TestMCPRouteAuthorization(t *testing.T) {
165165
})
166166
require.Error(t, err)
167167
errMsg := strings.ToLower(err.Error())
168-
require.True(t, strings.Contains(errMsg, "401") || strings.Contains(errMsg, "authorization"), "unexpected error: %v", err)
168+
require.True(t, strings.Contains(errMsg, "403") || strings.Contains(errMsg, "authorization"), "unexpected error: %v", err)
169169
})
170170
}
171171

0 commit comments

Comments
 (0)