|
1 | 1 | "use client" |
2 | 2 |
|
3 | | -import { Plus } from "lucide-react" |
| 3 | +import { Plus, Plug } from "lucide-react" |
4 | 4 | import { z } from "zod" |
5 | 5 | import { zodResolver } from "@hookform/resolvers/zod" |
6 | 6 | import { useForm } from "react-hook-form" |
@@ -34,6 +34,8 @@ import { useState } from "react" |
34 | 34 | import { Database } from "../../../database.types" |
35 | 35 | import { createClient } from "@/lib/supabase/client" |
36 | 36 | import { useRouter } from "next/navigation" |
| 37 | +import { CodeBlock } from "@/components/code-block" |
| 38 | +import { getServerUrl } from "@/lib/get-server-url" |
37 | 39 |
|
38 | 40 | type ToolsRow = Database["public"]["Tables"]["tools"]["Row"] |
39 | 41 | type ParametersRow = Database["public"]["Tables"]["parameters"]["Row"] |
@@ -434,3 +436,92 @@ export function ParameterForm({ |
434 | 436 | </Dialog> |
435 | 437 | ) |
436 | 438 | } |
| 439 | + |
| 440 | +export function ConnectButton({ |
| 441 | + serverId, |
| 442 | + accessToken, |
| 443 | +}: { |
| 444 | + serverId: string |
| 445 | + accessToken: string |
| 446 | +}) { |
| 447 | + const [open, setOpen] = useState(false) |
| 448 | + |
| 449 | + return ( |
| 450 | + <> |
| 451 | + <Button |
| 452 | + onClick={() => setOpen(true)} |
| 453 | + className="flex items-center gap-2" |
| 454 | + variant="outline" |
| 455 | + > |
| 456 | + <Plug className="h-4 w-4" /> |
| 457 | + Connect |
| 458 | + </Button> |
| 459 | + <ConnectDialog |
| 460 | + serverId={serverId} |
| 461 | + accessToken={accessToken} |
| 462 | + open={open} |
| 463 | + onOpenChange={setOpen} |
| 464 | + /> |
| 465 | + </> |
| 466 | + ) |
| 467 | +} |
| 468 | + |
| 469 | +export function ConnectDialog({ |
| 470 | + serverId, |
| 471 | + accessToken, |
| 472 | + open, |
| 473 | + onOpenChange, |
| 474 | +}: { |
| 475 | + serverId: string |
| 476 | + accessToken: string |
| 477 | + open: boolean |
| 478 | + onOpenChange: (open: boolean) => void |
| 479 | +}) { |
| 480 | + const serverUrl = getServerUrl(serverId) |
| 481 | + |
| 482 | + return ( |
| 483 | + <Dialog open={open} onOpenChange={onOpenChange}> |
| 484 | + <DialogContent className="max-w-2xl"> |
| 485 | + <DialogHeader> |
| 486 | + <DialogTitle className="flex items-center gap-2"> |
| 487 | + <Plug className="h-5 w-5" /> |
| 488 | + Connect to Server |
| 489 | + </DialogTitle> |
| 490 | + <DialogDescription> |
| 491 | + Use these credentials to connect your MCP client to this server. |
| 492 | + </DialogDescription> |
| 493 | + </DialogHeader> |
| 494 | + |
| 495 | + <div className="grid gap-6"> |
| 496 | + <div className="min-w-0"> |
| 497 | + <h4 className="text-sm font-medium mb-2">Server URL</h4> |
| 498 | + <CodeBlock className="min-w-0" code={serverUrl} /> |
| 499 | + </div> |
| 500 | + |
| 501 | + <div className="min-w-0"> |
| 502 | + <h4 className="text-sm font-medium mb-2">Bearer Token</h4> |
| 503 | + <CodeBlock className="min-w-0" code={accessToken} /> |
| 504 | + </div> |
| 505 | + |
| 506 | + <div className="bg-card rounded-lg p-4"> |
| 507 | + <h4 className="text-sm font-medium mb-2"> |
| 508 | + Connection Instructions |
| 509 | + </h4> |
| 510 | + <div className="text-sm text-muted-foreground space-y-2"> |
| 511 | + <p>In your MCP client (e.g. Cursor, Claude Code, VS Code):</p> |
| 512 | + <p>1. Copy the URL and set it as the remote server URL</p> |
| 513 | + <p>{`2. Copy the token and add it an "Authorization" header with the value "Bearer <TOKEN>"`}</p> |
| 514 | + <p> |
| 515 | + 3. Connect to the server and try using your configured tools! |
| 516 | + </p> |
| 517 | + <p className="text-xs italic mt-3"> |
| 518 | + Note: Tokens expire after 1 week, so you may need to copy it |
| 519 | + again later |
| 520 | + </p> |
| 521 | + </div> |
| 522 | + </div> |
| 523 | + </div> |
| 524 | + </DialogContent> |
| 525 | + </Dialog> |
| 526 | + ) |
| 527 | +} |
0 commit comments