mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat(web): add sandbox mode check for MCP tool availability
Extend MCP tool availability context to include sandbox mode check alongside version support. MCP tools are now blocked when sandbox is disabled, with appropriate tooltip messages for each blocking condition.
This commit is contained in:
@ -4,6 +4,7 @@ import { createContext, useContext } from 'react'
|
||||
|
||||
type MCPToolAvailabilityContextValue = {
|
||||
versionSupported?: boolean
|
||||
sandboxEnabled?: boolean
|
||||
}
|
||||
|
||||
const MCPToolAvailabilityContext = createContext<MCPToolAvailabilityContextValue | undefined>(undefined)
|
||||
@ -11,28 +12,53 @@ const MCPToolAvailabilityContext = createContext<MCPToolAvailabilityContextValue
|
||||
export type MCPToolAvailability = {
|
||||
allowed: boolean
|
||||
versionSupported?: boolean
|
||||
sandboxEnabled?: boolean
|
||||
blockedBy?: 'version' | 'sandbox'
|
||||
}
|
||||
|
||||
export const MCPToolAvailabilityProvider = ({
|
||||
versionSupported,
|
||||
sandboxEnabled,
|
||||
children,
|
||||
}: {
|
||||
versionSupported?: boolean
|
||||
sandboxEnabled?: boolean
|
||||
children: ReactNode
|
||||
}) => (
|
||||
<MCPToolAvailabilityContext.Provider value={{ versionSupported }}>
|
||||
{children}
|
||||
</MCPToolAvailabilityContext.Provider>
|
||||
)
|
||||
}) => {
|
||||
const parentContext = useContext(MCPToolAvailabilityContext)
|
||||
const value = {
|
||||
versionSupported: versionSupported !== undefined
|
||||
? versionSupported
|
||||
: parentContext?.versionSupported,
|
||||
sandboxEnabled: sandboxEnabled !== undefined
|
||||
? sandboxEnabled
|
||||
: parentContext?.sandboxEnabled,
|
||||
}
|
||||
return (
|
||||
<MCPToolAvailabilityContext.Provider value={value}>
|
||||
{children}
|
||||
</MCPToolAvailabilityContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useMCPToolAvailability = (): MCPToolAvailability => {
|
||||
const context = useContext(MCPToolAvailabilityContext)
|
||||
if (context === undefined)
|
||||
return { allowed: true }
|
||||
|
||||
const { versionSupported } = context
|
||||
const { versionSupported, sandboxEnabled } = context
|
||||
const versionAllowed = versionSupported ?? true
|
||||
const sandboxAllowed = sandboxEnabled ?? true
|
||||
const allowed = versionAllowed && sandboxAllowed
|
||||
let blockedBy: MCPToolAvailability['blockedBy']
|
||||
if (!versionAllowed)
|
||||
blockedBy = 'version'
|
||||
else if (!sandboxAllowed)
|
||||
blockedBy = 'sandbox'
|
||||
return {
|
||||
allowed: versionSupported === true,
|
||||
allowed,
|
||||
versionSupported,
|
||||
sandboxEnabled,
|
||||
blockedBy,
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,14 +4,19 @@ import { RiAlertFill } from '@remixicon/react'
|
||||
import * as React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Tooltip from '@/app/components/base/tooltip'
|
||||
import { useMCPToolAvailability } from './mcp-tool-availability'
|
||||
|
||||
const McpToolNotSupportTooltip: FC = () => {
|
||||
const { t } = useTranslation()
|
||||
const { blockedBy } = useMCPToolAvailability()
|
||||
const messageKey = blockedBy === 'sandbox'
|
||||
? 'detailPanel.toolSelector.mcpToolSandboxOnly'
|
||||
: 'detailPanel.toolSelector.unsupportedMCPTool'
|
||||
return (
|
||||
<Tooltip
|
||||
popupContent={(
|
||||
<div className="w-[256px]">
|
||||
{t('detailPanel.toolSelector.unsupportedMCPTool', { ns: 'plugin' })}
|
||||
{t(messageKey, { ns: 'plugin' })}
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user