import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { apiFetch } from '../../lib/api'; import { useI18n } from '../../lib/i18n'; import { useLayoutContext } from '../Layout'; type Project = { id: string; name: string }; export default function McpIntegration({ project }: { project: Project }) { const [copied, setCopied] = useState(null); const { onOpenSettings } = useLayoutContext(); const { t } = useI18n(); const mcpUrl = `${window.location.origin}/mcp/${project.id}`; const { data: keyStatus } = useQuery({ queryKey: ['api-key-status'], queryFn: () => apiFetch<{ hasKey: boolean; prefix: string | null }>('/auth/api-key/status'), }); const serverName = project.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, ''); const configSnippet = JSON.stringify({ mcpServers: { [serverName]: { type: 'http', url: mcpUrl, headers: { Authorization: 'Bearer ' }, }, }, }, null, 2); const copyText = (text: string, key: string) => { navigator.clipboard.writeText(text); setCopied(key); setTimeout(() => setCopied(null), 2000); }; return (
{/* MCP URL */}

{t('dashboard.mcp.urlTitle')}

{t('dashboard.mcp.urlDesc')}

{mcpUrl}
{/* Config snippet */}

{t('dashboard.mcp.configTitle')}

{t('dashboard.mcp.configDesc')}

{configSnippet}
{/* API Key guidance */} {keyStatus && (
{keyStatus.hasKey ? (

{t('dashboard.mcp.keyGenerated')}{' '} {' '}{t('dashboard.mcp.keyReplace')} <your-api-key> {t('dashboard.mcp.keyAbove')}

) : (

{t('dashboard.mcp.noKeyWarning')}

)}
)}
{/* Available tools */}

{t('dashboard.mcp.toolsTitle')}

{t('dashboard.mcp.toolsDesc')}

{[ { name: 'get_project_overview', desc: t('dashboard.mcp.tool1Desc'), num: '1' }, { name: 'list_modules', desc: t('dashboard.mcp.tool2Desc'), num: '2' }, { name: 'list_endpoints', desc: t('dashboard.mcp.tool3Desc'), num: '3' }, { name: 'get_endpoint_detail', desc: t('dashboard.mcp.tool4Desc'), num: '4' }, { name: 'search_endpoints', desc: t('dashboard.mcp.tool5Desc'), num: '5' }, ].map((tool) => (
{tool.num}
{tool.name}

{tool.desc}

))}
); }