From f822605b3563c57030aa200492f68572cadcc4da Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 20 Aug 2026 12:56:45 -0700 Subject: [PATCH] refac --- src/lib/components/AddToolServerModal.svelte | 69 ++++++++++++++++--- src/lib/components/common/AccessButton.svelte | 7 +- src/lib/i18n/locales/en-US/translation.json | 4 ++ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/lib/components/AddToolServerModal.svelte b/src/lib/components/AddToolServerModal.svelte index 4a22a5ebb8..572b7fd3ab 100644 --- a/src/lib/components/AddToolServerModal.svelte +++ b/src/lib/components/AddToolServerModal.svelte @@ -17,7 +17,11 @@ import Switch from '$lib/components/common/Switch.svelte'; import Tags from './common/Tags.svelte'; import { getToolServerData } from '$lib/apis'; - import { verifyToolServerConnection, registerOAuthClient } from '$lib/apis/configs'; + import { + verifyToolServerConnection, + registerOAuthClient, + initiateOAuthRedirect + } from '$lib/apis/configs'; import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte'; import AccessButton from '$lib/components/common/AccessButton.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; @@ -73,6 +77,29 @@ 'bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700'; const selectClass = 'bg-transparent pr-5 outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700'; + const isMcpOAuth = () => type === 'mcp' && ['oauth_2.1', 'oauth_2.1_static'].includes(auth_type); + const verifyLabel = () => + isMcpOAuth() ? $i18n.t('Check OAuth Discovery') : $i18n.t('Verify Connection'); + const verifySuccessMessage = () => + isMcpOAuth() ? $i18n.t('OAuth discovery successful') : $i18n.t('Connection successful'); + + const authorizeOAuthHandler = () => { + if (!id) { + toast.error($i18n.t('Please enter a valid ID')); + return; + } + + if (!edit) { + toast.error($i18n.t('Please save the connection before authorizing OAuth')); + return; + } + + initiateOAuthRedirect({ + id: `server:mcp:${id}`, + serverId: id, + authType: 'mcp' + }); + }; const registerOAuthClientHandler = async () => { if (url === '') { @@ -185,14 +212,21 @@ info: { id, name, - description + description, + ...(isMcpOAuth() + ? { + ...(oauthServerUrl ? { oauth_server_url: oauthServerUrl } : {}), + ...(oauthScope ? { oauth_scope: oauthScope } : {}), + oauth_resource_parameter: oauthResourceParameter + } + : {}) } }).catch((err) => { toast.error($i18n.t('Connection failed')); }); if (res) { - toast.success($i18n.t('Connection successful')); + toast.success(verifySuccessMessage()); console.debug('Connection successful', res); } } @@ -609,16 +643,13 @@ required /> - + + + + {/if} +
{ showAccessControlModal = true; }} + label={$i18n.t('Access Control')} /> {/if}
diff --git a/src/lib/components/common/AccessButton.svelte b/src/lib/components/common/AccessButton.svelte index 24a2b048a6..0381323615 100644 --- a/src/lib/components/common/AccessButton.svelte +++ b/src/lib/components/common/AccessButton.svelte @@ -5,10 +5,11 @@ import LockClosed from '$lib/components/icons/LockClosed.svelte'; + const i18n = getContext>('i18n'); + export let className = ''; export let disabled = false; - - const i18n = getContext>('i18n'); + export let label = ''; diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index f9d908d2ae..f3ba8331b2 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -305,6 +305,7 @@ "Auth required": "", "Authenticate": "", "Authentication": "", + "Authorize OAuth": "", "Auto": "", "Auto (Random)": "", "Auto Redirect": "", @@ -415,6 +416,7 @@ "Channel updated successfully": "", "Channels": "", "Character": "", + "Check OAuth Discovery": "", "Chat": "", "Chat actions": "", "Chat archived.": "", @@ -1901,6 +1903,7 @@ "OAuth Scopes": "", "OAuth scopes requested during sign-in.": "", "OAuth Server URL": "", + "OAuth discovery successful": "", "OAuth session disconnected": "", "OAuth Signup": "", "October": "", @@ -2063,6 +2066,7 @@ "Please enter Client ID and Client Secret": "", "Please fill in all fields.": "", "Please register the OAuth client": "", + "Please save the connection before authorizing OAuth": "", "Please save the connection to persist the OAuth client information and do not change the ID": "", "Please select a model.": "", "Please select a reason": "",