import { Check, Copy } from 'lucide-react' import { useEffect, useState } from 'react' import { cn } from '@/lib/utils' import { useOAuthGrants, type OAuthGrant, } from '@/registry/default/blocks/headless-app-tanstack/hooks/use-oauth-grants' import { Button } from '@/registry/default/components/ui/button' const buildPrompt = (productName: string, mcpServerUrl: string) => `Connect to ${productName} using this MCP server:\n\n${mcpServerUrl}\n\nUse your MCP connection setup to authorize access in my browser. Then call whoami to verify the connection and list the available tools.` const formatDate = (value: string) => new Date(value).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' }) function ConnectAgent({ productName, mcpServerUrl, }: { productName: string mcpServerUrl: string }) { const [copied, setCopied] = useState<'url' | 'prompt' | null>(null) const [error, setError] = useState(null) useEffect(() => { if (!copied) return const timeout = window.setTimeout(() => setCopied(null), 2000) return () => window.clearTimeout(timeout) }, [copied]) const copy = async (type: 'url' | 'prompt') => { setError(null) try { await navigator.clipboard.writeText( type === 'url' ? mcpServerUrl : buildPrompt(productName, mcpServerUrl) ) setCopied(type) } catch { setCopied(null) setError('Unable to copy. Select and copy the server URL above.') } } return (

Connect an agent

Add this server URL in your agent’s MCP settings, then sign in and approve access.

          {mcpServerUrl}
        

Use the prompt if your agent supports adding MCP servers through chat.

{/* Always mounted so screen readers announce the change. */} {copied ? 'Copied to clipboard' : ''} {error && (

{error}

)}
) } function GrantRow({ grant, isRevoking, disabled, onRevoke, }: { grant: OAuthGrant isRevoking: boolean disabled: boolean onRevoke: () => void }) { return (
  • {grant.client.name} Authorized {formatDate(grant.granted_at)} {grant.scopes.length > 0 && ` · ${grant.scopes.join(', ')}`}
  • ) } export interface ConnectedAgentsViewProps extends React.ComponentPropsWithoutRef<'div'> { mcpServerUrl: string productName?: string grants?: OAuthGrant[] | null isLoading?: boolean error?: string | null revokingClientId?: string | null onRefresh?: () => void onRevoke?: (clientId: string) => void } export function ConnectedAgentsView({ mcpServerUrl, productName = 'this app', grants = null, isLoading = false, error = null, revokingClientId = null, onRefresh, onRevoke, className, ...props }: ConnectedAgentsViewProps) { return (

    Connected agents

    Authorize agents to use {productName} on your behalf.

    Authorized agents

    {onRefresh && ( )}
    {/* Always mounted so screen readers announce the change. */}

    {isLoading ? 'Loading connected agents...' : ''}

    {grants && grants.length > 0 && (
      {grants.map((grant) => ( onRevoke?.(grant.client.id)} /> ))}
    )} {!isLoading && !error && grants?.length === 0 && (

    No agents authorized yet. Connect an agent using the server URL above.

    )} {error && (

    {error}

    )} {grants && grants.length > 0 && (

    Revoking access prevents an agent from renewing its session. Its current access token may work until it expires.

    )}
    ) } interface ConnectedAgentsProps extends React.ComponentPropsWithoutRef<'div'> { mcpServerUrl: string productName?: string } export function ConnectedAgents(props: ConnectedAgentsProps) { const { grants, error, isLoading, revokingClientId, refresh, revoke } = useOAuthGrants() return ( void refresh()} onRevoke={(clientId) => void revoke(clientId)} {...props} /> ) }