import { Form, useLoaderData } from "react-router"; import type { LoaderFunctionArgs } from "react-router"; import { FeatherAlertTriangle } from "@subframe/core"; import { FeatherEye, FeatherPencil } from "@subframe/core"; import { describeMcpScope, resolveMcpClientIcon } from "@hivegrid/view-models"; import { requireUserId, getUserInfo } from "~/utils/session.server"; import { McpOAuthError, resolveAuthorizeRequest, type McpOAuthAuthorizeRequest } from "~/services/mcp/oauth.server"; import { getTranslations } from "~/locale/i18next.server"; import { loadRequiredWebConfig } from "@hivegrid/config"; import { AuthShell, AuthStatus } from "~/components/auth/AuthShell"; import { ClientIcon } from "~/components/mcp/ClientIcon"; import { Button } from "~/ui/components/Button"; type AuthorizeLabels = { errorTitle: string; title: string; description: string; scopesHeading: string; revokeHint: string; approve: string; deny: string; }; export async function loader({ request }: LoaderFunctionArgs) { const requestUrl = new URL(request.url); const userId = await requireUserId(request, `${requestUrl.pathname}${requestUrl.search}`); const { t } = await getTranslations(request); const appName = loadRequiredWebConfig().appName; try { const resolved = await resolveAuthorizeRequest(requestUrl, userId); const userInfo = await getUserInfo(request); const labels: AuthorizeLabels = { errorTitle: t("mcp.oauth.authorize.errorTitle"), title: t("mcp.oauth.authorize.title", { appName }), description: t("mcp.oauth.authorize.description", { clientName: resolved.client.clientName, tenantName: resolved.tenant.name }), scopesHeading: t("mcp.oauth.authorize.scopesHeading"), revokeHint: t("mcp.oauth.authorize.revokeHint", { appName }), approve: t("mcp.oauth.authorize.approve"), deny: t("mcp.oauth.authorize.deny"), }; // Same brand-mark derivation the connect dialog uses, so the client the // user is about to approve looks the same here as it does afterwards. const clientIcon = resolveMcpClientIcon(resolved.client.clientName); // Every requested scope still gets its own row — the consent has to stay // complete. Each carries a plain-language label where we have one; the raw // scope stays visible underneath so nothing is paraphrased away. const scopeRows = resolved.scopes.map((scope) => { const described = describeMcpScope(scope); return { ...described, label: described.labelKey ? t(described.labelKey) : null }; }); return Response.json({ ...resolved, csrf: userInfo.csrf ?? "", clientIcon, scopeRows, labels }); } catch (error) { if (error instanceof McpOAuthError) { return Response.json( { error: error.error, errorDescription: error.description, labels: { errorTitle: t("mcp.oauth.authorize.errorTitle") } }, { status: error.status }, ); } throw error; } } type ScopeRow = { scope: string; labelKey: string | null; label: string | null; write: boolean }; type AuthorizeData = McpOAuthAuthorizeRequest & { csrf: string; clientIcon: string; scopeRows: ScopeRow[]; labels: AuthorizeLabels }; type AuthorizeError = { error: string; errorDescription: string; labels: { errorTitle: string } }; export default function McpOAuthAuthorizeRoute() { const data = useLoaderData(); if ("error" in data) { return ( } tone="negative" title={data.labels.errorTitle} message={data.errorDescription} dataUiId="ui.mcp.oauth.authorize.error" /> ); } return (
{data.client.clientName} {data.tenant.name}
{data.labels.scopesHeading}
    {data.scopeRows.map((row) => (
  • svg]:h-full [&>svg]:w-full ${row.write ? "text-icon-feedback-warning" : "text-icon-neutral-secondary"}`}> {row.write ? : }
    {row.label ? ( {row.label} ) : null} {/* The raw scope stays on screen even when a label exists: it is what actually gets granted, and an unlabelled scope must never look like it was silently dropped. */} {row.scope}
  • ))}
{data.state ? : null} {/* `neutral` is remapped to the same solid black as `primary` in globals.css, so the decline action needs the outlined variant to read as the secondary choice. */}

{data.labels.revokeHint}

); }