Skip to content

Commit 2127f5c

Browse files
committed
Keep manual OAuth sign-in available during reconnect errors
1 parent 4cc4bcb commit 2127f5c

5 files changed

Lines changed: 110 additions & 3 deletions

File tree

‎docs/features/oauth-authentication.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ actionable **Sign-in** state:
166166
is quarantined, but its tools stay blocked until you **Approve** the server.
167167
The panel makes both gates explicit.
168168

169+
### Switching accounts and retrying sign-in
170+
171+
To switch accounts or recover an OAuth error, use **Sign in again** in the
172+
server card’s **More actions** menu or the detail page’s **Actions** menu.
173+
For an OAuth-capable upstream this remains available during reconnect attempts
174+
and generic timeout errors, even when the health panel does not suggest login.
175+
After logout it is labelled **Sign in**. Select the intended account/workspace
176+
at the provider; if the provider reuses its own browser session, switch that
177+
account before starting sign-in again.
178+
169179
## CLI Commands
170180

171181
### Start Authentication

‎frontend/src/components/ServerCard.vue‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
<li v-if="canLogout">
111111
<button type="button" @click="triggerLogout" :disabled="loading" data-test="server-card-menu-logout">Logout</button>
112112
</li>
113+
<li v-if="canSignIn">
114+
<button type="button" @click="triggerOAuth" :disabled="loading" data-test="server-card-menu-login">{{ server.authenticated || server.connected ? 'Sign in again' : 'Sign in' }}</button>
115+
</li>
113116
<li>
114117
<button
115118
type="button"
@@ -229,6 +232,7 @@ import { useSystemStore } from '@/stores/system'
229232
import { useSecurityScannerStatus } from '@/composables/useSecurityScannerStatus'
230233
import { serverDetailPath, serverDisplayName, reviewPath } from '@/utils/serverRoute'
231234
import { oauthSignInState, healthStatusText, healthActionLabel } from '@/utils/health'
235+
import { canStartOAuthLogin } from '@/utils/oauthActions'
232236
import { deriveTrustModeState, TRUST_MODES } from '@/utils/trustMode'
233237
234238
interface Props {
@@ -259,6 +263,7 @@ const isHttpProtocol = computed(() => {
259263
// the status line reads a calm amber "Sign-in required" instead of red
260264
// "Disconnected"/"Unhealthy", matching the ServerDetail Sign-in CTA.
261265
const signInState = computed(() => oauthSignInState(props.server))
266+
const canSignIn = computed(() => canStartOAuthLogin(props.server))
262267
263268
// Trust-mode badge (spec 088 FR-007 / FR-001). Display only — the mode is
264269
// changed from the server detail Configuration tab.

‎frontend/src/utils/oauthActions.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Server } from '@/types'
2+
3+
// Account switching and recovery must remain available even when a timeout
4+
// is classified as a reconnect error, or a background connection is running.
5+
export function canStartOAuthLogin(server: Server): boolean {
6+
const protocol = String(server.protocol)
7+
const remote = ['http', 'sse', 'streamable-http'].includes(protocol) ||
8+
(protocol === 'auto' && !!server.url && !server.command)
9+
return !!(server.enabled && remote && (
10+
server.oauth || server.authenticated || server.health?.action === 'login' ||
11+
server.health?.actions?.includes('login') || server.diagnostic?.code?.startsWith('MCPX_OAUTH_') ||
12+
/oauth/i.test(server.last_error || '')
13+
))
14+
}

‎frontend/src/views/ServerDetail.vue‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
{{ isHttpProtocol ? 'Reconnect' : 'Restart' }}
7777
</button>
7878
</li>
79-
<li v-if="healthAction === 'login'">
80-
<button @click="triggerOAuth" :disabled="actionLoading">
79+
<li v-if="canSignIn">
80+
<button @click="triggerOAuth" :disabled="actionLoading" data-test="server-detail-menu-login">
8181
<span v-if="actionLoading" class="loading loading-spinner loading-xs"></span>
82-
Login
82+
{{ server.authenticated || server.connected ? 'Sign in again' : 'Sign in' }}
8383
</button>
8484
</li>
8585
<li v-if="server.enabled && server.connected">
@@ -1604,6 +1604,7 @@ import { refName } from '@/utils/secretRef'
16041604
import { isTerminalScanStatus, decideScanReconcile, finalizeToastKind } from '@/utils/scanState'
16051605
import { selectQuarantinedTools } from '@/utils/toolQuarantine'
16061606
import { oauthSignInState, healthStatusLabel, healthActionLabel, healthStatusText } from '@/utils/health'
1607+
import { canStartOAuthLogin } from '@/utils/oauthActions'
16071608
import type { HealthStatusValue } from '@/types/contracts'
16081609
import { describeIsolation } from '@/utils/isolationState'
16091610
import { computeToolDiffSections } from '@/utils/toolDiff'
@@ -1824,6 +1825,7 @@ const logTail = ref(100)
18241825
const isHttpProtocol = computed(() => {
18251826
return server.value?.protocol === 'http' || server.value?.protocol === 'streamable-http'
18261827
})
1828+
const canSignIn = computed(() => !!server.value && canStartOAuthLogin(server.value))
18271829
18281830
// Suggested action from unified health status
18291831
const healthAction = computed(() => {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest'
2+
import { mount, flushPromises } from '@vue/test-utils'
3+
import { createPinia, setActivePinia } from 'pinia'
4+
import { createRouter, createWebHistory } from 'vue-router'
5+
import ServerCard from '@/components/ServerCard.vue'
6+
import ServerDetail from '@/views/ServerDetail.vue'
7+
import { useServersStore } from '@/stores/servers'
8+
import { canStartOAuthLogin } from '@/utils/oauthActions'
9+
import type { Server } from '@/types'
10+
11+
let server: Server
12+
vi.mock('@/services/api', () => {
13+
const ok = (data: unknown = {}) => Promise.resolve({ success: true, data })
14+
return { default: {
15+
getServers: vi.fn(() => ok({ servers: [server] })),
16+
getToolApprovals: vi.fn(() => ok({ tools: [], count: 0 })),
17+
getToolDiff: vi.fn(() => ok({})),
18+
getServerTools: vi.fn(() => ok({ tools: [] })),
19+
getSecurityOverview: vi.fn(() => ok({ scanners_enabled: 0, docker_available: true })),
20+
listScanners: vi.fn(() => ok([])),
21+
getScanReport: vi.fn(() => Promise.resolve({ success: false, error: 'no report' })),
22+
getScanStatus: vi.fn(() => ok({ status: 'completed' })),
23+
getServerLogs: vi.fn(() => ok({ logs: [] })),
24+
} }
25+
})
26+
27+
beforeEach(() => {
28+
setActivePinia(createPinia())
29+
server = {
30+
name: 'notion', protocol: 'http', url: 'https://mcp.notion.com/mcp',
31+
enabled: true, connected: false, connecting: true, authenticated: true,
32+
tool_count: 0, oauth: { client_id: 'test' },
33+
last_error: 'OAuth authorization during MCP init failed: context deadline exceeded',
34+
health: { level: 'unhealthy', admin_state: 'enabled', summary: 'OAuth error', action: 'restart', actions: ['restart', 'view_logs'] },
35+
} as Server
36+
})
37+
38+
describe('manual OAuth sign-in', () => {
39+
it('stays available while reconnecting and after a timeout or logout', () => {
40+
expect(canStartOAuthLogin(server)).toBe(true)
41+
expect(canStartOAuthLogin({ ...server, authenticated: false })).toBe(true)
42+
expect(canStartOAuthLogin({ ...server, connected: true, connecting: false, health: undefined, last_error: undefined })).toBe(true)
43+
})
44+
it('does not offer OAuth on disabled, stdio, or unauthenticated non-OAuth HTTP servers', () => {
45+
expect(canStartOAuthLogin({ ...server, enabled: false })).toBe(false)
46+
expect(canStartOAuthLogin({ ...server, protocol: 'stdio' })).toBe(false)
47+
expect(canStartOAuthLogin({ ...server, oauth: undefined, authenticated: false, last_error: 'network timeout', health: undefined })).toBe(false)
48+
})
49+
it('recognizes auto-discovered OAuth without explicit config', () => {
50+
expect(canStartOAuthLogin({ ...server, oauth: undefined, authenticated: false })).toBe(true)
51+
})
52+
it('starts a fresh OAuth flow from the card even when reconnect is the primary action', async () => {
53+
const spy = vi.spyOn(useServersStore(), 'triggerOAuthLogin').mockResolvedValue(true)
54+
const card = mount(ServerCard, { props: { server }, global: { stubs: { RouterLink: true } } })
55+
const action = card.find('[data-test="server-card-menu-login"]')
56+
expect(action.text()).toBe('Sign in again')
57+
expect(action.attributes('disabled')).toBeUndefined()
58+
await action.trigger('click'); await flushPromises()
59+
expect(spy).toHaveBeenCalledWith('notion')
60+
await card.setProps({ server: { ...server, authenticated: false } })
61+
expect(card.find('[data-test="server-card-menu-login"]').text()).toBe('Sign in')
62+
})
63+
it('offers sign-in again from the detail Actions menu during an OAuth reconnect error', async () => {
64+
const router = createRouter({ history: createWebHistory(), routes: [{ path: '/servers/:serverName', component: { template: '<div/>' } }] })
65+
await router.push('/servers/notion'); await router.isReady()
66+
const pinia = createPinia(); setActivePinia(pinia)
67+
const spy = vi.spyOn(useServersStore(), 'triggerOAuthLogin').mockResolvedValue(true)
68+
const detail = mount(ServerDetail, { props: { serverName: 'notion' }, global: { plugins: [pinia, router] } })
69+
await flushPromises(); await flushPromises()
70+
const action = detail.find('[data-test="server-detail-menu-login"]')
71+
expect(action.text()).toBe('Sign in again')
72+
expect(action.attributes('disabled')).toBeUndefined()
73+
await action.trigger('click'); await flushPromises()
74+
expect(spy).toHaveBeenCalledWith('notion')
75+
})
76+
})

0 commit comments

Comments
 (0)