diff --git a/.gitignore b/.gitignore index 533b3fca9f..3ee8dfee88 100644 --- a/.gitignore +++ b/.gitignore @@ -135,8 +135,6 @@ vite.config.js docs/* !docs/admin-api-keys.md !docs/mcp.md -!docs/mcp-oauth-connections.png -!docs/mcp-oauth-consent.png !docs/PAYMENT.md !docs/PAYMENT_CN.md !docs/ADMIN_PAYMENT_INTEGRATION_API.md diff --git a/docs/mcp-oauth-connections.png b/docs/mcp-oauth-connections.png deleted file mode 100644 index 48925d1efd..0000000000 Binary files a/docs/mcp-oauth-connections.png and /dev/null differ diff --git a/docs/mcp-oauth-consent.png b/docs/mcp-oauth-consent.png deleted file mode 100644 index 4a988336db..0000000000 Binary files a/docs/mcp-oauth-consent.png and /dev/null differ diff --git a/frontend/src/components/icons/Icon.vue b/frontend/src/components/icons/Icon.vue index 7859adee70..e02e1330d6 100644 --- a/frontend/src/components/icons/Icon.vue +++ b/frontend/src/components/icons/Icon.vue @@ -132,7 +132,11 @@ const icons = { calculator: 'M9 7h6m0 10v-3m-3 3h.01M9 17h.01M9 14h.01M12 14h.01M15 11h.01M12 11h.01M9 11h.01M7 21h10a2 2 0 002-2V5a2 2 0 00-2-2H7a2 2 0 00-2 2v14a2 2 0 002 2z', fire: 'M17.657 18.657A8 8 0 016.343 7.343S7 9 9 10c0-2 .5-5 2.986-7C14 5 16.09 5.777 17.656 7.343A7.975 7.975 0 0120 13a7.975 7.975 0 01-2.343 5.657z', badge: 'M9 12.75L11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 01-1.043 3.296 3.745 3.745 0 01-3.296 1.043A3.745 3.745 0 0112 21c-1.268 0-2.39-.63-3.068-1.593a3.746 3.746 0 01-3.296-1.043 3.745 3.745 0 01-1.043-3.296A3.745 3.745 0 013 12c0-1.268.63-2.39 1.593-3.068a3.745 3.745 0 011.043-3.296 3.746 3.746 0 013.296-1.043A3.746 3.746 0 0112 3c1.268 0 2.39.63 3.068 1.593a3.746 3.746 0 013.296 1.043 3.746 3.746 0 011.043 3.296A3.745 3.745 0 0121 12z', - brain: 'M9.75 3.104v5.714a2.25 2.25 0 01-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 014.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0112 15a9.065 9.065 0 00-6.23.693L5 14.5m0 0l-2.69 2.689c-1.232 1.232-.65 3.318 1.067 3.611A48.309 48.309 0 0012 21c2.773 0 5.491-.235 8.135-.687 1.718-.293 2.3-2.379 1.067-3.61L19.8 15.3M12 8.25a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm0 0v3m-3-1.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm0 0h6m-3 4.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z' + brain: 'M9.75 3.104v5.714a2.25 2.25 0 01-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 014.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0112 15a9.065 9.065 0 00-6.23.693L5 14.5m0 0l-2.69 2.689c-1.232 1.232-.65 3.318 1.067 3.611A48.309 48.309 0 0012 21c2.773 0 5.491-.235 8.135-.687 1.718-.293 2.3-2.379 1.067-3.61L19.8 15.3M12 8.25a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm0 0v3m-3-1.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm0 0h6m-3 4.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z', + + // Brands + // Model Context Protocol logo (modelcontextprotocol.io), scaled to the 24px stroke grid. + mcp: 'M3.98 11.4L11.59 3.79C12.64 2.74 14.34 2.74 15.39 3.79C16.44 4.84 16.44 6.54 15.39 7.59L9.64 13.34M9.72 13.26L15.39 7.59C16.44 6.54 18.14 6.54 19.2 7.59L19.24 7.63C20.29 8.68 20.29 10.39 19.24 11.44L12.35 18.32C12 18.67 12 19.24 12.35 19.59L13.77 21M13.49 5.69L7.86 11.32C6.81 12.37 6.81 14.07 7.86 15.12C8.91 16.17 10.61 16.17 11.67 15.12L17.29 9.49' } as const const iconPath = computed(() => icons[props.name]) diff --git a/frontend/src/components/layout/AppSidebar.vue b/frontend/src/components/layout/AppSidebar.vue index 3ef95d4caf..72e0f06b1a 100644 --- a/frontend/src/components/layout/AppSidebar.vue +++ b/frontend/src/components/layout/AppSidebar.vue @@ -481,6 +481,10 @@ const PluginIcon = { render: () => h(Icon, { name: 'cube' }) } +const MCPIcon = { + render: () => h(Icon, { name: 'mcp' }) +} + const BellIcon = { render: () => h( @@ -708,6 +712,7 @@ const purchaseNavLabel = computed(() => { const flagAffiliate = makeSidebarFlag(FeatureFlags.affiliate) const flagRiskControl = makeSidebarFlag(FeatureFlags.riskControl) const flagPluginManagement = makeSidebarFlag(FeatureFlags.pluginManagement) +const flagMCP = makeSidebarFlag(FeatureFlags.mcp) const flagOpsMonitoring = () => adminSettingsStore.opsMonitoringEnabled const flagAdminPayment = () => adminSettingsStore.paymentEnabled const flagBatchImageAccess = () => canUseBatchImage.value @@ -734,7 +739,7 @@ function buildSelfNavItems(withDashboard: boolean): NavItem[] { { path: '/redeem', label: t('nav.redeem'), icon: GiftIcon, hideInSimpleMode: true }, { path: '/affiliate', label: t('nav.affiliate'), icon: UsersIcon, hideInSimpleMode: true, featureFlag: flagAffiliate }, { path: '/profile', label: t('nav.profile'), icon: UserIcon }, - { path: '/settings/mcp', label: t('mcp.title'), icon: PluginIcon }, + { path: '/settings/mcp', label: t('mcp.title'), icon: MCPIcon, featureFlag: flagMCP }, ...customMenuItemsForUser.value.map((item): NavItem => ({ path: `/custom/${item.id}`, label: item.label, @@ -846,7 +851,7 @@ const adminNavItems = computed((): NavItem[] => { if (authStore.isSimpleMode) { const filtered = visible.filter(item => !item.hideInSimpleMode) filtered.push({ path: '/keys', label: t('nav.apiKeys'), icon: KeyIcon }) - filtered.push({ path: '/settings/mcp', label: t('mcp.title'), icon: PluginIcon }) + if (flagMCP()) filtered.push({ path: '/settings/mcp', label: t('mcp.title'), icon: MCPIcon }) filtered.push({ path: '/admin/settings', label: t('nav.settings'), icon: CogIcon }) for (const cm of customMenuItemsForAdmin.value) { filtered.push({ path: `/custom/${cm.id}`, label: cm.label, icon: null, iconSvg: cm.icon_svg }) diff --git a/frontend/src/components/layout/__tests__/AppSidebar.spec.ts b/frontend/src/components/layout/__tests__/AppSidebar.spec.ts index 0ecb56a9f5..636fc9d724 100644 --- a/frontend/src/components/layout/__tests__/AppSidebar.spec.ts +++ b/frontend/src/components/layout/__tests__/AppSidebar.spec.ts @@ -80,3 +80,13 @@ describe('AppSidebar subscription feature flag', () => { expect(componentSource).toMatch(/path: '\/purchase'[^\n]*label: purchaseNavLabel\.value/) }) }) + +describe('AppSidebar MCP entry', () => { + it('uses the MCP logo and shows the entry only when the deployment enables MCP', () => { + expect(componentSource).toContain("render: () => h(Icon, { name: 'mcp' })") + expect(componentSource).toContain('const flagMCP = makeSidebarFlag(FeatureFlags.mcp)') + expect(componentSource).toMatch(/path: '\/settings\/mcp'[^\n]*icon: MCPIcon, featureFlag: flagMCP/) + expect(componentSource).toMatch(/if \(flagMCP\(\)\) filtered\.push\(\{ path: '\/settings\/mcp'[^\n]*icon: MCPIcon/) + expect(componentSource).not.toMatch(/path: '\/settings\/mcp'[^\n]*PluginIcon/) + }) +}) diff --git a/frontend/src/i18n/locales/en/mcp.ts b/frontend/src/i18n/locales/en/mcp.ts index f30119fdc7..9abc39fc80 100644 --- a/frontend/src/i18n/locales/en/mcp.ts +++ b/frontend/src/i18n/locales/en/mcp.ts @@ -23,6 +23,7 @@ export default { readWrite: 'Allow changes', readOnlyHint: 'Expose query tools only, for analyzing usage and checking status.', readWriteHint: 'Allow creating, updating and deleting resources within this scope, including API keys and billing entitlements. Only approve this for an application you trust.', + adminWriteHint: 'Platform write access always requires two-factor authentication (TOTP) to be enabled and verified when you approve.', empty: 'No authorized applications yet. Start a connection from your AI client using the server URL above.', loading: 'Loading authorized applications…', loadFailed: 'Failed to load authorized applications. Please try again.', diff --git a/frontend/src/i18n/locales/zh/mcp.ts b/frontend/src/i18n/locales/zh/mcp.ts index cd53754341..e8c9e09a4e 100644 --- a/frontend/src/i18n/locales/zh/mcp.ts +++ b/frontend/src/i18n/locales/zh/mcp.ts @@ -23,6 +23,7 @@ export default { readWrite: '允许修改', readOnlyHint: '只开放查询工具,适合分析用量、查看状态。', readWriteHint: '允许创建、修改和删除范围内的资源,包括 API 密钥和计费权益。请只授权给你信任的应用。', + adminWriteHint: '平台管理的修改权限始终需要你已开启两步验证(TOTP),并在授权时完成验证。', empty: '尚未授权任何应用。请在 AI 客户端中使用上方服务地址发起连接。', loading: '正在加载已授权应用…', loadFailed: '加载已授权应用失败,请重试。', diff --git a/frontend/src/stores/app.ts b/frontend/src/stores/app.ts index a240441970..40a8d62fd9 100644 --- a/frontend/src/stores/app.ts +++ b/frontend/src/stores/app.ts @@ -380,6 +380,7 @@ export const useAppStore = defineStore('app', () => { service_quota_enabled: false, affiliate_enabled: false, allow_user_view_error_requests: false, + mcp_enabled: false, }) } diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index 25ac0fb936..a33cb95401 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -287,6 +287,8 @@ export interface PublicSettings { service_quota_enabled: boolean affiliate_enabled: boolean allow_user_view_error_requests?: boolean + /** True when the deployment configures MCP_PUBLIC_URL; MCP is disabled otherwise. */ + mcp_enabled?: boolean } export interface AuthResponse { diff --git a/frontend/src/utils/__tests__/featureFlags.spec.ts b/frontend/src/utils/__tests__/featureFlags.spec.ts index c5695dfaae..c31d980ca5 100644 --- a/frontend/src/utils/__tests__/featureFlags.spec.ts +++ b/frontend/src/utils/__tests__/featureFlags.spec.ts @@ -63,3 +63,19 @@ describe('resolveFeatureFlag', () => { expect(isFeatureFlagEnabled(FeatureFlags.subscription)).toBe(false) }) }) + +describe('FeatureFlags.mcp', () => { + beforeEach(() => { + setActivePinia(createPinia()) + delete (window as any).__APP_CONFIG__ + }) + + it('stays hidden unless the deployment explicitly enables MCP', () => { + expect(FeatureFlags.mcp.key).toBe('mcp_enabled') + expect(FeatureFlags.mcp.mode).toBe('opt-in') + expect(isFeatureFlagEnabled(FeatureFlags.mcp)).toBe(false) + expect(resolveFeatureFlag({} as PublicSettings, FeatureFlags.mcp)).toBe(false) + expect(resolveFeatureFlag({ mcp_enabled: false } as PublicSettings, FeatureFlags.mcp)).toBe(false) + expect(resolveFeatureFlag({ mcp_enabled: true } as PublicSettings, FeatureFlags.mcp)).toBe(true) + }) +}) diff --git a/frontend/src/utils/featureFlags.ts b/frontend/src/utils/featureFlags.ts index cce2767726..8493ed9278 100644 --- a/frontend/src/utils/featureFlags.ts +++ b/frontend/src/utils/featureFlags.ts @@ -134,6 +134,12 @@ export const FeatureFlags = { mode: 'opt-in', label: 'Affiliate', }), + // Read-only: enabled by the deployment's MCP_PUBLIC_URL, not an admin toggle. + mcp: defineFlag({ + key: 'mcp_enabled', + mode: 'opt-in', + label: 'MCP', + }), } as const export type RegisteredFeatureFlag = keyof typeof FeatureFlags diff --git a/frontend/src/views/admin/AuditLogView.vue b/frontend/src/views/admin/AuditLogView.vue index b2bb2d099a..522b4e77f3 100644 --- a/frontend/src/views/admin/AuditLogView.vue +++ b/frontend/src/views/admin/AuditLogView.vue @@ -485,7 +485,8 @@ const methodOptions = computed(() => [ const authMethodOptions = computed(() => [ { value: '', label: t('admin.audit.filters.all') }, { value: 'jwt', label: 'JWT' }, - { value: 'admin_api_key', label: 'Admin API Key' } + { value: 'admin_api_key', label: 'Admin API Key' }, + { value: 'mcp_oauth', label: 'MCP OAuth' } ]) const resultOptions = computed(() => [ diff --git a/frontend/src/views/auth/MCPOAuthAuthorizeView.vue b/frontend/src/views/auth/MCPOAuthAuthorizeView.vue index 8d60d778bf..adf9e67bfc 100644 --- a/frontend/src/views/auth/MCPOAuthAuthorizeView.vue +++ b/frontend/src/views/auth/MCPOAuthAuthorizeView.vue @@ -2,7 +2,7 @@
-
+

