{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-ops-04",
  "title": "MCP servers",
  "description": "The servers an agent can reach, each unfolding its tools with Enabled and Ask first switches: Reconnect becomes a spinner then Connected, and the Add server dialog resizes from Testing to Failed with the reason, then to Connected with its tools.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/inline-sheet.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/spinner.json",
    "https://ui.ndekocode.dev/r/status-orb.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-04/index.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  pressedSolidOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { PlusIcon } from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { AddServerDialog } from './add-server-dialog';\nimport { AGENT_NAME } from './data';\nimport { ServerRow } from './server-row';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  RECONNECT_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  SETTLE_MS,\n  TEST_MS,\n  type McpState,\n  type ServerLive,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\ntype Reach = {\n  connected: number;\n  toolsOn: number;\n  askFirst: number;\n};\n\nfunction isConnected(live: ServerLive) {\n  const isSteady = live.status === 'connected';\n  const isRestored = live.status === 'restored';\n  return isSteady || isRestored;\n}\n\n/** Only the tools of connected servers count: the agent cannot call the others. */\nfunction reachOf(state: McpState): Reach {\n  const reach: Reach = { connected: 0, toolsOn: 0, askFirst: 0 };\n  for (const server of state.servers) {\n    const live = state.live[server.id];\n    if (!isConnected(live)) {\n      continue;\n    }\n    reach.connected += 1;\n    for (const setting of Object.values(live.tools)) {\n      if (!setting.isEnabled) {\n        continue;\n      }\n      reach.toolsOn += 1;\n      if (setting.asksFirst) {\n        reach.askFirst += 1;\n      }\n    }\n  }\n  return reach;\n}\n\nfunction reachLineOf(reach: Reach, total: number) {\n  const servers = countOf(total, 'server');\n  const tools = countOf(reach.toolsOn, 'tool');\n  return `${reach.connected} of ${servers} connected, ${tools} on, ${reach.askFirst} ask first`;\n}\n\ntype ReachFigureProps = {\n  label: string;\n  value: number;\n  suffix?: string;\n};\n\nfunction ReachFigure({ label, value, suffix }: ReachFigureProps) {\n  return (\n    <div className='flex min-w-0 flex-col gap-0.5'>\n      <dt className='text-muted-foreground text-xs'>{label}</dt>\n      <dd className='flex items-baseline gap-1.5'>\n        <MotionNumber\n          value={value}\n          className='text-2xl leading-8 font-semibold'\n        />\n        {suffix && (\n          <span className='text-muted-foreground text-xs tabular-nums'>\n            {suffix}\n          </span>\n        )}\n      </dd>\n    </div>\n  );\n}\n\nexport default function AgentOps04() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule } = useTimeouts();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const reach = reachOf(state);\n  const serverCount = state.servers.length;\n  const isEmpty = serverCount === 0;\n  const reachLine = reachLineOf(reach, serverCount);\n  const message = spokenUnless(isAutoplaying, reachLine);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function reconnect(id: string) {\n    act({ type: 'reconnect', id });\n    schedule(() => act({ type: 'reconnected', id }), RECONNECT_MS);\n    schedule(() => act({ type: 'settled', id }), RECONNECT_MS + SETTLE_MS);\n  }\n\n  function test() {\n    act({ type: 'test' });\n    schedule(() => act({ type: 'tested' }), TEST_MS);\n  }\n\n  function openDialog() {\n    act({ type: 'dialogOpened' });\n    focusLater('[data-dialog-first]');\n  }\n\n  function closeDialog() {\n    act({ type: 'dialogClosed' });\n    focusLater('[data-add-server]');\n  }\n\n  function addServer() {\n    act({ type: 'added' });\n    focusLater('[data-add-server]');\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container relative h-dvh min-h-[40rem] w-full overflow-hidden'\n      >\n        <div inert={state.dialog.isOpen} className='h-full overflow-y-auto'>\n          <div className='mx-auto flex max-w-3xl flex-col gap-5 p-4 @3xl:p-8'>\n            <header className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n              <BrandTile brand='mcp' size='lg' />\n              <div className='flex min-w-40 flex-1 flex-col leading-tight'>\n                <h1 className='text-lg font-semibold text-balance'>\n                  MCP servers\n                </h1>\n                <p className='text-muted-foreground text-xs'>\n                  What the {AGENT_NAME} can reach\n                </p>\n              </div>\n              <ReplayButton\n                isShown={canReplay}\n                onReplay={restart}\n                label='Replay the setup'\n              />\n              <Button\n                type='button'\n                data-add-server\n                onClick={openDialog}\n                className={pressedSolidOf(pressed === 'add')}\n              >\n                <PlusIcon />\n                Add server\n              </Button>\n            </header>\n\n            <dl className='grid grid-cols-3 gap-3'>\n              <ReachFigure\n                label='Connected'\n                value={reach.connected}\n                suffix={`of ${serverCount}`}\n              />\n              <ReachFigure label='Tools on' value={reach.toolsOn} />\n              <ReachFigure label='Ask first' value={reach.askFirst} />\n            </dl>\n\n            <section\n              aria-label='Servers'\n              className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex flex-col rounded-xl p-1 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n            >\n              <ul className='flex flex-col'>\n                <AnimatePresence initial={false}>\n                  {state.servers.map((server) => (\n                    <motion.li\n                      key={server.id}\n                      className='overflow-hidden'\n                      {...rowPresence}\n                    >\n                      <ServerRow\n                        server={server}\n                        live={state.live[server.id]}\n                        isOpen={state.openId === server.id}\n                        isRemoving={state.removingId === server.id}\n                        pressed={pressed}\n                        onAction={act}\n                        onReconnect={reconnect}\n                      />\n                    </motion.li>\n                  ))}\n                </AnimatePresence>\n              </ul>\n              {isEmpty && (\n                <div className='flex flex-col items-start gap-3 p-3 transition-opacity duration-300 starting:opacity-0'>\n                  <p className='text-muted-foreground text-[13px]'>\n                    No server is connected, so the agent has no tools. Add one\n                    to give it something to work with.\n                  </p>\n                  <Button\n                    type='button'\n                    variant='outline'\n                    size='sm'\n                    onClick={openDialog}\n                  >\n                    <PlusIcon />\n                    Add server\n                  </Button>\n                </div>\n              )}\n            </section>\n\n            <Badge variant='secondary' className='self-start'>\n              Illustrative tool lists\n            </Badge>\n          </div>\n        </div>\n\n        <AddServerDialog\n          dialog={state.dialog}\n          pressed={pressed}\n          onAction={act}\n          onTest={test}\n          onAdd={addServer}\n          onClose={closeDialog}\n        />\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-04/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-04/server-row.tsx",
      "content": "'use client';\n\nimport { useId } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { WordRoll } from '@/components/core/word-roll';\nimport { ChevronDownIcon, Trash2Icon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport { StatusOrb, type StatusOrbTone } from '@/registry/ndeko/ui/status-orb';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nimport { TRANSPORT_WORD, type Access, type Server, type Tool } from './data';\nimport {\n  enabledCountOf,\n  type ConnectionStatus,\n  type McpAction,\n  type ServerLive,\n  type ToolSetting,\n} from './session';\n\nconst STATUS_WORD: Record<ConnectionStatus, string> = {\n  connected: 'Connected',\n  expired: 'Token expired',\n  reconnecting: 'Reconnecting',\n  restored: 'Connected',\n};\n\nconst STATUS_WORDS = ['Connected', 'Token expired', 'Reconnecting'];\n\nconst ORB_TONE: Record<ConnectionStatus, StatusOrbTone> = {\n  connected: 'success',\n  expired: 'error',\n  reconnecting: 'loading',\n  restored: 'success',\n};\n\nconst WORD_TONE: Record<ConnectionStatus, string> = {\n  connected: 'text-muted-foreground',\n  expired: 'text-destructive-ink',\n  reconnecting: 'text-muted-foreground',\n  restored: 'text-muted-foreground',\n};\n\nconst REASON_TONE: Record<ConnectionStatus, string> = {\n  connected: 'text-foreground',\n  expired: 'text-destructive-ink',\n  reconnecting: 'text-foreground',\n  restored: 'text-foreground',\n};\n\nconst RECONNECT_STATE: Record<ConnectionStatus, MorphState> = {\n  connected: 'done',\n  expired: 'idle',\n  reconnecting: 'busy',\n  restored: 'done',\n};\n\nconst RECONNECT_LABELS: Record<MorphState, string> = {\n  idle: 'Reconnect',\n  busy: 'Reconnecting',\n  done: 'Connected',\n};\n\nconst REASON_LINE: Record<ConnectionStatus, string> = {\n  connected: 'Signed in. The tools are back',\n  expired: 'The agent cannot use these tools until you sign in again',\n  reconnecting: 'Asking for a new token',\n  restored: 'Signed in. The tools are back',\n};\n\nconst ACCESS_WORD: Record<Access, string> = { read: 'Read', write: 'Write' };\n\nconst ACCESS_COLOR: Record<Access, string> = {\n  read: 'var(--muted-foreground)',\n  write: 'var(--warning)',\n};\n\nfunction toolsWordOf(count: number) {\n  if (count === 1) {\n    return 'tool on';\n  }\n  return 'tools on';\n}\n\nfunction lostToolsOf(count: number) {\n  if (count === 1) {\n    return 'its tool';\n  }\n  return `its ${count} tools`;\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\nfunction pressedQuietOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.94] bg-foreground/[0.07] text-foreground';\n  }\n  return undefined;\n}\n\nfunction toggleLabelOf(server: Server, isOpen: boolean) {\n  if (isOpen) {\n    return `Hide the tools of ${server.name}`;\n  }\n  return `Show the tools of ${server.name}`;\n}\n\nfunction removeVariantOf(isRemoving: boolean) {\n  if (isRemoving) {\n    return 'destructive';\n  }\n  return 'ghost';\n}\n\nfunction removeLabelOf(server: Server, isRemoving: boolean) {\n  if (isRemoving) {\n    return `Remove ${server.name}`;\n  }\n  return 'Remove server';\n}\n\nfunction ServerTile({ server }: { server: Server }) {\n  if (server.brand) {\n    return <BrandTile brand={server.brand} size='lg' />;\n  }\n  return <MeshTile seed={server.name} size='lg' />;\n}\n\ntype ToolRowProps = {\n  serverId: string;\n  tool: Tool;\n  setting: ToolSetting;\n  onAction: (action: McpAction) => void;\n};\n\nfunction ToolRow({ serverId, tool, setting, onAction }: ToolRowProps) {\n  function setEnabled(isEnabled: boolean) {\n    onAction({ type: 'toolEnabled', id: serverId, tool: tool.name, isEnabled });\n  }\n\n  function setAsksFirst(asksFirst: boolean) {\n    onAction({ type: 'toolAsks', id: serverId, tool: tool.name, asksFirst });\n  }\n\n  return (\n    <li className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col gap-2 rounded-lg px-2.5 py-2 @xl:flex-row @xl:items-center @xl:gap-4'>\n      <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n        <p className='flex flex-wrap items-center gap-2'>\n          <code className='font-mono text-xs'>{tool.name}</code>\n          <Chip color={ACCESS_COLOR[tool.access]}>\n            {ACCESS_WORD[tool.access]}\n          </Chip>\n        </p>\n        <p className='text-muted-foreground text-xs'>{tool.summary}</p>\n      </div>\n      <div className='flex shrink-0 items-center gap-4'>\n        <label className='flex cursor-pointer items-center gap-2 text-xs'>\n          <Switch\n            checked={setting.isEnabled}\n            onCheckedChange={setEnabled}\n            aria-label={`Let the agent use ${tool.name}`}\n          />\n          Enabled\n        </label>\n        <label\n          className={cn(\n            'flex cursor-pointer items-center gap-2 text-xs transition-opacity duration-200',\n            !setting.isEnabled && 'cursor-not-allowed opacity-50'\n          )}\n        >\n          <Switch\n            checked={setting.asksFirst}\n            disabled={!setting.isEnabled}\n            onCheckedChange={setAsksFirst}\n            aria-label={`Ask first before ${tool.name}`}\n          />\n          Ask first\n        </label>\n      </div>\n    </li>\n  );\n}\n\nexport type ServerRowProps = {\n  server: Server;\n  live: ServerLive;\n  isOpen: boolean;\n  isRemoving: boolean;\n  pressed: string | null;\n  onAction: (action: McpAction) => void;\n  onReconnect: (id: string) => void;\n};\n\nexport function ServerRow({\n  server,\n  live,\n  isOpen,\n  isRemoving,\n  pressed,\n  onAction,\n  onReconnect,\n}: ServerRowProps) {\n  const panelId = useId();\n  const enabledCount = enabledCountOf(live);\n  const toolCount = server.tools.length;\n  const needsAttention = live.status !== 'connected';\n  const removeLabel = removeLabelOf(server, isRemoving);\n\n  function removeStep() {\n    if (isRemoving) {\n      onAction({ type: 'removed', id: server.id });\n      return;\n    }\n    onAction({ type: 'removeAsked', id: server.id });\n  }\n\n  return (\n    <div className='flex flex-col px-2 py-2.5'>\n      <div className='flex items-center gap-3'>\n        <ServerTile server={server} />\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <p className='flex flex-wrap items-center gap-x-2 gap-y-0.5'>\n            <span className='text-[13px] leading-5 font-medium'>\n              {server.name}\n            </span>\n            <Badge variant='secondary'>\n              {TRANSPORT_WORD[server.transport]}\n            </Badge>\n          </p>\n          <p className='text-muted-foreground flex min-w-0 items-center gap-1 text-xs'>\n            <MotionNumber value={enabledCount} />\n            <span className='shrink-0'>\n              of {toolCount} {toolsWordOf(toolCount)}\n            </span>\n            {server.address && (\n              <code className='min-w-0 truncate ps-1 font-mono'>\n                {server.address}\n              </code>\n            )}\n          </p>\n        </div>\n        <div className='flex shrink-0 items-center gap-2'>\n          <span\n            className={cn(\n              'hidden text-xs transition-colors duration-200 @md:block',\n              WORD_TONE[live.status]\n            )}\n          >\n            <WordRoll text={STATUS_WORD[live.status]} labels={STATUS_WORDS} />\n          </span>\n          <StatusOrb tone={ORB_TONE[live.status]} size='sm' />\n          <span className='sr-only @md:hidden'>{STATUS_WORD[live.status]}</span>\n        </div>\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon-sm'\n          aria-expanded={isOpen}\n          aria-controls={panelId}\n          aria-label={toggleLabelOf(server, isOpen)}\n          onClick={() => onAction({ type: 'toggled', id: server.id })}\n          className={cn(\n            'text-muted-foreground',\n            pressedQuietOf(pressed === `toggle-${server.id}`)\n          )}\n        >\n          <ChevronDownIcon\n            className={cn(\n              'transition-transform duration-200 ease-(--ease-out-strong)',\n              chevronTurnOf(isOpen)\n            )}\n          />\n        </Button>\n      </div>\n\n      <Fold open={needsAttention} className='ps-10'>\n        <div className='flex flex-wrap items-center gap-x-3 gap-y-2 pt-2'>\n          <p className='min-w-0 flex-1 text-xs'>\n            <span\n              className={cn(\n                'font-medium transition-colors duration-200 @md:hidden',\n                REASON_TONE[live.status]\n              )}\n            >\n              {STATUS_WORD[live.status]}.{' '}\n            </span>\n            <span className='text-muted-foreground'>\n              <Swap swapKey={live.status}>{REASON_LINE[live.status]}</Swap>\n            </span>\n          </p>\n          <MorphButton\n            type='button'\n            size='sm'\n            variant='outline'\n            state={RECONNECT_STATE[live.status]}\n            labels={RECONNECT_LABELS}\n            onClick={() => onReconnect(server.id)}\n            className={pressedQuietOf(pressed === `reconnect-${server.id}`)}\n          />\n        </div>\n      </Fold>\n\n      <Fold open={isOpen} id={panelId} className='ps-10'>\n        <ul\n          aria-label={`Tools of ${server.name}`}\n          className='flex flex-col gap-1 pt-2'\n        >\n          {server.tools.map((tool) => (\n            <ToolRow\n              key={tool.name}\n              serverId={server.id}\n              tool={tool}\n              setting={live.tools[tool.name]}\n              onAction={onAction}\n            />\n          ))}\n        </ul>\n        <div className='flex flex-wrap items-center gap-x-3 gap-y-2 pt-2'>\n          <Button\n            type='button'\n            size='sm'\n            variant={removeVariantOf(isRemoving)}\n            onClick={removeStep}\n            className={cn(!isRemoving && 'text-destructive-ink')}\n          >\n            <Trash2Icon />\n            <Swap swapKey={removeLabel}>{removeLabel}</Swap>\n          </Button>\n          {isRemoving && (\n            <>\n              <Button\n                type='button'\n                size='sm'\n                variant='ghost'\n                onClick={() => onAction({ type: 'removeCancelled' })}\n                className='transition-opacity duration-200 starting:opacity-0'\n              >\n                Keep it\n              </Button>\n              <p className='text-muted-foreground text-xs transition-opacity duration-200 starting:opacity-0'>\n                The agent loses {lostToolsOf(toolCount)}\n              </p>\n            </>\n          )}\n        </div>\n      </Fold>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-04/server-row.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-04/add-server-dialog.tsx",
      "content": "'use client';\n\nimport { useId } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CheckIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\n\nimport { DEMO_NAME, FOUND_TOOLS, type Transport } from './data';\nimport type { DialogState, McpAction, TestStatus } from './session';\n\nconst TRANSPORTS: Segment<Transport>[] = [\n  { value: 'remote', label: 'Remote' },\n  { value: 'local', label: 'Local' },\n];\n\nconst ADDRESS_LABEL: Record<Transport, string> = {\n  remote: 'Server URL',\n  local: 'Command',\n};\n\nconst ADDRESS_HINT: Record<Transport, string> = {\n  remote: 'https://mcp.example.dev/mcp',\n  local: 'node ./mcp/server.js',\n};\n\nconst TEST_STATE: Record<TestStatus, MorphState> = {\n  idle: 'idle',\n  testing: 'busy',\n  connected: 'done',\n  failed: 'idle',\n};\n\nconst TEST_LABELS: Record<MorphState, string> = {\n  idle: 'Test connection',\n  busy: 'Testing',\n  done: 'Connected',\n};\n\nfunction pressedQuietOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-[0.94] bg-foreground/[0.07]';\n  }\n  return undefined;\n}\n\nfunction toolsFoundOf(count: number) {\n  if (count === 1) {\n    return '1 tool found';\n  }\n  return `${count} tools found`;\n}\n\nfunction TestResult({ dialog }: { dialog: DialogState }) {\n  if (dialog.test === 'testing') {\n    return (\n      <p className='text-muted-foreground flex items-center gap-2 text-[13px]'>\n        <Spinner label='Testing the connection' />\n        Testing the connection\n      </p>\n    );\n  }\n  if (dialog.test === 'failed') {\n    return (\n      <div className='bg-destructive/10 flex items-start gap-2.5 rounded-lg p-3'>\n        <XIcon className='text-destructive-ink mt-0.5 size-4 shrink-0' />\n        <div className='flex min-w-0 flex-col gap-0.5'>\n          <p className='text-destructive-ink text-[13px] font-medium'>Failed</p>\n          <p className='text-[13px] leading-relaxed'>{dialog.failure}</p>\n        </div>\n      </div>\n    );\n  }\n  if (dialog.test === 'connected') {\n    return (\n      <div className='bg-success/10 flex items-start gap-2.5 rounded-lg p-3'>\n        <CheckIcon className='text-success-foreground mt-0.5 size-4 shrink-0' />\n        <div className='flex min-w-0 flex-col gap-2'>\n          <p className='text-success-foreground text-[13px] font-medium'>\n            Connected, {toolsFoundOf(FOUND_TOOLS.length)}\n          </p>\n          <ul className='flex flex-wrap gap-1'>\n            {FOUND_TOOLS.map((tool) => (\n              <li\n                key={tool.name}\n                className='bg-card/70 dark:bg-foreground/[0.06] rounded-sm px-1.5 py-0.5 font-mono text-[11px]'\n              >\n                {tool.name}\n              </li>\n            ))}\n          </ul>\n        </div>\n      </div>\n    );\n  }\n  return null;\n}\n\nexport type AddServerDialogProps = {\n  dialog: DialogState;\n  pressed: string | null;\n  onAction: (action: McpAction) => void;\n  onTest: () => void;\n  onAdd: () => void;\n  onClose: () => void;\n};\n\n/** Drawn inside the block, so the demonstration never opens a layer over the rest of the page. */\nexport function AddServerDialog({\n  dialog,\n  pressed,\n  onAction,\n  onTest,\n  onAdd,\n  onClose,\n}: AddServerDialogProps) {\n  const titleId = useId();\n  const nameId = useId();\n  const addressId = useId();\n  const isOpen = dialog.isOpen;\n  const isTesting = dialog.test === 'testing';\n  const canAdd = dialog.test === 'connected';\n  const addressLabel = ADDRESS_LABEL[dialog.transport];\n\n  function submit(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (canAdd) {\n      onAdd();\n    }\n  }\n\n  return (\n    <InlineSheet\n      labelledBy={titleId}\n      closeLabel='Close the dialog'\n      side='center'\n      closer='none'\n      isOpen={isOpen}\n      panelClassName='text-card-foreground p-6'\n      onClose={onClose}\n    >\n      <form noValidate onSubmit={submit}>\n        <AnimatedSize contentClassName='flex flex-col gap-4'>\n          <div className='flex flex-col gap-1.5 pe-8'>\n            <h2 id={titleId} className='text-lg leading-tight font-semibold'>\n              Add a server\n            </h2>\n            <p className='text-muted-foreground text-[13px]'>\n              Test the connection first. The agent only gets the tools the\n              server lists.\n            </p>\n          </div>\n\n          <div className='flex flex-col gap-1.5'>\n            <Label htmlFor={nameId}>Name</Label>\n            <Input\n              id={nameId}\n              data-dialog-first\n              autoComplete='off'\n              placeholder={DEMO_NAME}\n              value={dialog.name}\n              disabled={isTesting}\n              onChange={(event) =>\n                onAction({ type: 'named', text: event.target.value })\n              }\n            />\n          </div>\n\n          <div className='flex flex-col gap-1.5'>\n            <span className='text-[13px] leading-none font-medium'>\n              Transport\n            </span>\n            <Segments\n              value={dialog.transport}\n              segments={TRANSPORTS}\n              onValueChange={(transport) =>\n                onAction({ type: 'transport', transport })\n              }\n              label='Transport'\n              className='w-44'\n            />\n          </div>\n\n          <div className='flex flex-col gap-1.5'>\n            <Label htmlFor={addressId}>\n              <Swap swapKey={addressLabel}>{addressLabel}</Swap>\n            </Label>\n            <Input\n              id={addressId}\n              autoComplete='off'\n              autoCapitalize='off'\n              spellCheck={false}\n              placeholder={ADDRESS_HINT[dialog.transport]}\n              value={dialog.address}\n              disabled={isTesting}\n              aria-invalid={dialog.test === 'failed'}\n              onChange={(event) =>\n                onAction({ type: 'addressed', text: event.target.value })\n              }\n              className='font-mono'\n            />\n          </div>\n\n          <div aria-live='polite' className='empty:hidden'>\n            <TestResult dialog={dialog} />\n          </div>\n\n          <div className='flex flex-col-reverse gap-2 @sm:flex-row @sm:items-center @sm:justify-end'>\n            <MorphButton\n              type='button'\n              variant='outline'\n              state={TEST_STATE[dialog.test]}\n              labels={TEST_LABELS}\n              onClick={onTest}\n              className={cn('@sm:me-auto', pressedQuietOf(pressed === 'test'))}\n            />\n            <Button type='button' variant='ghost' onClick={onClose}>\n              Cancel\n            </Button>\n            <Button\n              type='submit'\n              disabled={!canAdd}\n              className={pressedSolidOf(pressed === 'confirm')}\n            >\n              Add server\n            </Button>\n          </div>\n        </AnimatedSize>\n      </form>\n      <Button\n        type='button'\n        variant='ghost'\n        size='icon-sm'\n        aria-label='Close'\n        onClick={onClose}\n        className='text-muted-foreground absolute top-3 right-3'\n      >\n        <XIcon />\n      </Button>\n    </InlineSheet>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-04/add-server-dialog.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-04/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  ADDED_SERVER_ID,\n  DEMO_ADDRESS,\n  DEMO_ADDRESS_FIRST,\n  DEMO_NAME,\n  FOUND_TOOLS,\n  SERVERS,\n  type Server,\n  type Tool,\n  type Transport,\n} from './data';\n\n/** Restored is connected a moment ago: the row still shows the button that did it. */\nexport type ConnectionStatus =\n  'connected' | 'expired' | 'reconnecting' | 'restored';\n\nexport type ToolSetting = {\n  isEnabled: boolean;\n  asksFirst: boolean;\n};\n\nexport type ServerLive = {\n  status: ConnectionStatus;\n  tools: Record<string, ToolSetting>;\n};\n\nexport type TestStatus = 'idle' | 'testing' | 'connected' | 'failed';\n\nexport type DialogState = {\n  isOpen: boolean;\n  name: string;\n  address: string;\n  transport: Transport;\n  test: TestStatus;\n  failure: string | null;\n};\n\nexport type McpState = {\n  servers: Server[];\n  live: Record<string, ServerLive>;\n  /** The server whose tools are unfolded. */\n  openId: string | null;\n  /** The server that asks, in its own row, whether it should be removed. */\n  removingId: string | null;\n  dialog: DialogState;\n  addedCount: number;\n};\n\nexport type McpAction =\n  | { type: 'toggled'; id: string }\n  | { type: 'toolEnabled'; id: string; tool: string; isEnabled: boolean }\n  | { type: 'toolAsks'; id: string; tool: string; asksFirst: boolean }\n  | { type: 'reconnect'; id: string }\n  | { type: 'reconnected'; id: string }\n  | { type: 'settled'; id: string }\n  | { type: 'removeAsked'; id: string }\n  | { type: 'removeCancelled' }\n  | { type: 'removed'; id: string }\n  | { type: 'dialogOpened' }\n  | { type: 'dialogClosed' }\n  | { type: 'named'; text: string }\n  | { type: 'addressed'; text: string }\n  | { type: 'transport'; transport: Transport }\n  | { type: 'test' }\n  | { type: 'tested' }\n  | { type: 'added' };\n\ntype Step = SessionStep<McpState, McpAction>;\n\n/** A tool that writes asks first until a person decides otherwise. */\nfunction settingOf(tool: Tool): ToolSetting {\n  return { isEnabled: true, asksFirst: tool.access === 'write' };\n}\n\nfunction liveOf(server: Server, status: ConnectionStatus): ServerLive {\n  const tools: Record<string, ToolSetting> = {};\n  for (const tool of server.tools) {\n    tools[tool.name] = settingOf(tool);\n  }\n  return { status, tools };\n}\n\nconst FIRST_STATUS: Record<string, ConnectionStatus> = {\n  linear: 'expired',\n};\n\nfunction initialLive() {\n  const live: Record<string, ServerLive> = {};\n  for (const server of SERVERS) {\n    const status = FIRST_STATUS[server.id] ?? 'connected';\n    live[server.id] = liveOf(server, status);\n  }\n  return live;\n}\n\nconst EMPTY_DIALOG: DialogState = {\n  isOpen: false,\n  name: '',\n  address: '',\n  transport: 'remote',\n  test: 'idle',\n  failure: null,\n};\n\nexport const INITIAL: McpState = {\n  servers: SERVERS,\n  live: initialLive(),\n  openId: null,\n  removingId: null,\n  dialog: EMPTY_DIALOG,\n  addedCount: 0,\n};\n\nconst REMOTE_SHAPE = /^https:\\/\\/\\S+\\/mcp\\/?$/;\n\n/** What a test connection answers, read from the address alone: nothing is called. */\nexport function failureOf(dialog: DialogState) {\n  const address = dialog.address.trim();\n  if (dialog.transport === 'local') {\n    if (address === '') {\n      return 'Enter the command that starts the server';\n    }\n    return null;\n  }\n  if (!address.startsWith('https://')) {\n    return 'A remote server needs an address that starts with https://';\n  }\n  if (!REMOTE_SHAPE.test(address)) {\n    return 'No MCP server answered at this address. Most remote servers end in /mcp';\n  }\n  return null;\n}\n\nexport function enabledCountOf(live: ServerLive) {\n  const settings = Object.values(live.tools);\n  const enabled = settings.filter((setting) => setting.isEnabled);\n  return enabled.length;\n}\n\nfunction withLive(\n  state: McpState,\n  id: string,\n  change: (live: ServerLive) => ServerLive\n): McpState {\n  const current = state.live[id];\n  if (!current) {\n    return state;\n  }\n  return { ...state, live: { ...state.live, [id]: change(current) } };\n}\n\nfunction withTool(\n  state: McpState,\n  id: string,\n  tool: string,\n  patch: Partial<ToolSetting>\n) {\n  return withLive(state, id, (live) => {\n    const setting = { ...live.tools[tool], ...patch };\n    return { ...live, tools: { ...live.tools, [tool]: setting } };\n  });\n}\n\nfunction withStatus(\n  state: McpState,\n  id: string,\n  from: ConnectionStatus,\n  to: ConnectionStatus\n) {\n  return withLive(state, id, (live) => {\n    if (live.status !== from) {\n      return live;\n    }\n    return { ...live, status: to };\n  });\n}\n\nfunction toggled(state: McpState, id: string): McpState {\n  if (state.openId === id) {\n    return { ...state, openId: null };\n  }\n  return { ...state, openId: id };\n}\n\nfunction removed(state: McpState, id: string): McpState {\n  const servers = state.servers.filter((server) => server.id !== id);\n  const live = { ...state.live };\n  delete live[id];\n  let openId = state.openId;\n  if (openId === id) {\n    openId = null;\n  }\n  return { ...state, servers, live, openId, removingId: null };\n}\n\n/** Changing a field makes the last test stale: Add waits for a new one. */\nfunction edited(state: McpState, patch: Partial<DialogState>): McpState {\n  if (state.dialog.test === 'testing') {\n    return state;\n  }\n  const dialog: DialogState = {\n    ...state.dialog,\n    ...patch,\n    test: 'idle',\n    failure: null,\n  };\n  return { ...state, dialog };\n}\n\nfunction test(state: McpState): McpState {\n  const canTest = state.dialog.isOpen && state.dialog.test !== 'testing';\n  if (!canTest) {\n    return state;\n  }\n  return { ...state, dialog: { ...state.dialog, test: 'testing' } };\n}\n\nfunction tested(state: McpState): McpState {\n  if (state.dialog.test !== 'testing') {\n    return state;\n  }\n  const failure = failureOf(state.dialog);\n  if (failure) {\n    return { ...state, dialog: { ...state.dialog, test: 'failed', failure } };\n  }\n  return { ...state, dialog: { ...state.dialog, test: 'connected' } };\n}\n\nfunction nameOf(dialog: DialogState) {\n  const trimmed = dialog.name.trim();\n  if (trimmed === '') {\n    return 'New server';\n  }\n  return trimmed;\n}\n\nfunction added(state: McpState): McpState {\n  if (state.dialog.test !== 'connected') {\n    return state;\n  }\n  const name = nameOf(state.dialog);\n  const count = state.addedCount + 1;\n  const server: Server = {\n    id: `${ADDED_SERVER_ID}-${count}`,\n    name,\n    transport: state.dialog.transport,\n    address: state.dialog.address.trim(),\n    tools: FOUND_TOOLS,\n  };\n  return {\n    ...state,\n    servers: [...state.servers, server],\n    live: { ...state.live, [server.id]: liveOf(server, 'connected') },\n    dialog: { ...state.dialog, isOpen: false },\n    addedCount: count,\n  };\n}\n\nexport function reducer(state: McpState, action: McpAction): McpState {\n  switch (action.type) {\n    case 'toggled':\n      return toggled(state, action.id);\n    case 'toolEnabled':\n      return withTool(state, action.id, action.tool, {\n        isEnabled: action.isEnabled,\n      });\n    case 'toolAsks':\n      return withTool(state, action.id, action.tool, {\n        asksFirst: action.asksFirst,\n      });\n    case 'reconnect':\n      return withStatus(state, action.id, 'expired', 'reconnecting');\n    case 'reconnected':\n      return withStatus(state, action.id, 'reconnecting', 'restored');\n    case 'settled':\n      return withStatus(state, action.id, 'restored', 'connected');\n    case 'removeAsked':\n      return { ...state, removingId: action.id };\n    case 'removeCancelled':\n      return { ...state, removingId: null };\n    case 'removed':\n      return removed(state, action.id);\n    case 'dialogOpened':\n      return { ...state, dialog: { ...EMPTY_DIALOG, isOpen: true } };\n    case 'dialogClosed':\n      return { ...state, dialog: { ...state.dialog, isOpen: false } };\n    case 'named':\n      return edited(state, { name: action.text });\n    case 'addressed':\n      return edited(state, { address: action.text });\n    case 'transport':\n      return edited(state, { transport: action.transport });\n    case 'test':\n      return test(state);\n    case 'tested':\n      return tested(state);\n    case 'added':\n      return added(state);\n  }\n}\n\nconst CHUNK = 3;\n\nfunction delayOfChunk(index: number, startAfter: number) {\n  if (index === 0) {\n    return startAfter;\n  }\n  return 70;\n}\n\n/** The demonstration types from what the field holds to the full text, a few characters at a time. */\nfunction typingSteps(\n  from: string,\n  to: string,\n  startAfter: number,\n  write: (text: string) => McpAction\n): Step[] {\n  const steps: Step[] = [];\n  const last = to.length + CHUNK;\n  for (let end = from.length + CHUNK; end < last; end += CHUNK) {\n    const text = to.slice(0, end);\n    const after = delayOfChunk(steps.length, startAfter);\n    steps.push({ after, by: 'demo', action: write(text) });\n  }\n  return steps;\n}\n\nfunction named(text: string): McpAction {\n  return { type: 'named', text };\n}\n\nfunction addressed(text: string): McpAction {\n  return { type: 'addressed', text };\n}\n\nexport const RECONNECT_MS = 1500;\n\nexport const SETTLE_MS = 1600;\n\nexport const TEST_MS = 1200;\n\nexport const SCRIPT: Step[] = [\n  {\n    after: 1300,\n    by: 'demo',\n    press: 'toggle-github',\n    action: { type: 'toggled', id: 'github' },\n  },\n  {\n    after: 1500,\n    by: 'demo',\n    action: {\n      type: 'toolAsks',\n      id: 'github',\n      tool: 'comment_on_issue',\n      asksFirst: false,\n    },\n  },\n  {\n    after: 1500,\n    by: 'demo',\n    press: 'reconnect-linear',\n    action: { type: 'reconnect', id: 'linear' },\n  },\n  { after: RECONNECT_MS, action: { type: 'reconnected', id: 'linear' } },\n  { after: SETTLE_MS, action: { type: 'settled', id: 'linear' } },\n  { after: 600, by: 'demo', press: 'add', action: { type: 'dialogOpened' } },\n  ...typingSteps('', DEMO_NAME, 800, named),\n  ...typingSteps('', DEMO_ADDRESS_FIRST, 500, addressed),\n  { after: 600, by: 'demo', press: 'test', action: { type: 'test' } },\n  { after: TEST_MS, action: { type: 'tested' } },\n  ...typingSteps(DEMO_ADDRESS_FIRST, DEMO_ADDRESS, 1700, addressed),\n  { after: 600, by: 'demo', press: 'test', action: { type: 'test' } },\n  { after: TEST_MS, action: { type: 'tested' } },\n  { after: 1700, by: 'demo', press: 'confirm', action: { type: 'added' } },\n];\n\n/** Under reduced motion the first server shows its tools and one server waits for a new token. */\nexport const RESTING: McpState = { ...INITIAL, openId: 'github' };\n\nexport const LOOP_AFTER_MS = 3600;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-04/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-04/data.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport const AGENT_NAME = 'Support agent';\n\nexport type Transport = 'remote' | 'local';\n\nexport const TRANSPORT_WORD: Record<Transport, string> = {\n  remote: 'Remote',\n  local: 'Local',\n};\n\nexport type Access = 'read' | 'write';\n\nexport type Tool = {\n  name: string;\n  summary: string;\n  access: Access;\n};\n\nexport type Server = {\n  id: string;\n  name: string;\n  transport: Transport;\n  /** The mark of a known product. A server of your own gets a picture drawn from its name. */\n  brand?: BrandSlug;\n  /** Shown for a server of your own: its address or the command that starts it. */\n  address?: string;\n  tools: Tool[];\n};\n\n/** Tool lists written for this demo: what a server really offers comes from the server. */\nexport const SERVERS: Server[] = [\n  {\n    id: 'github',\n    name: 'GitHub',\n    transport: 'remote',\n    brand: 'github',\n    tools: [\n      {\n        name: 'search_code',\n        summary: 'Find code across the repositories',\n        access: 'read',\n      },\n      {\n        name: 'get_pull_request',\n        summary: 'Read a pull request and its checks',\n        access: 'read',\n      },\n      {\n        name: 'list_issues',\n        summary: 'List open issues by label',\n        access: 'read',\n      },\n      {\n        name: 'create_issue',\n        summary: 'Open an issue in a repository',\n        access: 'write',\n      },\n      {\n        name: 'comment_on_issue',\n        summary: 'Reply in an issue thread',\n        access: 'write',\n      },\n      {\n        name: 'merge_pull_request',\n        summary: 'Merge a pull request into its base',\n        access: 'write',\n      },\n    ],\n  },\n  {\n    id: 'linear',\n    name: 'Linear',\n    transport: 'remote',\n    brand: 'linear',\n    tools: [\n      {\n        name: 'list_issues',\n        summary: 'List the issues of a team',\n        access: 'read',\n      },\n      { name: 'get_issue', summary: 'Read one issue', access: 'read' },\n      {\n        name: 'create_issue',\n        summary: 'Create an issue for a team',\n        access: 'write',\n      },\n      {\n        name: 'update_issue',\n        summary: 'Change the state or the owner of an issue',\n        access: 'write',\n      },\n    ],\n  },\n  {\n    id: 'notion',\n    name: 'Notion',\n    transport: 'remote',\n    brand: 'notion',\n    tools: [\n      { name: 'search', summary: 'Search the workspace', access: 'read' },\n      { name: 'get_page', summary: 'Read a page', access: 'read' },\n      {\n        name: 'create_page',\n        summary: 'Create a page under a parent',\n        access: 'write',\n      },\n      {\n        name: 'append_to_page',\n        summary: 'Add blocks at the end of a page',\n        access: 'write',\n      },\n    ],\n  },\n  {\n    id: 'orders',\n    name: 'Orders database',\n    transport: 'local',\n    brand: 'postgresql',\n    address: 'node ./mcp/orders-db.js',\n    tools: [\n      {\n        name: 'describe_table',\n        summary: 'Read the columns of a table',\n        access: 'read',\n      },\n      {\n        name: 'run_query',\n        summary: 'Run a read-only query',\n        access: 'read',\n      },\n      {\n        name: 'update_order',\n        summary: 'Change the state of one order',\n        access: 'write',\n      },\n    ],\n  },\n];\n\nexport const ADDED_SERVER_ID = 'added';\n\n/** What the test connection finds on the server the dialog adds. */\nexport const FOUND_TOOLS: Tool[] = [\n  {\n    name: 'search_docs',\n    summary: 'Search the help center',\n    access: 'read',\n  },\n  { name: 'get_article', summary: 'Read one article', access: 'read' },\n  {\n    name: 'list_collections',\n    summary: 'List the collections of articles',\n    access: 'read',\n  },\n  {\n    name: 'suggest_edit',\n    summary: 'Propose a change to an article',\n    access: 'write',\n  },\n  {\n    name: 'create_draft',\n    summary: 'Start a draft article',\n    access: 'write',\n  },\n  {\n    name: 'publish_article',\n    summary: 'Publish a draft',\n    access: 'write',\n  },\n];\n\nexport const DEMO_NAME = 'Docs search';\n\nexport const DEMO_ADDRESS_FIRST = 'https://mcp.example.dev';\n\nexport const DEMO_ADDRESS = 'https://mcp.example.dev/mcp';\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-04/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-ops"
  ],
  "type": "registry:block"
}