feat/ui:The server configuration allows switching between Streamable HTTP and SSE.

This commit is contained in:
riverLethe committed 2025-10-22 19:59:49 +08:00
1 parent e25e119ba1
commit b2bd2e30dd
7 files changed
+82 -147

No files matched your search

@@ -1,7 +1,7 @@
"use client";
import React from "react";
import { Card, Chip, Button } from "@nextui-org/react";
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";
@@ -13,23 +13,38 @@ import toast from "react-hot-toast";
interface ServerConfigProps {
mcpName?: string;
url?: string;
className?: string;
}
type McpType = "sse" | "streamable-http";
export const ServerConfig: React.FC<ServerConfigProps> = ({
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<McpType>("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": "sse",
"type": "${mcpType}",
"autoApprove":"all",
"url": "${url}?authkey={Your-${platformConfig?.name}-Auth-Key}"
"url": "${serverUrl}"
}
}
}`;
@@ -45,8 +60,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
};
return (
<div className="min-w-full md:min-w-[40%] w-[40%] max-w-100 flex-shrink-0 mt-12">
<div className="mb-4 mt-1">
<div className={`min-w-full ${className} flex-shrink-0`}>
<div className="mb-2 mt-1">
<FlipButton
className="w-full rounded-md"
text={t("Sign up to get the auth key")}
@@ -54,8 +69,35 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
/>
</div>
{/* MCP Type Selection */}
<div className="mb-2">
<Select
label={t("Transport Type")}
placeholder={t("Select MCP transport type")}
selectedKeys={[mcpType]}
onSelectionChange={(keys) => {
const selectedKey = Array.from(keys)[0] as McpType;
setMcpType(selectedKey);
}}
className="w-full"
size="sm"
classNames={{
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
label: "!text-default-200",
value: "!text-white",
popoverContent: "bg-black text-white",
}}
>
{mcpTypeOptions.map((option) => (
<SelectItem key={option.key} value={option.key}>
{option.label}
</SelectItem>
))}
</Select>
</div>
{/* Code Snippet */}
<Card className="w-full max-w-2xl bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
<Card className="w-full bg-black text-white p-2 sm:p-4 rounded-lg relative z-10">
<div className="text-left font-mono">
<div className="flex items-center gap-2 mb-2 justify-between">
<Chip className="text-white" size="sm" variant="flat">
@@ -77,9 +119,12 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
{`{
"mcpServers": {
"${mcpName || "xpack-mcp-market"}": {
"type": "sse",
"type": "${mcpType}",
"autoApprove":"all",
"url": "${url}?authkey=`}
"url": "`}
{mcpType === "streamable-http"
? `${url}/streamable-http?authkey=`
: `${url}?authkey=`}
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
{`"
}