|
9 | 9 | DEFAULT_SERVER_DIR, |
10 | 10 | MCP_CLIENTS, |
11 | 11 | type McpSnippetOptions, |
| 12 | + type McpTransport, |
| 13 | + REMOTE_URL, |
12 | 14 | } from "@/lib/mcp/clients"; |
13 | 15 |
|
14 | 16 | function CopyButton({ text }: { text: string }) { |
@@ -38,48 +40,82 @@ function CopyButton({ text }: { text: string }) { |
38 | 40 | ); |
39 | 41 | } |
40 | 42 |
|
| 43 | +const TRANSPORTS: { id: McpTransport; label: string; hint: string }[] = [ |
| 44 | + { id: "remote", label: "Hosted", hint: "mcp.surfsense.com — nothing to install" }, |
| 45 | + { id: "stdio", label: "Self-host", hint: "run the server against your own backend" }, |
| 46 | +]; |
| 47 | + |
41 | 48 | /** |
42 | | - * Per-agent MCP setup instructions as tabs: pick a client, follow its steps, |
43 | | - * copy its exact config. Used on the /mcp-server marketing page and in the |
44 | | - * API playground; `options` fills in real values where the caller has them. |
| 49 | + * Per-agent MCP setup instructions as tabs: pick a client, then Hosted or |
| 50 | + * Self-host, and copy its exact config. Used on the /mcp-server marketing page |
| 51 | + * and in the API playground; `options` fills in real values where the caller |
| 52 | + * has them. |
45 | 53 | */ |
46 | 54 | export function AgentSetupTabs({ options }: { options?: Partial<McpSnippetOptions> }) { |
| 55 | + const [transport, setTransport] = useState<McpTransport>("remote"); |
| 56 | + |
47 | 57 | const resolved: McpSnippetOptions = { |
48 | | - baseUrl: options?.baseUrl || "https://api.surfsense.com", |
| 58 | + remoteUrl: options?.remoteUrl || REMOTE_URL, |
49 | 59 | apiKey: options?.apiKey || API_KEY_PLACEHOLDER, |
| 60 | + baseUrl: options?.baseUrl || "https://api.surfsense.com", |
50 | 61 | serverDir: options?.serverDir || DEFAULT_SERVER_DIR, |
51 | 62 | }; |
52 | 63 |
|
| 64 | + const active = TRANSPORTS.find((t) => t.id === transport) ?? TRANSPORTS[0]; |
| 65 | + |
53 | 66 | return ( |
54 | | - <Tabs defaultValue={MCP_CLIENTS[0].id} className="w-full"> |
55 | | - <TabsList className="flex h-auto flex-wrap justify-start gap-1"> |
56 | | - {MCP_CLIENTS.map((client) => ( |
57 | | - <TabsTrigger key={client.id} value={client.id}> |
58 | | - {client.label} |
59 | | - </TabsTrigger> |
60 | | - ))} |
61 | | - </TabsList> |
62 | | - {MCP_CLIENTS.map((client) => { |
63 | | - const config = client.buildConfig(resolved); |
64 | | - return ( |
65 | | - <TabsContent key={client.id} value={client.id} className="space-y-3"> |
66 | | - <ol className="list-decimal space-y-1 pl-5 text-sm leading-relaxed text-muted-foreground"> |
67 | | - {client.steps.map((step) => ( |
68 | | - <li key={step}>{step}</li> |
69 | | - ))} |
70 | | - </ol> |
71 | | - <div> |
72 | | - <p className="mb-1.5 font-mono text-xs text-muted-foreground">{client.configFile}</p> |
73 | | - <div className="relative"> |
74 | | - <CopyButton text={config} /> |
75 | | - <pre className="overflow-x-auto rounded-lg border bg-muted/50 p-4 font-mono text-xs leading-relaxed"> |
76 | | - <code>{config}</code> |
77 | | - </pre> |
| 67 | + <div className="space-y-4"> |
| 68 | + <div className="flex flex-wrap items-center gap-3"> |
| 69 | + <div className="inline-flex rounded-lg border bg-muted/40 p-0.5"> |
| 70 | + {TRANSPORTS.map((t) => ( |
| 71 | + <Button |
| 72 | + key={t.id} |
| 73 | + variant={t.id === transport ? "secondary" : "ghost"} |
| 74 | + size="sm" |
| 75 | + className="h-7 px-3 text-xs" |
| 76 | + onClick={() => setTransport(t.id)} |
| 77 | + aria-pressed={t.id === transport} |
| 78 | + > |
| 79 | + {t.label} |
| 80 | + </Button> |
| 81 | + ))} |
| 82 | + </div> |
| 83 | + <span className="text-xs text-muted-foreground">{active.hint}</span> |
| 84 | + </div> |
| 85 | + |
| 86 | + <Tabs defaultValue={MCP_CLIENTS[0].id} className="w-full"> |
| 87 | + <TabsList className="flex h-auto flex-wrap justify-start gap-1"> |
| 88 | + {MCP_CLIENTS.map((client) => ( |
| 89 | + <TabsTrigger key={client.id} value={client.id}> |
| 90 | + {client.label} |
| 91 | + </TabsTrigger> |
| 92 | + ))} |
| 93 | + </TabsList> |
| 94 | + {MCP_CLIENTS.map((client) => { |
| 95 | + const snippet = client[transport]; |
| 96 | + const config = snippet.build(resolved); |
| 97 | + return ( |
| 98 | + <TabsContent key={client.id} value={client.id} className="space-y-3"> |
| 99 | + <ol className="list-decimal space-y-1 pl-5 text-sm leading-relaxed text-muted-foreground"> |
| 100 | + {snippet.steps.map((step) => ( |
| 101 | + <li key={step}>{step}</li> |
| 102 | + ))} |
| 103 | + </ol> |
| 104 | + <div> |
| 105 | + <p className="mb-1.5 font-mono text-xs text-muted-foreground"> |
| 106 | + {snippet.configFile} |
| 107 | + </p> |
| 108 | + <div className="relative"> |
| 109 | + <CopyButton text={config} /> |
| 110 | + <pre className="overflow-x-auto rounded-lg border bg-muted/50 p-4 font-mono text-xs leading-relaxed"> |
| 111 | + <code>{config}</code> |
| 112 | + </pre> |
| 113 | + </div> |
78 | 114 | </div> |
79 | | - </div> |
80 | | - </TabsContent> |
81 | | - ); |
82 | | - })} |
83 | | - </Tabs> |
| 115 | + </TabsContent> |
| 116 | + ); |
| 117 | + })} |
| 118 | + </Tabs> |
| 119 | + </div> |
84 | 120 | ); |
85 | 121 | } |
0 commit comments