diff --git a/web/app/components/tools/mcp/mcp-server-modal.tsx b/web/app/components/tools/mcp/mcp-server-modal.tsx index 26fb8a17dd..3783291172 100644 --- a/web/app/components/tools/mcp/mcp-server-modal.tsx +++ b/web/app/components/tools/mcp/mcp-server-modal.tsx @@ -60,7 +60,7 @@ const MCPServerModal = ({
-
{t('tools.mcp.server.modal.parameters')}
+
{t('tools.mcp.server.modal.parameters')}
{t('tools.mcp.server.modal.parametersTip')}
diff --git a/web/app/components/tools/mcp/mcp-service-card.tsx b/web/app/components/tools/mcp/mcp-service-card.tsx index 0d0dc2d498..1d3a191425 100644 --- a/web/app/components/tools/mcp/mcp-service-card.tsx +++ b/web/app/components/tools/mcp/mcp-service-card.tsx @@ -1,5 +1,5 @@ 'use client' -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiLoopLeftLine, @@ -10,7 +10,6 @@ import { import Button from '@/app/components/base/button' import Tooltip from '@/app/components/base/tooltip' import { asyncRunSafe } from '@/utils' -import { basePath } from '@/utils/var' import Switch from '@/app/components/base/switch' import Divider from '@/app/components/base/divider' import CopyFeedback from '@/app/components/base/copy-feedback' @@ -21,6 +20,9 @@ import type { AppSSO } from '@/types/app' import Indicator from '@/app/components/header/indicator' import MCPServerModal from '@/app/components/tools/mcp/mcp-server-modal' import { useAppWorkflow } from '@/service/use-workflow' +import { + useMCPServerDetail, +} from '@/service/use-tools' import cn from '@/utils/classnames' export type IAppCardProps = { @@ -36,14 +38,20 @@ function MCPServiceCard({ const { isCurrentWorkspaceManager, isCurrentWorkspaceEditor } = useAppContext() const [genLoading, setGenLoading] = useState(false) const [showConfirmDelete, setShowConfirmDelete] = useState(false) + const [showMCPServerModal, setShowMCPServerModal] = useState(false) const { data: currentWorkflow } = useAppWorkflow(appInfo.id) + const { data: detail } = useMCPServerDetail(appInfo.id) + const { id, status, server_code } = detail ?? {} - const toggleDisabled = !isCurrentWorkspaceEditor || !currentWorkflow?.graph - const runningStatus = appInfo.enable_site // TODO - const { app_base_url, access_token } = appInfo.site ?? {} - const appMode = (appInfo.mode !== 'completion' && appInfo.mode !== 'workflow') ? 'chat' : appInfo.mode - const appUrl = `${app_base_url}${basePath}/${appMode}/${access_token}` + const appUnpublished = !currentWorkflow?.graph + const serverPublished = !!id + const serverActivated = status === 'active' + const serverURL = serverPublished ? `${globalThis.location.protocol}//${globalThis.location.host}/api/server/${server_code}/mcp` : '***********' + + const toggleDisabled = !isCurrentWorkspaceEditor || appUnpublished + + const [activated, setActivated] = useState(serverActivated) const onGenCode = async () => { if (onGenerateCode) { @@ -53,17 +61,36 @@ function MCPServiceCard({ } } - const onChangeStatus = async (status: boolean) => { - // TODO + const onChangeStatus = async (state: boolean) => { + if (state) { + if (!serverPublished) { + setActivated(true) + setShowMCPServerModal(true) + } + // TODO handle server activation + } + else { + // TODO handle server activation + } } - const [showMCPServerModal, setShowMCPServerModal] = useState(false) + const handleServerModalHide = () => { + setShowMCPServerModal(false) + if (!serverActivated) + setActivated(false) + } + + const handleServerModalConfirm = () => { + setShowMCPServerModal(false) + } + + useEffect(() => { + setActivated(serverActivated) + }, [serverActivated]) if (!currentWorkflow) return null - // TODO: show disabled state if workflow not published - return ( <>
@@ -81,14 +108,20 @@ function MCPServiceCard({
- -
- {runningStatus + +
+ {serverActivated ? t('appOverview.overview.status.running') : t('appOverview.overview.status.disable')}
- + +
+ +
+
@@ -97,53 +130,64 @@ function MCPServiceCard({
- {appUrl} + {serverURL}
- - - {/* button copy link/ button regenerate */} - {showConfirmDelete && ( - { - onGenCode() - setShowConfirmDelete(false) - }} - onCancel={() => setShowConfirmDelete(false)} - /> - )} - {isCurrentWorkspaceManager && ( - -
setShowConfirmDelete(true)} - > - -
-
+ {serverPublished && ( + <> + + + {isCurrentWorkspaceManager && ( + +
setShowConfirmDelete(true)} + > + +
+
+ )} + )}
- +
{showMCPServerModal && ( setShowMCPServerModal(false)} - onHide={() => setShowMCPServerModal(false)} + onConfirm={handleServerModalConfirm} + onHide={handleServerModalHide} + /> + )} + {/* button copy link/ button regenerate */} + {showConfirmDelete && ( + { + onGenCode() + setShowConfirmDelete(false) + }} + onCancel={() => setShowConfirmDelete(false)} /> )} diff --git a/web/i18n/en-US/tools.ts b/web/i18n/en-US/tools.ts index fd264f381b..bc8c0b2d1c 100644 --- a/web/i18n/en-US/tools.ts +++ b/web/i18n/en-US/tools.ts @@ -206,6 +206,7 @@ const translation = { parametersPlaceholder: 'Parameter purpose and constraints', confirm: 'Enable MCP Server', }, + publishTip: 'App not published. Please publish the app first.', }, }, } diff --git a/web/i18n/zh-Hans/tools.ts b/web/i18n/zh-Hans/tools.ts index be8b67de4f..5aecc01f1a 100644 --- a/web/i18n/zh-Hans/tools.ts +++ b/web/i18n/zh-Hans/tools.ts @@ -206,6 +206,7 @@ const translation = { parametersPlaceholder: '参数的用途和约束条件', confirm: '启用 MCP 服务', }, + publishTip: '应用未发布。请先发布应用。', }, }, }