{{ t('mcp.consentTitle') }}

{{ t('mcp.consentDescription') }}

@@ -54,6 +54,7 @@

{{ readOnly ? t('mcp.readOnlyHint') : t('mcp.readWriteHint') }}

+

{{ t('mcp.adminWriteHint') }}

diff --git a/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts b/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts index 452c0ef463..9ef63e66b3 100644 --- a/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts +++ b/frontend/src/views/auth/__tests__/MCPOAuthAuthorizeView.spec.ts @@ -154,6 +154,19 @@ describe('MCP OAuth consent', () => { expect(assign).toHaveBeenCalledWith(redirectURL) }) + it('explains that administrator write access always needs two-factor verification', async () => { + auth.isAdmin = true + const wrapper = render() + await flushPromises() + expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false) + await wrapper.get('#mcp-consent-permissions').setValue('false') + expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false) + await wrapper.get('#mcp-consent-scope').setValue('admin') + expect(wrapper.get('[data-testid="admin-write-hint"]').text()).toBe('mcp.adminWriteHint') + await wrapper.get('#mcp-consent-permissions').setValue('true') + expect(wrapper.find('[data-testid="admin-write-hint"]').exists()).toBe(false) + }) + it('cancels admin step-up without granting access', async () => { auth.isAdmin = true authorize.mockRejectedValue({ reason: 'STEP_UP_REQUIRED' }) diff --git a/frontend/src/views/user/MCPView.vue b/frontend/src/views/user/MCPView.vue index 2411fc0bab..2007332fbc 100644 --- a/frontend/src/views/user/MCPView.vue +++ b/frontend/src/views/user/MCPView.vue @@ -4,7 +4,7 @@
- +

{{ t('mcp.connectionTitle') }}