Skip to content

Commit 8c82613

Browse files
committed
Streamline server "Connect" details
1 parent b9c0262 commit 8c82613

4 files changed

Lines changed: 108 additions & 19 deletions

File tree

src/app/[serverId]/client.tsx

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { Plus } from "lucide-react"
3+
import { Plus, Plug } from "lucide-react"
44
import { z } from "zod"
55
import { zodResolver } from "@hookform/resolvers/zod"
66
import { useForm } from "react-hook-form"
@@ -34,6 +34,8 @@ import { useState } from "react"
3434
import { Database } from "../../../database.types"
3535
import { createClient } from "@/lib/supabase/client"
3636
import { useRouter } from "next/navigation"
37+
import { CodeBlock } from "@/components/code-block"
38+
import { getServerUrl } from "@/lib/get-server-url"
3739

3840
type ToolsRow = Database["public"]["Tables"]["tools"]["Row"]
3941
type ParametersRow = Database["public"]["Tables"]["parameters"]["Row"]
@@ -434,3 +436,92 @@ export function ParameterForm({
434436
</Dialog>
435437
)
436438
}
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+
}

src/app/[serverId]/page.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { ChevronLeft } from "lucide-react"
22
import Link from "next/link"
3-
import { notFound } from "next/navigation"
3+
import { notFound, redirect } from "next/navigation"
44

5-
import { CodeBlock } from "@/components/code-block"
65
import { Button } from "@/components/ui/button"
7-
import { getServerUrl } from "@/lib/get-server-url"
86
import { createClient } from "@/lib/supabase/server"
9-
import { ToolSection } from "@/app/[serverId]/client"
7+
import { ToolSection, ConnectButton } from "@/app/[serverId]/client"
108

119
export default async function ServerPage({
1210
params,
@@ -17,6 +15,14 @@ export default async function ServerPage({
1715

1816
const { serverId } = await params
1917

18+
// Get user session for access token
19+
const $session = await client.auth.getSession()
20+
const accessToken = $session.data.session?.access_token
21+
22+
if (!accessToken) {
23+
redirect("/auth/login")
24+
}
25+
2026
const $server = await client
2127
.from("servers")
2228
.select("*, tools(*, parameters(*))")
@@ -43,11 +49,12 @@ export default async function ServerPage({
4349
</Button>
4450
</div>
4551

46-
<h1 className="text-2xl font-bold mb-10 grow">{server.name}</h1>
52+
<div className="flex items-center justify-between mb-10">
53+
<h1 className="text-2xl font-bold grow">{server.name}</h1>
54+
<ConnectButton serverId={server.id} accessToken={accessToken} />
55+
</div>
4756
</header>
4857

49-
<CodeBlock label="URL" code={getServerUrl(server.id)} />
50-
5158
<ToolSection serverId={server.id} tools={server.tools} />
5259
</div>
5360
)

src/app/client.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"use client"
2-
import { Link as LinkIcon, Plus } from "lucide-react"
2+
import { Plus } from "lucide-react"
33
import Link from "next/link"
44
import { useRouter } from "next/navigation"
55

6-
import { CopyButton } from "@/components/copy-button"
76
import { Button } from "@/components/ui/button"
8-
import { getServerUrl } from "@/lib/get-server-url"
7+
98
import { createClient } from "@/lib/supabase/client"
109
import { Database } from "../../database.types"
1110

@@ -26,12 +25,6 @@ export function ServerCard({
2625
<div className="bg-card border rounded-md px-6 py-6 flex items-center">
2726
<span className="grow">{server.name}</span>
2827
<div className="flex items-center gap-2">
29-
<CopyButton
30-
label="Copy URL"
31-
variant="outline"
32-
defaultIcon={<LinkIcon />}
33-
text={getServerUrl(server.id)}
34-
/>
3528
<Button variant="outline" asChild>
3629
<Link href={`/${server.id}`}>Edit</Link>
3730
</Button>

src/components/navbar.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Image from "next/image"
44
import { createClient } from "@/lib/supabase/server"
55
import { cn } from "@/lib/utils"
66
import z from "zod"
7-
import { CopyToken } from "@/components/copy-token"
87

98
const ClaimsSchema = z.object({
109
email: z.string().email(),
@@ -42,7 +41,6 @@ export async function Navbar({ className }: { className?: string }) {
4241

4342
{userData && (
4443
<div className="flex gap-6 items-center">
45-
<CopyToken token={userData.accessToken} />
4644
<span className="text-muted-foreground text-sm">
4745
{userData.email}
4846
</span>

0 commit comments

Comments
 (0)