"use client"; import React, { useState } from "react"; import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react"; import { FlipButton } from "@/shared/components/FlipButton"; import { useAuth } from "@/shared/lib/useAuth"; import { useTranslation } from "react-i18next"; import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext"; import { Copy } from "lucide-react"; import { copyToClipboard } from "@/shared/utils/clipboard"; import toast from "react-hot-toast"; interface ServerConfigProps { mcpName?: string; url?: string; className?: string; } type McpType = "sse" | "streamable-http"; export const ServerConfig: React.FC = ({ mcpName, url = process.env.NEXT_PUBLIC_MCP_URL, className = "md:min-w-[40%] w-[40%] max-w-100 mt-12", }) => { const { t } = useTranslation(); const { handleLogin } = useAuth(); const { platformConfig } = usePlatformConfig(); const [mcpType, setMcpType] = useState("sse"); const mcpTypeOptions = [ { key: "sse", label: "SSE (Server-Sent Events)" }, { key: "streamable-http", label: "Streamable HTTP" }, ]; const getCodeContent = () => { const serverUrl = mcpType === "streamable-http" ? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}` : `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`; return `{ "mcpServers": { "${mcpName || "xpack-mcp-market"}": { "type": "${mcpType}", "autoApprove":"all", "url": "${serverUrl}" } } }`; }; const handleCopy = async () => { const result = await copyToClipboard(getCodeContent()); if (result.success) { toast.success(t("Copied to clipboard")); } else { toast.error(t("Copy failed, please copy manually")); } }; return (
{/* MCP Type Selection */}
{/* Code Snippet */}
{platformConfig?.name} MCP
            
              {`{
  "mcpServers": {
    "${mcpName || "xpack-mcp-market"}": {
      "type": "${mcpType}",
      "autoApprove":"all",
      "url": "`}
              {mcpType === "streamable-http"
                ? `${url}/streamable-http?authkey=`
                : `${url}?authkey=`}
              {`{Your-${platformConfig?.name}-Auth-Key}`}
              {`"
    }
  }
}`}
            
          
); };