🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
feat(connectors): add edit/uninstall buttons for connectors in SkillDetail (#15829)
LiJian346d5be27cdc
diff --git a/apps/server/src/routers/lambda/connector.ts b/apps/server/src/routers/lambda/connector.tsindex 3053d023b9d..2def5ab040c 100644--- a/apps/server/src/routers/lambda/connector.ts+++ b/apps/server/src/routers/lambda/connector.ts@@ -268,9 +268,14 @@ export const connectorRouter = router({await ctx.connectorModel.update(input.id, {...patch,// undefined → leave untouched; null → clear; object → encrypt the JSON string.+ // When credentials are cleared, also drop the cached expiry timestamp so+ // token-refresh logic doesn't act on a stale value for the new server....(credentials === undefined? {}- : { credentials: credentials ? JSON.stringify(credentials) : null }),+ : {+ credentials: credentials ? JSON.stringify(credentials) : null,+ ...(credentials === null ? { tokenExpiresAt: null } : {}),+ }),} as any);}),diff --git a/locales/en-US/tool.json b/locales/en-US/tool.jsonindex edd8e497d85..624e3df2a12 100644--- a/locales/en-US/tool.json+++ b/locales/en-US/tool.json@@ -202,6 +202,10 @@"securityBlacklist.sshPrivateKeys": "Reading SSH private keys can compromise system security","securityBlacklist.sudoers": "Modifying sudoers file without proper validation is dangerous","securityBlacklist.suidShells": "Setting SUID on shells or interpreters is a security risk",+ "connector.edit": "Edit",+ "connector.edit.success": "Connector updated",+ "connector.uninstall": "Uninstall",+ "connector.uninstallConfirm": "Are you sure you want to uninstall this connector?","updateArgs.duplicateKeyError": "Field key must be unique","updateArgs.form.add": "Add an Item","updateArgs.form.key": "Field Key",diff --git a/locales/zh-CN/tool.json b/locales/zh-CN/tool.jsonindex 1379a1269a0..5b6fe9ff3e5 100644--- a/locales/zh-CN/tool.json+++ b/locales/zh-CN/tool.json@@ -202,6 +202,10 @@"securityBlacklist.sshPrivateKeys": "读取 SSH 私钥可能危及系统安全","securityBlacklist.sudoers": "未经正确验证修改 sudoers 文件是危险操作","securityBlacklist.suidShells": "在 Shell 或解释器上设置 SUID 是安全风险",+ "connector.edit": "编辑",+ "connector.edit.success": "连接器已更新",+ "connector.uninstall": "卸载",+ "connector.uninstallConfirm": "确定要卸载此连接器吗?","updateArgs.duplicateKeyError": "字段键必须唯一","updateArgs.form.add": "添加一项","updateArgs.form.key": "字段键",diff --git a/packages/types/src/tool/plugin.ts b/packages/types/src/tool/plugin.tsindex 15446e53db4..df87ae8603d 100644--- a/packages/types/src/tool/plugin.ts+++ b/packages/types/src/tool/plugin.ts@@ -43,6 +43,8 @@ export interface CustomPluginParams {type: 'none' | 'bearer' | 'oauth2';token?: string; // Bearer TokenaccessToken?: string; // OAuth2 Access Token+ clientId?: string; // OAuth2 client ID+ clientSecret?: string; // OAuth2 client secret};// Added headers configuration supportheaders?: Record<string, string>;diff --git a/src/features/Connectors/AddConnectorModal/index.tsx b/src/features/Connectors/AddConnectorModal/index.tsxindex 9f0ce20fb4e..12b9accb6c1 100644--- a/src/features/Connectors/AddConnectorModal/index.tsx+++ b/src/features/Connectors/AddConnectorModal/index.tsx@@ -7,8 +7,11 @@ import { useTranslation } from 'react-i18next';import { ConnectorSourceType } from '@/database/schemas';import { lambdaClient } from '@/libs/trpc/client';import { useToolStore } from '@/store/tool';+import { connectorSelectors } from '@/store/tool/slices/connector';interface AddConnectorModalProps {+ /** If provided, opens in edit mode pre-filling the form from the existing connector. */+ connectorId?: string;onClose: () => void;open: boolean;}@@ -63,14 +66,18 @@ const waitForOAuthPopup = (popup: Window, connectorId: string): Promise<OAuthPop}, 800);});-const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {+const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose, connectorId }) => {const { t } = useTranslation('tool');const { message } = App.useApp();const createConnector = useToolStore((s) => s.createConnector);+ const updateConnector = useToolStore((s) => s.updateConnector);const startConnectorOAuth = useToolStore((s) => s.startConnectorOAuth);const syncConnectorTools = useToolStore((s) => s.syncConnectorTools);const fetchConnectors = useToolStore((s) => s.fetchConnectors);+ const existingConnector = useToolStore(connectorSelectors.connectorById(connectorId ?? ''));+ const isEditMode = !!connectorId;+const [name, setName] = useState('');const [url, setUrl] = useState('');const [clientId, setClientId] = useState('');@@ -78,6 +85,17 @@ const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {const [showAdvanced, setShowAdvanced] = useState(false);const [submitting, setSubmitting] = useState(false);+ // Pre-fill form when opening in edit mode+ useEffect(() => {+ if (open && isEditMode && existingConnector) {+ setName(existingConnector.name);+ setUrl(existingConnector.mcpServerUrl ?? '');+ setClientId('');+ setClientSecret('');+ setShowAdvanced(false);+ }+ }, [open, isEditMode, existingConnector]);+// Show the exact redirect URI the SERVER will use (APP_URL-based), so what the// user registers matches what is sent at authorize time. Fall back to the// current origin only if the query fails.@@ -130,7 +148,7 @@ const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {// client_id present → pre-registration; absent → dynamic client registration (DCR).const scheme = trimmedClientId ? 'pre_registration' : 'dcr';- const connectorId = await createConnector({+ const newConnectorId = await createConnector({identifier: name.toLowerCase().replaceAll(/\s+/g, '-'),mcpConnectionType: 'http',mcpServerUrl: url.trim(),@@ -148,9 +166,9 @@ const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {// If the server turns out not to require OAuth (no authorization server// discovered), fall back to a plain tool sync for public MCP servers.try {- const authorizationUrl = await startConnectorOAuth(connectorId);+ const authorizationUrl = await startConnectorOAuth(newConnectorId);popup.location.href = authorizationUrl;- const result = await waitForOAuthPopup(popup, connectorId);+ const result = await waitForOAuthPopup(popup, newConnectorId);// Reflect the server-side state regardless of how the popup ended// (window.close is often blocked for cross-origin-navigated popups).await fetchConnectors();@@ -177,7 +195,7 @@ const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {} catch {popup.close();try {- await syncConnectorTools(connectorId);+ await syncConnectorTools(newConnectorId);message.success(t('connector.add.success', 'Connector connected'));} catch {message.error(@@ -196,21 +214,119 @@ const AddConnectorModal = memo<AddConnectorModalProps>(({ open, onClose }) => {}};+ const handleEdit = async () => {+ if (!name.trim() || !url.trim() || !connectorId) return;++ const trimmedClientId = clientId.trim();+ const trimmedClientSecret = clientSecret.trim();+ const hasNewCredentials = !!trimmedClientId || !!trimmedClientSecret;+ const urlChanged = url.trim() !== (existingConnector?.mcpServerUrl ?? '');+ // Re-run OAuth if the URL changed or new credentials were supplied+ const needsReAuth = urlChanged || hasNewCredentials;++ let popup: Window | null = null;+ if (needsReAuth) {+ popup = window.open('about:blank', 'lobe-connector-oauth', 'width=600,height=720');+ if (!popup) {+ message.error(+ t('connector.add.popupBlocked', 'Please allow popups for this site and try again.'),+ );+ return;+ }+ }++ setSubmitting(true);+ try {+ const scheme = trimmedClientId ? 'pre_registration' : 'dcr';+ await updateConnector(connectorId, {+ ...(urlChanged ? { credentials: null } : {}),+ mcpServerUrl: url.trim(),+ name: name.trim(),+ ...(hasNewCredentials+ ? {+ oidcConfig: {+ clientId: trimmedClientId || undefined,+ clientSecret: trimmedClientSecret || undefined,+ scheme,+ },+ }+ : {}),+ });++ if (needsReAuth && popup) {+ try {+ const authorizationUrl = await startConnectorOAuth(connectorId);+ popup.location.href = authorizationUrl;+ const result = await waitForOAuthPopup(popup, connectorId);+ await fetchConnectors();+ if (result.status === 'success') {+ if (result.synced === false) {+ message.warning(+ t(+ 'connector.add.syncFailed',+ 'Authorized, but tools could not be synced. Click Sync to retry.',+ ),+ );+ } else {+ message.success(t('connector.edit.success', 'Connector updated'));+ }+ } else if (result.status === 'error') {+ message.error(+ t('connector.add.authError', 'Authorization failed: {{reason}}', {+ reason: result.error || t('connector.add.unknownError', 'unknown error'),+ }),+ );+ } else {+ message.warning(t('connector.add.cancelled', 'Authorization was not completed'));+ }+ } catch {+ popup.close();+ try {+ await syncConnectorTools(connectorId);+ message.success(t('connector.edit.success', 'Connector updated'));+ } catch {+ message.error(+ t(+ 'connector.add.authFailed',+ 'Could not connect. This server may require an OAuth Client ID in Advanced settings.',+ ),+ );+ }+ }+ } else {+ message.success(t('connector.edit.success', 'Connector updated'));+ }++ reset();+ onClose();+ } finally {+ setSubmitting(false);+ }+ };+const handleCancel = () => {reset();onClose();};+ const modalTitle = isEditMode+ ? t('connector.add.editTitle', 'Edit Connector')+ : t('connector.add.title', 'Add custom connector');++ const okText = isEditMode+ ? t('connector.add.update', 'Save')+ : t('connector.add.confirm', 'Add');+return (<ModalcancelText={t('connector.add.cancel', 'Cancel')}confirmLoading={submitting}okButtonProps={{ disabled: !name.trim() || !url.trim() }}- okText={t('connector.add.confirm', 'Add')}+ okText={okText}open={open}- title={t('connector.add.title', 'Add custom connector')}+ title={modalTitle}onCancel={handleCancel}- onOk={handleAdd}+ onOk={isEditMode ? handleEdit : handleAdd}><div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}><div>diff --git a/src/features/Connectors/ConnectorDetail/index.tsx b/src/features/Connectors/ConnectorDetail/index.tsxindex 9717e353896..808b58ba363 100644--- a/src/features/Connectors/ConnectorDetail/index.tsx+++ b/src/features/Connectors/ConnectorDetail/index.tsx@@ -1,7 +1,7 @@import { confirmModal } from '@lobehub/ui/base-ui';import { Button } from 'antd';-import { RefreshCwIcon, Trash2 } from 'lucide-react';-import { memo, useCallback } from 'react';+import { PencilIcon, RefreshCwIcon, Trash2 } from 'lucide-react';+import { memo, useCallback, useState } from 'react';import { useTranslation } from 'react-i18next';import type { ConnectorToolPermission } from '@/database/schemas';@@ -9,6 +9,7 @@ import { ConnectorSourceType } from '@/database/schemas';import { useToolStore } from '@/store/tool';import { connectorSelectors } from '@/store/tool/slices/connector';+import CustomConnectorModal from '../CustomConnectorModal';import ToolPermissionGroup from './ToolPermissionGroup';interface ConnectorDetailProps {@@ -18,6 +19,7 @@ interface ConnectorDetailProps {const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) => {const { t } = useTranslation('tool');+ const [customModalOpen, setCustomModalOpen] = useState(false);const connector = useToolStore(connectorSelectors.connectorById(connectorId));const { readTools, createTools, updateTools, deleteTools } = useToolStore(@@ -31,9 +33,14 @@ const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) =const resetConnectorPermissions = useToolStore((s) => s.resetConnectorPermissions);const disconnectConnector = useToolStore((s) => s.disconnectConnector);const deleteConnector = useToolStore((s) => s.deleteConnector);+ const uninstallBuiltinTool = useToolStore((s) => s.uninstallBuiltinTool);+ const uninstallMCPPlugin = useToolStore((s) => s.uninstallMCPPlugin);+ const fetchConnectors = useToolStore((s) => s.fetchConnectors);const updateToolPermission = useToolStore((s) => s.updateToolPermission);const isMcpConnector = connector?.sourceType === ConnectorSourceType.custom;+ const isBuiltin = connector?.sourceType === ConnectorSourceType.builtin;+ const isMarketplace = connector?.sourceType === ConnectorSourceType.marketplace;const handleSync = useCallback(async () => {if (!connector) return;@@ -46,6 +53,23 @@ const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) =}}, [connector, connectorId, syncBuiltinTool, syncPluginTools, syncConnectorTools]);+ const handleUninstall = () => {+ if (!connector) return;+ confirmModal({+ okButtonProps: { danger: true },+ onOk: async () => {+ if (isBuiltin) {+ await uninstallBuiltinTool(connector.identifier);+ } else if (isMarketplace) {+ await uninstallMCPPlugin(connector.identifier);+ }+ await deleteConnector(connectorId);+ onDelete?.();+ },+ title: t('connector.uninstallConfirm', 'Uninstall this tool?'),+ });+ };+if (!connector) return null;// Sync button label: re-sync tool list from manifest (does NOT reset permissions)@@ -91,6 +115,17 @@ const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) =>{syncLabel}</Button>+ {/* Edit button for custom MCP connectors — only http type has a server URL to edit */}+ {isMcpConnector && connector?.mcpConnectionType === 'http' && (+ <Button+ icon={<PencilIcon size={14} />}+ size="small"+ onClick={() => setCustomModalOpen(true)}+ >+ {t('connector.edit', 'Edit')}+ </Button>+ )}+ {/* Disconnect / Delete for custom MCP connectors */}{isMcpConnector && (<><Button danger size="small" onClick={() => disconnectConnector(connectorId)}>@@ -115,6 +150,17 @@ const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) =</Button></>)}+ {/* Uninstall for builtin and marketplace tools */}+ {(isBuiltin || isMarketplace) && (+ <Button+ danger+ icon={<Trash2 size={14} />}+ size="small"+ onClick={handleUninstall}+ >+ {t('connector.uninstall', 'Uninstall')}+ </Button>+ )}</div></div>@@ -164,6 +210,18 @@ const ConnectorDetail = memo<ConnectorDetailProps>(({ connectorId, onDelete }) ={t('connector.noTools', 'No tool permissions to configure.')}</div>)}++ {/* Edit modal — only http connectors have a server URL to edit */}+ {isMcpConnector && connector?.mcpConnectionType === 'http' && (+ <CustomConnectorModal+ connectorId={connectorId}+ open={customModalOpen}+ onClose={() => setCustomModalOpen(false)}+ onEditSuccess={() => {+ fetchConnectors();+ }}+ />+ )}</div>);});diff --git a/src/features/Connectors/CustomConnectorModal/index.tsx b/src/features/Connectors/CustomConnectorModal/index.tsxindex 34519c6a90d..6a9f55a13a2 100644--- a/src/features/Connectors/CustomConnectorModal/index.tsx+++ b/src/features/Connectors/CustomConnectorModal/index.tsx@@ -1,12 +1,15 @@import { type LobeToolCustomPlugin } from '@lobechat/types';-import { memo } from 'react';+import { memo, useMemo } from 'react';import { ConnectorSourceType } from '@/database/schemas';import DevModal from '@/features/PluginDevModal';import { useToolStore } from '@/store/tool';+import { connectorSelectors } from '@/store/tool/slices/connector';interface CustomConnectorModalProps {+ connectorId?: string;onClose: () => void;+ onEditSuccess?: () => void;open: boolean;}@@ -63,104 +66,220 @@ const cleanRecord = (record?: Record<string, string>): Record<string, string> |};/**- * "Add custom connector" entry. Reuses the rich PluginDevModal MCP form, but- * persists everything onto the connector subsystem (the single backend for+ * "Add / Edit custom connector" entry. Reuses the rich PluginDevModal MCP form,+ * but persists everything onto the connector subsystem (the single backend for* custom MCP) instead of the legacy custom-plugin store:*+ * Create mode:* - none / bearer / custom headers → create + sync the tool list directly* - OAuth → create with the OIDC config, then run the authorize-code popup flow* (the popup is opened synchronously inside DevModal's save handler)+ *+ * Edit mode (connectorId provided):+ * - Pre-fills the form from the existing connector record+ * - Calls updateConnector instead of createConnector on save+ * - Clears credentials when the server URL changes*/-const CustomConnectorModal = memo<CustomConnectorModalProps>(({ open, onClose }) => {- const createConnector = useToolStore((s) => s.createConnector);- const startConnectorOAuth = useToolStore((s) => s.startConnectorOAuth);- const syncConnectorTools = useToolStore((s) => s.syncConnectorTools);- const fetchConnectors = useToolStore((s) => s.fetchConnectors);-- const handleSave = async (value: LobeToolCustomPlugin, ctx?: { oauthPopup?: Window | null }) => {- const mcp = (value.customParams?.mcp ?? {}) as {- args?: string[];- auth?: { clientId?: string; clientSecret?: string; token?: string; type?: string };- command?: string;- env?: Record<string, string>;- headers?: Record<string, string>;- type?: 'http' | 'stdio';- url?: string;- };- const identifier = value.identifier;- const isHttp = mcp.type !== 'stdio';- const authType = mcp.auth?.type;-- const base = {- identifier,- mcpConnectionType: (mcp.type ?? 'http') as 'http' | 'stdio',- mcpServerUrl: isHttp ? mcp.url?.trim() : undefined,- mcpStdioConfig: isHttp- ? undefined- : { args: mcp.args ?? [], command: (mcp.command ?? '').trim(), env: cleanRecord(mcp.env) },- name: identifier,- sourceType: ConnectorSourceType.custom,- };+const CustomConnectorModal = memo<CustomConnectorModalProps>(+ ({ open, onClose, connectorId, onEditSuccess }) => {+ const createConnector = useToolStore((s) => s.createConnector);+ const updateConnector = useToolStore((s) => s.updateConnector);+ const startConnectorOAuth = useToolStore((s) => s.startConnectorOAuth);+ const syncConnectorTools = useToolStore((s) => s.syncConnectorTools);+ const fetchConnectors = useToolStore((s) => s.fetchConnectors);++ const connector = useToolStore(+ connectorId ? connectorSelectors.connectorById(connectorId) : () => undefined,+ );++ const isEditMode = Boolean(connectorId);++ // Build the pre-fill value for edit mode from the stored connector.+ const editValue = useMemo((): LobeToolCustomPlugin | undefined => {+ if (!isEditMode || !connector) return undefined;++ const c = connector as typeof connector & {+ mcpStdioConfig?: { args?: string[]; command?: string; env?: Record<string, string> };+ oidcConfig?: { clientId?: string; clientSecret?: string; scheme?: string };+ };++ const oidcConfig = c.oidcConfig;+ const mcpStdioConfig = c.mcpStdioConfig;++ const credentials = (c as typeof c & {+ credentials?: { headers?: Record<string, string>; token?: string; type?: string };+ }).credentials;++ const authType = oidcConfig+ ? 'oauth2'+ : credentials?.type === 'bearer'+ ? 'bearer'+ : credentials?.type === 'header'+ ? 'header'+ : 'none';++ return {+ customParams: {+ description: connector.metadata?.description as string | undefined,+ mcp: {+ args: mcpStdioConfig?.args,+ auth: {+ clientId: oidcConfig?.clientId,+ token: authType === 'bearer' ? credentials?.token : undefined,+ type: authType === 'header' ? 'none' : authType,+ },+ command: mcpStdioConfig?.command,+ env: mcpStdioConfig?.env,+ headers: authType === 'header' ? credentials?.headers : undefined,+ type: (connector.mcpConnectionType ?? 'http') as 'http' | 'stdio',+ url: connector.mcpServerUrl ?? undefined,+ },+ },+ identifier: connector.identifier,+ type: 'customPlugin' as const,+ };+ }, [isEditMode, connector]);++ const handleSave = async (value: LobeToolCustomPlugin, ctx?: { oauthPopup?: Window | null }) => {+ const mcp = (value.customParams?.mcp ?? {}) as {+ args?: string[];+ auth?: { clientId?: string; clientSecret?: string; token?: string; type?: string };+ command?: string;+ env?: Record<string, string>;+ headers?: Record<string, string>;+ type?: 'http' | 'stdio';+ url?: string;+ };+ const identifier = value.identifier;+ const isHttp = mcp.type !== 'stdio';+ const authType = mcp.auth?.type;++ // ── Edit mode ─────────────────────────────────────────────────────────+ if (isEditMode && connectorId) {+ const newUrl = isHttp ? mcp.url?.trim() : undefined;+ const urlChanged = newUrl !== (connector?.mcpServerUrl ?? undefined);++ const patch: Record<string, any> = {};++ if (newUrl !== undefined) patch.mcpServerUrl = newUrl;++ if (urlChanged) {+ // Clear stale credentials whenever the server URL changes.+ patch.credentials = null;+ } else if (authType === 'bearer' && mcp.auth?.token?.trim()) {+ patch.credentials = { token: mcp.auth.token.trim(), type: 'bearer' as const };+ } else if (authType === 'header') {+ const headers = cleanRecord(mcp.headers);+ if (headers) patch.credentials = { headers, type: 'header' as const };+ } else if (authType === 'none') {+ patch.credentials = null;+ }- // OAuth: create with the OIDC config, then drive the authorize popup that- // DevModal already opened synchronously for us.- if (isHttp && authType === 'oauth2') {- const popup = ctx?.oauthPopup ?? null;- if (!popup) throw new Error('OAuth popup was blocked');-- const clientId = mcp.auth?.clientId?.trim();- try {- const connectorId = await createConnector({- ...base,- oidcConfig: {+ if (authType === 'oauth2') {+ const clientId = mcp.auth?.clientId?.trim();+ patch.oidcConfig = {clientId: clientId || undefined,clientSecret: mcp.auth?.clientSecret?.trim() || undefined,- // client_id present → pre-registration; absent → dynamic registration.scheme: clientId ? 'pre_registration' : 'dcr',- },- });-- const authorizationUrl = await startConnectorOAuth(connectorId);- popup.location.href = authorizationUrl;- const result = await waitForOAuthPopup(popup, connectorId);- await fetchConnectors();- if (result.status !== 'success') {- throw new Error(result.error || 'Authorization was not completed');+ };+ }++ await updateConnector(connectorId, patch);++ if (authType === 'oauth2' && isHttp) {+ const popup = ctx?.oauthPopup ?? null;+ if (!popup) throw new Error('OAuth popup was blocked');+ try {+ const authorizationUrl = await startConnectorOAuth(connectorId);+ popup.location.href = authorizationUrl;+ const result = await waitForOAuthPopup(popup, connectorId);+ await fetchConnectors();+ if (result.status !== 'success') {+ throw new Error(result.error || 'Authorization was not completed');+ }+ } catch (e) {+ if (!popup.closed) popup.close();+ throw e;+ }}- } catch (e) {- // Close the blank/in-flight popup we opened so it isn't left dangling.- // On success the OAuth callback page closes it itself.- if (!popup.closed) popup.close();- throw e;++ onEditSuccess?.();+ return;}- return;- }-- // None / bearer / custom headers: store credentials and sync the tool list.- const credentials =- authType === 'bearer' && mcp.auth?.token?.trim()- ? ({ token: mcp.auth.token.trim(), type: 'bearer' } as const)- : (() => {- const headers = cleanRecord(mcp.headers);- return headers ? ({ headers, type: 'header' } as const) : undefined;- })();-- const connectorId = await createConnector({ ...base, credentials });- await syncConnectorTools(connectorId);- };-- return (- <DevModal- enableOAuth- mode={'create'}- open={open}- onSave={handleSave}- onOpenChange={(next) => {- if (!next) onClose();- }}- />- );-});++ // ── Create mode ───────────────────────────────────────────────────────+ const base = {+ identifier,+ mcpConnectionType: (mcp.type ?? 'http') as 'http' | 'stdio',+ mcpServerUrl: isHttp ? mcp.url?.trim() : undefined,+ mcpStdioConfig: isHttp+ ? undefined+ : { args: mcp.args ?? [], command: (mcp.command ?? '').trim(), env: cleanRecord(mcp.env) },+ name: identifier,+ sourceType: ConnectorSourceType.custom,+ };++ // OAuth: create with the OIDC config, then drive the authorize popup that+ // DevModal already opened synchronously for us.+ if (isHttp && authType === 'oauth2') {+ const popup = ctx?.oauthPopup ?? null;+ if (!popup) throw new Error('OAuth popup was blocked');++ const clientId = mcp.auth?.clientId?.trim();+ try {+ const newConnectorId = await createConnector({+ ...base,+ oidcConfig: {+ clientId: clientId || undefined,+ clientSecret: mcp.auth?.clientSecret?.trim() || undefined,+ // client_id present → pre-registration; absent → dynamic registration.+ scheme: clientId ? 'pre_registration' : 'dcr',+ },+ });++ const authorizationUrl = await startConnectorOAuth(newConnectorId);+ popup.location.href = authorizationUrl;+ const result = await waitForOAuthPopup(popup, newConnectorId);+ await fetchConnectors();+ if (result.status !== 'success') {+ throw new Error(result.error || 'Authorization was not completed');+ }+ } catch (e) {+ // Close the blank/in-flight popup we opened so it isn't left dangling.+ // On success the OAuth callback page closes it itself.+ if (!popup.closed) popup.close();+ throw e;+ }+ return;+ }++ // None / bearer / custom headers: store credentials and sync the tool list.+ const credentials =+ authType === 'bearer' && mcp.auth?.token?.trim()+ ? ({ token: mcp.auth.token.trim(), type: 'bearer' } as const)+ : (() => {+ const headers = cleanRecord(mcp.headers);+ return headers ? ({ headers, type: 'header' } as const) : undefined;+ })();++ const newConnectorId = await createConnector({ ...base, credentials });+ await syncConnectorTools(newConnectorId);+ };++ return (+ <DevModal+ enableOAuth+ mode={isEditMode ? 'edit' : 'create'}+ open={open}+ value={editValue}+ onSave={handleSave}+ onOpenChange={(next) => {+ if (!next) onClose();+ }}+ />+ );+ },+);CustomConnectorModal.displayName = 'CustomConnectorModal';diff --git a/src/store/tool/slices/connector/action.ts b/src/store/tool/slices/connector/action.tsindex 4d67bf6691a..c181782e222 100644--- a/src/store/tool/slices/connector/action.ts+++ b/src/store/tool/slices/connector/action.ts@@ -50,6 +50,24 @@ export class ConnectorActionImpl {await this.fetchConnectors();};+ updateConnector = async (+ id: string,+ patch: {+ credentials?: null;+ isEnabled?: boolean;+ mcpServerUrl?: string;+ name?: string;+ oidcConfig?: {+ clientId?: string;+ clientSecret?: string;+ scheme?: 'pre_registration' | 'dcr' | 'client_id_metadata_document';+ };+ },+ ): Promise<void> => {+ await lambdaClient.connector.update.mutate({ id, patch: patch as any });+ await this.fetchConnectors();+ };+syncConnectorTools = async (id: string): Promise<void> => {this.#set((s) => ({ connectorSyncing: { ...s.connectorSyncing, [id]: true } }),