MCP server card
An MCP server as a card: its address, the scopes it asks for, and whether this client is connected.
For a product that lets its users connect MCP servers. The card reads the protected resource metadata of the server: its address, the authorization server that it trusts, and its scopes.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/mcp-server-card.json
npx shadcn@latest add https://examples.lumoauth.dev/r/mcp-server-card.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/mcp-server-card.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/mcp-server-card.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge button cardInstall the packages.
npm install lucide-reactCopy the code into your project.
components/mcp-server-card.tsx'use client';import * as React from 'react';import { KeyRound, Loader2, Plug, ServerCog, ShieldCheck, Unplug } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';import { cn } from '@/lib/utils';export type McpConnectionState = 'disconnected' | 'connecting' | 'connected' | 'needs_scope';export interface McpServerData {name: string;/** The address that clients connect to. A token for it works at no other address. */resource: string;/** The authorization servers that the server trusts. */authorizationServers?: string[];scopes?: string[];/** True when the server accepts only tokens that are bound to a key (DPoP). */dpopRequired?: boolean;}/*** Maps the protected resource metadata of an MCP server (RFC 9728), the* document at `/.well-known/oauth-protected-resource`.*/export function fromProtectedResourceMetadata(doc: Record<string, any>): McpServerData {return {name: doc.resource_name ?? new URL(doc.resource).hostname,resource: doc.resource,authorizationServers: Array.isArray(doc.authorization_servers) ? doc.authorization_servers : [],scopes: Array.isArray(doc.scopes_supported) ? doc.scopes_supported : [],dpopRequired: doc.dpop_bound_access_tokens_required === true,};}export interface McpServerCardProps {server: McpServerData;state: McpConnectionState;/** The scopes that this client holds now. They are marked in the list. */grantedScopes?: string[];/** The scopes that the server asked for with an `insufficient_scope` challenge. */missingScopes?: string[];/** Start the authorization flow. With `missingScopes`, ask for those. */onConnect?: () => void;onDisconnect?: () => void;className?: string;}export function McpServerCard({ server, state, grantedScopes = [], missingScopes = [], onConnect, onDisconnect, className }: McpServerCardProps) {const host = (url: string) => {try {return new URL(url).host;} catch {return url;}};return (<Card className={cn('w-full max-w-md gap-4', className)}><CardHeader><div className="flex items-start justify-between gap-3"><div className="flex min-w-0 items-center gap-3"><span className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted"><ServerCog className="size-4" aria-hidden="true" /></span><div className="grid min-w-0 gap-0.5"><CardTitle className="truncate text-base">{server.name}</CardTitle><CardDescription className="truncate font-mono text-xs">{server.resource}</CardDescription></div></div>{state === 'connected' && <Badge className="border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-400">Connected</Badge>}{state === 'needs_scope' && <Badge className="border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-400">More access needed</Badge>}</div></CardHeader><CardContent className="grid gap-3 text-sm">{server.authorizationServers && server.authorizationServers.length > 0 && (<p className="flex items-center gap-2 text-muted-foreground"><ShieldCheck className="size-4 shrink-0" aria-hidden="true" /><span className="min-w-0 truncate">Sign-in through <span className="font-medium text-foreground">{server.authorizationServers.map(host).join(', ')}</span></span></p>)}{server.dpopRequired && (<p className="flex items-center gap-2 text-muted-foreground"><KeyRound className="size-4 shrink-0" aria-hidden="true" />Accepts only tokens that are bound to a key of the client</p>)}{server.scopes && server.scopes.length > 0 && (<div className="grid gap-1.5"><p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">Scopes</p><div className="flex flex-wrap gap-1">{server.scopes.map((scope) => {const missing = missingScopes.includes(scope);const granted = grantedScopes.includes(scope);return (<Badgekey={scope}variant={granted ? 'secondary' : 'outline'}className={cn('font-mono font-normal', missing && 'border-amber-500/60 text-amber-700 dark:text-amber-400', !granted && !missing && 'text-muted-foreground')}>{scope}</Badge>);})}</div>{state === 'needs_scope' && missingScopes.length > 0 && (<p className="text-amber-700 dark:text-amber-400">The tool that you called needs {missingScopes.length === 1 ? 'one more scope' : 'more scopes'}: {missingScopes.join(', ')}.</p>)}</div>)}</CardContent><CardFooter className="gap-2">{state === 'disconnected' && (<Button onClick={onConnect}><Plug aria-hidden="true" />Connect</Button>)}{state === 'connecting' && (<Button disabled><Loader2 className="animate-spin" aria-hidden="true" />Waiting for sign-in…</Button>)}{state === 'needs_scope' && (<Button onClick={onConnect}><Plug aria-hidden="true" />Give access</Button>)}{(state === 'connected' || state === 'needs_scope') && (<Button variant="outline" onClick={onDisconnect}><Unplug aria-hidden="true" />Disconnect</Button>)}</CardFooter></Card>);}Change the import paths if your project keeps its components in another place.
Usage
fromProtectedResourceMetadata maps the metadata document of the server. Your MCP client owns the connection state.
'use client';
import { McpServerCard, fromProtectedResourceMetadata, type McpConnectionState } from '@/components/mcp-server-card';
export function Server({ metadata, state, granted, missing, connect, disconnect }: {
metadata: Record<string, unknown>; // the document at /.well-known/oauth-protected-resource
state: McpConnectionState;
granted: string[];
missing: string[]; // from an insufficient_scope challenge
connect: () => void; // starts the authorization flow of your MCP client
disconnect: () => void;
}) {
return (
<McpServerCard
server={fromProtectedResourceMetadata(metadata)}
state={state}
grantedScopes={granted}
missingScopes={missing}
onConnect={connect}
onDisconnect={disconnect}
/>
);
}
When a tool call answers 403 insufficient_scope, set the state to needs_scope and pass the scopes of the challenge as missingScopes. "Give access" then starts the flow again for those scopes only.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| Address, authorization server and scopes | The document at /.well-known/oauth-protected-resource of the MCP server (RFC 9728) |
| Where to find that document | The resource_metadata address in the WWW-Authenticate header of a 401 answer |
| The servers of your own organization | GET /mcp/servers |
| More scope | The scope of an insufficient_scope challenge |
States
- More access needed. The missing scope is marked, and the card says what the tool needs.
- Connecting, for a server that accepts only tokens that are bound to a key.
Props
| Prop | Type | Description |
|---|---|---|
serverrequired | McpServerData | The server: name, resource, authorizationServers, scopes and dpopRequired. |
staterequired | 'disconnected' | 'connecting' | 'connected' | 'needs_scope' | The state of the connection. |
grantedScopes | string[] | The scopes that this client holds now. |
missingScopes | string[] | The scopes that the server asked for with an insufficient_scope challenge. |
onConnect | () => void | Start the authorization flow. |
onDisconnect | () => void | Drop the connection. |
className | string | Class name for the card. |