mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 21:05:53 +08:00
MCP server create & update
This commit is contained in:
parent
f0fca59f31
commit
938a180aff
@ -141,7 +141,6 @@ const CardView: FC<ICardViewProps> = ({ appId, isInPanel, className }) => {
|
|||||||
{isInPanel && appDetail.mode === 'workflow' && (
|
{isInPanel && appDetail.mode === 'workflow' && (
|
||||||
<MCPServiceCard
|
<MCPServiceCard
|
||||||
appInfo={appDetail}
|
appInfo={appDetail}
|
||||||
onGenerateCode={onGenerateCode}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
} from '@/app/components/base/icons/src/vender/other'
|
} from '@/app/components/base/icons/src/vender/other'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import { asyncRunSafe } from '@/utils'
|
|
||||||
import Switch from '@/app/components/base/switch'
|
import Switch from '@/app/components/base/switch'
|
||||||
import Divider from '@/app/components/base/divider'
|
import Divider from '@/app/components/base/divider'
|
||||||
import CopyFeedback from '@/app/components/base/copy-feedback'
|
import CopyFeedback from '@/app/components/base/copy-feedback'
|
||||||
@ -21,23 +20,26 @@ import Indicator from '@/app/components/header/indicator'
|
|||||||
import MCPServerModal from '@/app/components/tools/mcp/mcp-server-modal'
|
import MCPServerModal from '@/app/components/tools/mcp/mcp-server-modal'
|
||||||
import { useAppWorkflow } from '@/service/use-workflow'
|
import { useAppWorkflow } from '@/service/use-workflow'
|
||||||
import {
|
import {
|
||||||
|
useInvalidateMCPServerDetail,
|
||||||
useMCPServerDetail,
|
useMCPServerDetail,
|
||||||
|
useRefreshMCPServerCode,
|
||||||
|
useUpdateMCPServer,
|
||||||
} from '@/service/use-tools'
|
} from '@/service/use-tools'
|
||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
export type IAppCardProps = {
|
export type IAppCardProps = {
|
||||||
appInfo: AppDetailResponse & Partial<AppSSO>
|
appInfo: AppDetailResponse & Partial<AppSSO>
|
||||||
onGenerateCode?: () => Promise<void>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MCPServiceCard({
|
function MCPServiceCard({
|
||||||
appInfo,
|
appInfo,
|
||||||
onGenerateCode,
|
|
||||||
}: IAppCardProps) {
|
}: IAppCardProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { mutateAsync: updateMCPServer } = useUpdateMCPServer()
|
||||||
|
const { mutateAsync: refreshMCPServerCode, isPending: genLoading } = useRefreshMCPServerCode()
|
||||||
|
const invalidateMCPServerDetail = useInvalidateMCPServerDetail()
|
||||||
const { isCurrentWorkspaceManager, isCurrentWorkspaceEditor } = useAppContext()
|
const { isCurrentWorkspaceManager, isCurrentWorkspaceEditor } = useAppContext()
|
||||||
const [genLoading, setGenLoading] = useState(false)
|
|
||||||
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
||||||
const [showMCPServerModal, setShowMCPServerModal] = useState(false)
|
const [showMCPServerModal, setShowMCPServerModal] = useState(false)
|
||||||
|
|
||||||
@ -61,23 +63,34 @@ function MCPServiceCard({
|
|||||||
}, [currentWorkflow])
|
}, [currentWorkflow])
|
||||||
|
|
||||||
const onGenCode = async () => {
|
const onGenCode = async () => {
|
||||||
if (onGenerateCode) {
|
await refreshMCPServerCode(detail?.id || '')
|
||||||
setGenLoading(true)
|
invalidateMCPServerDetail(appInfo.id)
|
||||||
await asyncRunSafe(onGenerateCode())
|
|
||||||
setGenLoading(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChangeStatus = async (state: boolean) => {
|
const onChangeStatus = async (state: boolean) => {
|
||||||
|
setActivated(state)
|
||||||
if (state) {
|
if (state) {
|
||||||
if (!serverPublished) {
|
if (!serverPublished)
|
||||||
setActivated(true)
|
|
||||||
setShowMCPServerModal(true)
|
setShowMCPServerModal(true)
|
||||||
}
|
|
||||||
// TODO handle server activation
|
await updateMCPServer({
|
||||||
|
appID: appInfo.id,
|
||||||
|
id: id || '',
|
||||||
|
description: detail?.description || '',
|
||||||
|
parameters: detail?.parameters || {},
|
||||||
|
status: 'active',
|
||||||
|
})
|
||||||
|
invalidateMCPServerDetail(appInfo.id)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO handle server activation
|
await updateMCPServer({
|
||||||
|
appID: appInfo.id,
|
||||||
|
id: id || '',
|
||||||
|
description: detail?.description || '',
|
||||||
|
parameters: detail?.parameters || {},
|
||||||
|
status: 'inactive',
|
||||||
|
})
|
||||||
|
invalidateMCPServerDetail(appInfo.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +231,15 @@ export const useUpdateMCPServer = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useRefreshMCPServerCode = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationKey: [NAME_SPACE, 'refresh-mcp-server-code'],
|
||||||
|
mutationFn: (appID: string) => {
|
||||||
|
return get<MCPServerDetail>(`apps/${appID}/server/refresh`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const useBuiltinProviderInfo = (providerName: string) => {
|
export const useBuiltinProviderInfo = (providerName: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [NAME_SPACE, 'builtin-provider-info', providerName],
|
queryKey: [NAME_SPACE, 'builtin-provider-info', providerName],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user