diff --git a/frontend/src/views/auth/MCPOAuthAuthorizeView.vue b/frontend/src/views/auth/MCPOAuthAuthorizeView.vue
index 065a739272..90aab688a9 100644
--- a/frontend/src/views/auth/MCPOAuthAuthorizeView.vue
+++ b/frontend/src/views/auth/MCPOAuthAuthorizeView.vue
@@ -41,18 +41,12 @@
{{ t('mcp.signedInAs', { email: authStore.user.email }) }}
-
+
{{ scope === 'admin' ? t('mcp.adminScopeHint') : t('mcp.userScopeHint') }}
-
+
{{ readOnly ? t('mcp.readOnlyHint') : t('mcp.readWriteHint') }}
{{ t('mcp.adminWriteHint') }}
@@ -73,6 +67,7 @@ import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { mcpAPI, type MCPAccessScope, type MCPAuthorization, type MCPConsent } from '@/api/mcp'
import TotpStepUpDialog from '@/components/auth/TotpStepUpDialog.vue'
+import Select from '@/components/common/Select.vue'
import { Icon } from '@/components/icons'
import { isStepUpBlocked, isStepUpCancelled, stepUpBlockReason, useStepUp } from '@/composables/useStepUp'
import { useAuthStore } from '@/stores/auth'
@@ -92,6 +87,24 @@ let authorization: MCPAuthorization | null = null
let generation = 0
const redirectOrigin = computed(() => consent.value ? new URL(consent.value.redirect_uri).origin : '')
+const scopeOptions = computed(() => [
+ { value: 'user', label: t('mcp.userScope') },
+ ...(authStore.isAdmin ? [{ value: 'admin', label: t('mcp.adminScope') }] : [])
+])
+
+const permissionOptions = computed(() => [
+ { value: true, label: t('mcp.readOnly') },
+ { value: false, label: t('mcp.readWrite') }
+])
+
+function setScope(value: string | number | boolean | null): void {
+ scope.value = value === 'admin' ? 'admin' : 'user'
+}
+
+function setReadOnly(value: string | number | boolean | null): void {
+ readOnly.value = value !== false
+}
+
function errorMessage(error: unknown, fallback: string): string {
const message = (error as { message?: unknown } | null)?.message
return typeof message === 'string' && message ? message : fallback
diff --git a/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts b/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts
index 9ef63e66b3..3e94804691 100644
--- a/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts
+++ b/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts
@@ -1,5 +1,5 @@
-import { flushPromises, mount } from '@vue/test-utils'
-import { reactive } from 'vue'
+import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
+import { nextTick, reactive } from 'vue'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import MCPOAuthAuthorizeView from '../MCPOAuthAuthorizeView.vue'
import type { MCPAuthorization, MCPConsent } from '@/api/mcp'
@@ -36,6 +36,29 @@ function render() {
mounted.push(wrapper)
return wrapper
}
+// The scope/permission pickers are common Select instances; their panels teleport to body.
+// Closed panels linger in the DOM until their leave transition ends (two rAF frames in jsdom),
+// so close any open panel first, wait it out, and expect exactly one portal afterwards.
+async function openDropdown(wrapper: VueWrapper, id: string) {
+ for (const trigger of wrapper.findAll('button[aria-haspopup="true"]')) {
+ if (trigger.attributes('aria-expanded') === 'true') await trigger.trigger('click')
+ }
+ await nextTick()
+ await new Promise(resolve => setTimeout(resolve, 50))
+ await wrapper.get(`#${id}`).trigger('click')
+ await nextTick()
+ const portals = document.body.querySelectorAll('.select-dropdown-portal')
+ expect(portals.length, `expected exactly one open dropdown portal for #${id}, got ${portals.length}`).toBe(1)
+ return portals[0]
+}
+
+async function pickOption(wrapper: VueWrapper, id: string, label: string) {
+ const dropdown = await openDropdown(wrapper, id)
+ const option = [...dropdown.querySelectorAll('.select-option')].find((el) => el.textContent?.includes(label))
+ expect(option, `option containing "${label}" not found`).toBeDefined()
+ ;(option as HTMLElement).click()
+ await nextTick()
+}
beforeEach(() => {
vi.clearAllMocks()
auth.isAdmin = false
@@ -46,6 +69,7 @@ beforeEach(() => {
})
afterEach(() => {
mounted.splice(0).forEach(wrapper => wrapper.unmount())
+ document.body.innerHTML = ''
Object.defineProperty(window, 'location', { configurable: true, value: originalLocation })
})
@@ -60,13 +84,25 @@ describe('MCP OAuth consent', () => {
expect(wrapper.text()).toContain('mcp.untrustedApplicationHint')
expect(authorize).not.toHaveBeenCalled()
expect(assign).not.toHaveBeenCalled()
- expect(wrapper.find('#mcp-consent-scope option[value="admin"]').exists()).toBe(false)
+ const scopeLabels = [...(await openDropdown(wrapper, 'mcp-consent-scope')).querySelectorAll('.select-option-label')].map((el) => el.textContent?.trim())
+ expect(scopeLabels).toEqual(['mcp.userScope'])
+ await wrapper.get('#mcp-consent-scope').trigger('click')
+ await nextTick()
await wrapper.get('form').trigger('submit')
await flushPromises()
expect(authorize).toHaveBeenCalledWith({ authorization: request, approved: true, scope: 'user', read_only: true })
expect(assign).toHaveBeenCalledWith(redirectURL)
})
+ it('renders the scope and permission pickers as themed custom dropdown panels', async () => {
+ const wrapper = render()
+ await flushPromises()
+ const permissionsLabels = [...(await openDropdown(wrapper, 'mcp-consent-permissions')).querySelectorAll('.select-option-label')].map((el) => el.textContent?.trim())
+ expect(permissionsLabels).toEqual(['mcp.readOnly', 'mcp.readWrite'])
+ const scopeLabels = [...(await openDropdown(wrapper, 'mcp-consent-scope')).querySelectorAll('.select-option-label')].map((el) => el.textContent?.trim())
+ expect(scopeLabels).toEqual(['mcp.userScope'])
+ })
+
it('allows an omitted OAuth scope without adding or changing request parameters', async () => {
delete routeState.current.query.scope
const wrapper = render()
@@ -140,9 +176,9 @@ describe('MCP OAuth consent', () => {
authorize.mockRejectedValueOnce({ reason: 'STEP_UP_REQUIRED' }).mockResolvedValueOnce({ redirect_url: redirectURL })
const wrapper = render()
await flushPromises()
- expect((wrapper.get('#mcp-consent-scope').element as HTMLSelectElement).value).toBe('user')
- await wrapper.get('#mcp-consent-scope').setValue('admin')
- await wrapper.get('#mcp-consent-permissions').setValue('false')
+ expect(wrapper.get('#mcp-consent-scope').text()).toContain('mcp.userScope')
+ await pickOption(wrapper, 'mcp-consent-scope', 'mcp.adminScope')
+ await pickOption(wrapper, 'mcp-consent-permissions', 'mcp.readWrite')
await wrapper.get('form').trigger('submit')
await flushPromises()
expect(authorize).toHaveBeenCalledTimes(1)
@@ -159,11 +195,11 @@ describe('MCP OAuth consent', () => {
const wrapper = render()
await flushPromises()
expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false)
- await wrapper.get('#mcp-consent-permissions').setValue('false')
+ await pickOption(wrapper, 'mcp-consent-permissions', 'mcp.readWrite')
expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false)
- await wrapper.get('#mcp-consent-scope').setValue('admin')
+ await pickOption(wrapper, 'mcp-consent-scope', 'mcp.adminScope')
expect(wrapper.get('[data-testid="admin-write-hint"]').text()).toBe('mcp.adminWriteHint')
- await wrapper.get('#mcp-consent-permissions').setValue('true')
+ await pickOption(wrapper, 'mcp-consent-permissions', 'mcp.readOnly')
expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false)
})
@@ -172,7 +208,7 @@ describe('MCP OAuth consent', () => {
authorize.mockRejectedValue({ reason: 'STEP_UP_REQUIRED' })
const wrapper = render()
await flushPromises()
- await wrapper.get('#mcp-consent-scope').setValue('admin')
+ await pickOption(wrapper, 'mcp-consent-scope', 'mcp.adminScope')
await wrapper.get('form').trigger('submit')
await flushPromises()
await wrapper.get('[data-testid="step-up-cancel"]').trigger('click')