{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ouro-mcp-app",
  "title": "OuroMcpApp",
  "description": "The view an MCP server returns for agent-composed UI (MCP Apps): the host, such as Claude or ChatGPT, frames it, and it shows the latest tool result's card: Ouro's composed tree in `structuredContent.ouro` with ComposedSurface, once it passes core's `validateTree` against the catalog, or A2UI messages in `structuredContent.a2ui` with `A2UISurface`.",
  "registryDependencies": [
    "@ouro/a2ui-surface",
    "@ouro/alert",
    "@ouro/composed-surface",
    "@ouro/lib-a2ui-core",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-mcp-app",
    "@ouro/lib-use-dev-messages",
    "@ouro/spinner"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/mcp-app/ouro-mcp-app-styles.ts",
      "content": "export { ROOT_CLASS, DEFAULT_APP_INFO, METHOD_NOT_FOUND, INVALID_PARAMS };\n\n/** The view's column: the card, then what the last press did, with HX's medium gap between them. */\nconst ROOT_CLASS = \"grid min-w-0 gap-4\";\n\n/** What the view tells the host it is, in `ui/initialize`, when the app names nothing else. */\nconst DEFAULT_APP_INFO = { name: \"Ouro HX card\", version: \"1.0.0\" };\n\n/** JSON-RPC's code for a method the receiver doesn't have. */\nconst METHOD_NOT_FOUND = -32601;\n\n/** JSON-RPC's code for a request whose parameters the receiver refuses: here, a function call the catalog doesn't declare. */\nconst INVALID_PARAMS = -32602;\n",
      "type": "registry:ui",
      "target": "@components/ouro/mcp-app/ouro-mcp-app-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/mcp-app/ouro-mcp-app.tsx",
      "content": "\"use client\";\n\nimport { type JSX, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { A2UISurface, type A2UIActionMessage, type A2UIHandoff, type A2UIProblem, type A2UISurfaceProps } from \"@/registry/ouro/components/ouro/a2ui-surface/a2ui-surface\";\nimport { Alert } from \"@/registry/ouro/components/ouro/alert/alert\";\nimport { ComposedSurface, type ComposedSurfaceProps } from \"@/registry/ouro/components/ouro/composed-surface/composed-surface\";\nimport { Spinner } from \"@/registry/ouro/components/ouro/spinner/spinner\";\nimport { functionCallProblem, loadCatalog, validateTree, type ComposedNode, type LoadedCatalog, type TreeProblem } from \"@/registry/ouro/lib/ouro/a2ui-core\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { connectMcpApp, MCP_APPS_PROTOCOL, McpAppError, windowHostLink, type McpAppConnection, type McpAppHostLink } from \"@/registry/ouro/lib/ouro/mcp-app\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { DEFAULT_APP_INFO, INVALID_PARAMS, METHOD_NOT_FOUND, ROOT_CLASS } from \"@/registry/ouro/components/ouro/mcp-app/ouro-mcp-app-styles\";\n\n/** Props for {@link OuroMcpApp}. */\nexport interface OuroMcpAppProps {\n  /** The app's A2UI catalog, generated from its actions by core's `ouro-a2ui-catalog.mts catalog`. Tool results carry only its id. */\n  catalog: unknown;\n  /**\n   * Where a person-only button takes the person: the address of your app's own screen for that action, which the\n   * host opens with `ui/open-link`. Without one, or when the host can't open links, the view tells the person where\n   * to do it.\n   */\n  handoffUrl?: ((handoff: A2UIHandoff) => string | undefined) | undefined;\n  /**\n   * The app's own word for an id on a confirm sheet, from its own data, in place of the agent's name. It works for a\n   * view you build in code, on an A2UI result; a composed tree's server names its ids when it builds the tree. See\n   * A2UISurface's `label`.\n   */\n  label?: A2UISurfaceProps[\"label\"];\n  /** The connection to the host. @default the window that framed the view, through `windowHostLink()` */\n  host?: McpAppHostLink | undefined;\n  /** What the view calls itself in `ui/initialize`. @default { name: \"Ouro HX card\", version: \"1.0.0\" } */\n  appInfo?: { name: string; version: string } | undefined;\n  /** Layout only: margins, width (`max-w-md`). */\n  className?: string | undefined;\n\n  /** Not a prop. A pressed button calls that action's own MCP tool through the host: give the view only the catalog. */\n  onAction?: { \"OuroMcpApp calls each action's own tool through the host; pass catalog\": never };\n}\n\n/** What the last press did, or why the card can't be shown. */\ninterface Status {\n  tone: \"success\" | \"destructive\" | \"primary\";\n  title: string;\n  description?: string;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === \"object\" && v !== null && !Array.isArray(v);\n\n/** The card a tool result carries: Ouro's composed tree, or A2UI messages. */\ntype CardContent = { tree: unknown; catalogId: unknown } | { messages: unknown[] };\n\n/**\n * The card in a tool result: `structuredContent.ouro`, as core's `mcpAppTreeResult` puts it, else\n * `structuredContent.a2ui`, as core's `mcpAppToolResult` puts it.\n */\nfunction cardOf(result: Record<string, unknown>): CardContent | undefined {\n  const content = isRecord(result.structuredContent) ? result.structuredContent : {};\n  const { ouro, a2ui } = content;\n  if (isRecord(ouro) && \"tree\" in ouro) return { tree: ouro.tree, catalogId: ouro.catalogId };\n  return isRecord(a2ui) && Array.isArray(a2ui.messages) ? { messages: a2ui.messages } : undefined;\n}\n\n/** What is wrong with a composed tree for this view: core's `validateTree` against its catalog, and the catalog it names. */\nfunction treeProblems(actions: LoadedCatalog, card: { tree: unknown; catalogId: unknown }): TreeProblem[] {\n  const named = card.catalogId === actions.catalogId ? [] : [{ path: \"/catalogId\", message: `The tree is for catalog ${JSON.stringify(card.catalogId)}; this view draws ${actions.catalogId}.` }];\n  return [...named, ...validateTree(actions, card.tree)];\n}\n\n/** What a press asks the action's own tool to do, from either format. */\ninterface ToolPress {\n  name: string;\n  input: Record<string, unknown>;\n  /** The button's label, as the person read it. */\n  label: string;\n}\n\n/** The text a tool result gives an agent and a text-only host. */\nfunction resultText(result: Record<string, unknown>): string | undefined {\n  if (!Array.isArray(result.content)) return undefined;\n  const texts = (result.content as unknown[]).flatMap((block) => (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\" ? [block.text] : []));\n  return texts.length ? texts.join(\"\\n\") : undefined;\n}\n\n/** Follows the host's light or dark theme, the way HX's own apps switch: the `dark` class on the document. */\nfunction applyTheme(context: unknown): void {\n  const theme = isRecord(context) ? context.theme : undefined;\n  if (theme !== \"light\" && theme !== \"dark\") return;\n  const root = document.documentElement;\n  root.classList.toggle(\"dark\", theme === \"dark\");\n  root.style.colorScheme = theme;\n}\n\n/**\n * The view an MCP server returns for agent-composed UI (MCP Apps): the host, such as Claude or ChatGPT, frames it,\n * and it shows the latest tool result's card: Ouro's composed tree in `structuredContent.ouro` with ComposedSurface,\n * once it passes core's `validateTree` against the catalog, or A2UI messages in `structuredContent.a2ui` with\n * {@link A2UISurface}. Read and write buttons call\n * their action's own tool through the host, a consequential one only after the person confirms, and a person-only\n * one takes the person to your app's screen. It follows the host's light or dark theme and tells the host its size.\n *\n * Build it into one HTML file with your catalog embedded (`node scripts/mcp-app.mts build`), and serve that as the\n * `ui://` resource. Use A2UISurface instead when the card is in your own app's screen, not in an MCP host.\n *\n * @claim \"a consequential one only after the person confirms\" registry/ouro/components/ouro/mcp-app/ouro-mcp-app.test.tsx verify:testExists(registry/ouro/components/ouro/mcp-app/ouro-mcp-app.test.tsx::OuroMcpApp > calls a consequential action's tool only after the person confirms)\n * @claim \"a person-only one takes the person to your app's screen\" registry/ouro/components/ouro/mcp-app/ouro-mcp-app.test.tsx verify:testExists(registry/ouro/components/ouro/mcp-app/ouro-mcp-app.test.tsx::OuroMcpApp > opens the app's own screen for a person-only button and calls no tool)\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/ouro-mcp-app\n *\n * @example\n * createRoot(document.getElementById(\"root\")!).render(\n *   <OuroMcpApp catalog={catalog} handoffUrl={({ action }) => `https://kitchen.example.com/recipes?do=${action}`} />,\n * );\n */\nexport function OuroMcpApp(props: OuroMcpAppProps): JSX.Element {\n  const { catalog, handoffUrl, label, host, appInfo, className, onAction } = props;\n  const actions = useMemo(() => loadCatalog(catalog), [catalog]);\n  const [card, setCard] = useState<CardContent | undefined>(undefined);\n  const [status, setStatus] = useState<Status | undefined>(undefined);\n  const [connection, setConnection] = useState<McpAppConnection | undefined>(undefined);\n  // Stryker disable next-line BooleanLiteral: read only after the handshake has set it.\n  const openLinks = useRef(false);\n  const root = useRef<HTMLDivElement>(null);\n  const name = appInfo?.name ?? DEFAULT_APP_INFO.name;\n  const version = appInfo?.version ?? DEFAULT_APP_INFO.version;\n\n  useEffect(() => {\n    const link = host ?? windowHostLink();\n    let observer: ResizeObserver | undefined;\n    const c = connectMcpApp(link, {\n      onNotification: (method, params) => {\n        if (method === \"ui/notifications/tool-result\") {\n          const next = cardOf(params);\n          if (next) {\n            setCard(next);\n            setStatus(undefined);\n          } else setStatus({ tone: \"destructive\", title: \"This card can't be shown\", description: \"The tool's result had no card in it.\" });\n        } else if (method === \"ui/notifications/tool-cancelled\") setStatus({ tone: \"primary\", title: \"The agent stopped before the card was ready.\" });\n        else if (method === \"ui/notifications/host-context-changed\") applyTheme(params);\n      },\n      onRequest: (method, params) => {\n        // An agent acts through the action's own tool, never through the person's screen.\n        if (method === \"tools/call\") {\n          const problem = functionCallProblem(actions, params.name);\n          throw new McpAppError(INVALID_PARAMS, problem.message, { code: \"INVALID_FUNCTION_CALL\", ...(problem.refusal ? { refusal: problem.refusal } : {}) });\n        }\n        if (method === \"ping\" || method === \"ui/resource-teardown\") return {};\n        throw new McpAppError(METHOD_NOT_FOUND, `${method} is not a request this view answers.`);\n      },\n    });\n    void c.request(\"ui/initialize\", { appInfo: { name, version }, appCapabilities: {}, protocolVersion: MCP_APPS_PROTOCOL }).then(\n      (result) => {\n        openLinks.current = isRecord(result.hostCapabilities) && isRecord(result.hostCapabilities.openLinks);\n        applyTheme(result.hostContext);\n        c.notify(\"ui/notifications/initialized\");\n        setConnection(c);\n        // The host sizes the frame to the view (MCP Apps' flexible dimensions).\n        observer = new ResizeObserver(() => {\n          const box = root.current!.getBoundingClientRect();\n          c.notify(\"ui/notifications/size-changed\", { width: Math.ceil(box.width), height: Math.ceil(box.height) });\n        });\n        observer.observe(root.current!);\n      },\n      () => setStatus({ tone: \"destructive\", title: \"This card can't be shown\", description: \"The host didn't connect to it.\" }),\n    );\n    return () => {\n      // Stryker disable next-line OptionalChaining,CallExpression: React has removed the root by now, and a detached element doesn't resize; disconnecting frees the observer.\n      observer?.disconnect();\n      c.close();\n    };\n  }, [host, actions, name, version]);\n\n  const callTool = useCallback(\n    async ({ name, input, label }: ToolPress) => {\n      try {\n        const result = await connection!.request(\"tools/call\", { name, arguments: input });\n        const next = cardOf(result);\n        if (next) setCard(next);\n        const text = resultText(result);\n        setStatus(result.isError === true ? { tone: \"destructive\", title: `${label} didn't go through`, ...(text ? { description: text } : {}) } : { tone: \"success\", title: text ?? `${label}: done.` });\n      } catch (e) {\n        setStatus({ tone: \"destructive\", title: `${label} didn't go through`, description: (e as Error).message });\n      }\n    },\n    [connection],\n  );\n  const runAction = useCallback(({ action }: A2UIActionMessage) => callTool({ name: action.name, input: action.context, label: action.userMessage }), [callTool]);\n  const pressTree = useCallback<ComposedSurfaceProps[\"onPress\"]>((press) => callTool({ name: press.action, input: press.input, label: press.label }), [callTool]);\n\n  const handOff = useCallback(\n    (handoff: A2UIHandoff) => {\n      const yourself = () => setStatus({ tone: \"primary\", title: `${actions.actions[handoff.action]!.label} is yours to do`, description: `Do it ${handoff.how}.` });\n      const url = handoffUrl?.(handoff);\n      if (url === undefined || !openLinks.current) return yourself();\n      connection!.request(\"ui/open-link\", { url }).catch(yourself);\n    },\n    [connection, handoffUrl, actions],\n  );\n\n  const tellAgent = useCallback(\n    (problems: readonly { path: string; message: string }[], structuredContent: object) => {\n      // The agent composed the card, so it hears what to correct.\n      void connection!\n        .request(\"ui/update-model-context\", {\n          content: [{ type: \"text\", text: `The card didn't pass the checks for composed UI: ${problems.map((p) => `${p.path}: ${p.message}`).join(\" \")}` }],\n          structuredContent,\n        })\n        .catch(() => {});\n    },\n    [connection],\n  );\n  const reportProblems = useCallback((problems: readonly A2UIProblem[]) => tellAgent(problems, { a2uiProblems: problems }), [tellAgent]);\n\n  const tree = card && \"tree\" in card ? card : undefined;\n  const problems = useMemo(() => (tree ? treeProblems(actions, tree) : []), [actions, tree]);\n  useEffect(() => {\n    if (problems.length && connection) tellAgent(problems, { ouroProblems: problems });\n  }, [problems, connection, tellAgent]);\n\n  useDevWarnings(\n    \"OuroMcpApp\",\n    process.env.NODE_ENV !== \"production\" ? () => [onAction !== undefined && [\"onAction is not a prop; a pressed button calls its action's own tool through the host\", \"<OuroMcpApp catalog={catalog} />\"]] : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  return (\n    <div ref={root} data-ouro=\"ouro-mcp-app\" className={cn(ROOT_CLASS, className)}>\n      {card && connection ? (\n        \"messages\" in card ? (\n          <A2UISurface catalog={catalog} messages={card.messages} label={label} onAction={runAction} onHandoff={handOff} onProblems={reportProblems} />\n        ) : problems.length ? (\n          <Alert tone=\"destructive\" title=\"This card can't be shown\" description=\"It didn't pass the checks for composed UI.\" />\n        ) : (\n          <ComposedSurface tree={card.tree as ComposedNode} onPress={pressTree} onHandoff={handOff} />\n        )\n      ) : status ? null : (\n        <Spinner label=\"Waiting for the card\" />\n      )}\n      {status ? <Alert tone={status.tone} title={status.title} description={status.description} /> : null}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/mcp-app/ouro-mcp-app.tsx"
    }
  ],
  "docs": "The view an MCP server returns for agent-composed UI (MCP Apps): the host, such as Claude or ChatGPT, frames it, and it shows the latest tool result's card: Ouro's composed tree in `structuredContent.ouro` with ComposedSurface, once it passes core's `validateTree` against the catalog, or A2UI messages in `structuredContent.a2ui` with `A2UISurface`. Import: import { OuroMcpApp } from \"@/components/ouro/mcp-app/ouro-mcp-app\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: a2ui-surface, alert, aspect-ratio, badge, button, card, composed-surface, confirm-dialog, description-list, dialog, heading, row, separator, sheet, spinner, stack, text, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/ouro-mcp-app.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}