mcp-ui-css
Guide for authoring CSS in packages/mcp-ui (the MCP Apps views): native stylesheets organized in cascade layers, specificity capped with :where(), colours from Studio's semantic tokens (bridged from the host's MCP Apps style variables), and fonts and radii from the host's variables. Use when adding or editing any .css file, className, data-slot, data-state or data-tone in packages/mcp-ui, or when adding a view.
MCP UI CSS
Reference implementation: packages/mcp-ui/src/shared/base.css and the component files beside it (badge.css, copy-field.css, …).
Each view is a single-file HTML document that a host (Claude, ChatGPT, an IDE) renders in an iframe inside its own UI. Two consequences shape every rule here:
- The host owns the look. It sends a theme, fonts and a set of standard style variables. A view that ignores them looks foreign inside the host. Supabase's own design values are only a fallback for hosts that send nothing. Colours reach components as Studio's semantic tokens, so the components can move into Studio unchanged (see Host theming).
- Views multiply. Views share the same rules, so a selector that wins by weight or by source order today breaks someone else's view later. Layers and
:where()keep every rule trivially overridable.
We stay close to the platform: plain CSS, native nesting, custom properties, @layer, :where(), logical properties. No Tailwind, no CSS-in-JS, no preprocessors, no utility-class styling.
Three primary patterns
1. Every rule lives in a layer
@layer base, native, components, view, utilities;
The statement lives only in src/shared/base.css, which holds base, native and utilities. Every view's main.tsx imports base.css as its first import, so the order is fixed before any other layered rule loads. Other CSS files do not repeat the statement.
Each shared component keeps its components rules in src/shared/<component>.css, named after its class (badge.css for .badge), and the TSX file that renders it imports that CSS (import './badge.css';). A view only ships the CSS of the components it imports, so a view that never imports CopyField never carries .copy-field's rules. A file has at most one block per layer, and a class is styled in only one file: the order of components rules across files follows import order and can differ between views. Where several TSX files render the same markup, each imports the CSS. Button variants (data-size, .primary) have no component of their own: they live in button.css, imported by each TSX file that renders a variant.
Later layers win over earlier ones regardless of specificity, so never reach for !important or a heavier selector to override across layers.
| Layer | Purpose | Max specificity |
|---|---|---|
base | Tokens on the root, root and body typography, safe-area padding, the focus ring, @keyframes | Zero: wrap everything in :where() |
native | Bare HTML elements (button, a, code, p) | A single element selector |
components | Shared components and their parts; class variants of native elements | At most a single element; usually zero |
view | Overrides for one view, under its wrapper class | A single class selector (the view wrapper) |
utilities | The few single-purpose classes that must win over everything, wherever they are used | Zero: :where(.class) |
2. Cap specificity per layer; everything past the cap goes in :where()
base::where(:root),:where(body),:where(:focus-visible).native: a bare element selector. States go inside:where()so the rule stays at one element:&:where(:hover:not(:disabled)),&:where(:disabled)(not:where(&:disabled), which drops to zero specificity and loses to the bare element).- One exception: a link that looks like a button (
<a class="button">) shares the native button rule through a selector list,:is(button, a:where(.button)).:is()takes its heaviest argument, so it stays at one element. Button variants use the same list (:is(button, a:where(.button)):where(.primary)), and the text-link rule excludes it (a:where(:not(.button))) so neither depends on source order. Plain CSS has no mixins; a selector list is how two selectors share one set of styles. Don't copy button declarations into a separate link rule.
- One exception: a link that looks like a button (
components: wrap the class in:where()::where(.badge). A variant of an element is element plus:where(.class):button:where(.primary)(written:is(button, a:where(.button)):where(.primary)so button-styled links get it too). Parts and states nested inside also use:where().view: at most one class, chosen by the view; everything nested uses:where().utilities::where(.sr-only). It is the last layer, so it wins without any specificity.- Never chain classes, never use ids, never nest without
:where()(a nestedcodeinside.xbecomes.x codeand raises specificity).
@layer components {
:where(.badge) {
color: var(--sb-color-muted-foreground);
&:where([data-tone="danger"]) {
color: var(--sb-color-destructive);
}
}
:where(.copy-field) {
display: flex;
flex-direction: column;
gap: var(--sb-space-1);
:where([data-slot="control"] [data-slot="value"]) {
flex: 1;
min-inline-size: 0;
}
}
}
A variant restates every state of a property it changes. button:where(.primary) sets background, so it needs its own hover and its own &:where(:disabled). Otherwise its background, sitting in a later layer, overrides the native button's disabled background.
3. A view's own styles go in its view.css, in the view layer
Most views need no CSS of their own. When one does, create src/views/<view>/view.css, import it in that view's main.tsx after base.css, and put its rules in @layer view. A view ships only its own CSS, so its rules apply on that view alone; it needs no wrapper element and chooses its own selectors, within the layer's cap. The view layer comes after components, so its rules win without extra specificity. Custom properties it declares are namespaced --sb-view-<view>-*.
@layer view {
:where(.project-card) {
:where([data-slot="header"]) {
align-items: center;
}
}
}
If a second view needs the same piece, move it to a component: a src/shared/<component>.css in components, imported by the component's TSX.
The utilities layer is for rules that must always win
utilities sits above view so that nothing a component or a view declares can undo it. It holds one class today, .sr-only: content hidden visually but read by screen readers has to stay hidden whatever else styles that element.
It is not a place for layout or colour helpers (.row, .stack, .text-muted); those belong in a component rule. Add a class here only when all of these hold: it does one thing, it is correct on any element, and a component or view overriding it would be a bug. Expect this layer to stay nearly empty.
Host theming
The SDK's useHostStyles writes the host's style variables as inline styles on <html>, sets data-theme and an inline color-scheme, and injects the host's font faces. Inline styles beat any stylesheet declaration in any layer.
Colours go through one more step, because these components will move into Studio and because hosts disagree about what each MCP Apps colour variable means (Claude's --color-border-primary is a strong 40% line, Codex's is a control outline; Claude's --color-background-primary is its raised white surface, Codex's is the app surface). Components use Studio's semantic tokens, and a host bridge at the top of base maps the host's variables onto them. The table and the reasons for each choice are in the bridge's comment in base.css.
- Colours: Studio's semantic tokens only.
--sb-color-foreground,--sb-color-muted-foreground,--sb-color-tertiary-foreground,--sb-color-background,--sb-color-foreground-contrast,--sb-color-card,--sb-color-muted,--sb-color-border,--sb-color-input,--sb-color-ring,--sb-color-primary,--sb-color-warning,--sb-color-destructiveand the status borders--sb-color-border-primary-bright,--sb-color-border-warningand--sb-color-border-destructive: Studio's core names (inpackages/ui/build/css/source/semantic.cssin the supabase monorepo) behind the--sb-color-prefix. Never the legacy names incompat.css(--background-surface-*,--foreground-light,--border-muted,--brand-*), and never a host--color-*variable outside the bridge:pnpm lint:cssfails on that, and on any--sb-color-*declared outsidebase.css. - The bridge is the only place a host colour is read. Each
--sb-color-*token isvar(<host variable>, <fallback>)on:where(:root)inbase.pnpm lint:csschecks each host name it reads, and each host variablebasedeclares a fallback for, againstMcpUiStyleVariableKeyin ext-apps'schema.json, so a misspelt name fails instead of silently leaving the fallback in place. To use a new Studio token, add it to the bridge with the host variable that means the same thing in every host (check what Claude and Codex send, not just the name), or derive it there. - Fallback values come from the Supabase design system (
packages/ui/build/cssin the supabase monorepo). They apply only where the host sends nothing. - Derive as Studio derives. Status tints and borders are the status colour at 10% and 30% (
color-mix(in oklab, var(--sb-color-warning) 10%, transparent)), not the host's status borders. Disabled controls fade withopacity, as Studio's do. - Everything else that isn't a colour uses the host's variables directly:
--font-sans,--font-mono,--font-weight-*,--font-text-{xs,sm,md,lg}-{size,line-height},--border-radius-*,--border-width-regular. Their fallbacks live once inbase: never writevar(--x, fallback)elsewhere, except a read of another component's--sb-component-<component>-*property (see Local tokens). A literal colour or font size innative,componentsorviewis a bug. The full list of host names is theMcpUiStyleVariableKeytype innode_modules/@modelcontextprotocol/ext-apps/dist/src/spec.types.d.ts. - Dark mode is
light-dark()inbaseand nothing else. The root declarescolor-scheme: light dark; the host's theme overrides it inline;light-dark()follows. Never select on[data-theme]orprefers-color-schemeto change a colour. - Keep the body background transparent. The host's surface shows through.
- Fonts are the host's or the system's. Do not load font files; the views ship as one small HTML file with no network access.
Local tokens
Where the host standard has no variable, use a local token prefixed --sb-. The prefix keeps local names from colliding with host names added later, so never name a local token --color-*, --font-*, --border-* or --shadow-*. Studio's semantic colour tokens (--sb-color-border, --sb-color-card, …) are not local tokens: they keep Studio's names behind the --sb-color- prefix, which only base.css may declare, so components can move there by dropping the prefix.
-
--sb-space-1to--sb-space-4(4px, 8px, 12px, 16px): the host standard has no spacing scale. Use these for gaps and padding; a one-off size may stay literal. -
--sb-inset-top,-right,-bottom,-left: the host's safe-area insets, set from JS insrc/shared/use-host-styles.ts. -
--sb-skeleton-background,--sb-skeleton-animation: a skeleton placeholder's colour and pulse.basesets the animation tononeunderprefers-reduced-motion, so a skeleton needs no media query. Any skeleton uses them (background: var(--sb-skeleton-background); animation: var(--sb-skeleton-animation);) instead of writing its own colour or animation. -
--sb-component-<component>-*: a custom property that belongs to one component, named after the component's CSS file, which is also the class it owns (--sb-component-project-card-radiusinproject-card.css; a view'sview.cssuses--sb-view-<view>-*). Declare it on the component's rule, in any layer; it needs no fallback inbase. A file may declare only its own namespace.--sb-component-and--sb-view-are reserved:base.cssdeclares none, and a name under them that matches no file is an error, so a global token can never be mistaken for a component's. The linter resolves a name to the longest matching file name, soprojectandproject-cardcan coexist. A file reads its own namespace with no fallback, and the property must be declared in that same file. -
Reading another component's namespace needs a fallback:
var(--sb-component-project-card-radius, var(--border-radius-lg)).connection-details.cssaligns with the card it sits in this way. A view can shipconnection-details.csswithoutproject-card.css, and without the fallback the read would be invalid there. This is the one place outsidebasewhere avar()fallback is allowed, and there it is required. Write the fallback with the global tokens the owner declares its property with, so the component looks right on its own, or a zero where the property is a padding that margins cancel. The linter also fails if the property is not declared in the other component's file, which catches typos and stale names.
Add a local token when a value is reused or carries meaning. Do not add one for a single use.
Markup
- One component class per element. No class stacks (
card card-body stack) and no styling by utility classes. The only class that may be added alongside a component class is one from theutilitieslayer. - A class names a component;
data-slotnames a part. A component stands alone and can be placed anywhere (.badge,.icon); it gets a class, its own top-level rule incomponents, and its own React component. A part only exists inside one component (the title row or the note of.project-card); it getsdata-slot, never a class, and is styled nested in its component::where(.project-card) { :where([data-slot="note"]) { … } }. A part can still carry state:<div data-slot="note" data-tone="danger">. - Every
data-slotrule is nested inside its component's rule. A bare:where([data-slot="…"])at the top of a layer is global: it matches that slot name in every component. If something is styled the same wherever it appears, it is a component and needs a class. - Qualify a part by its parent part when the parent gives it its meaning. A part with a generic name (
name,retry,note-text) or one that is a piece of a group (onedetailof thedetails) is selected through the part it belongs to, inside one:where()::where([data-slot="title-row"] [data-slot="name"]). The selector then says what the part is for, and it reads like the markup. Go up one level only, not the full path, so restructuring the markup above that parent doesn't break the rule. Parts that name a section of the component on their own (header,details,note) and parts used in several places (skeleton) stay unqualified.:where()keeps the added level at zero specificity. - Never nest one component's rule inside another's. If a component needs to look different in one place, that is a
viewoverride or a variant attribute on the component. - State and tone use attributes, not modifier classes:
data-state="failed",data-tone="success" | "warning" | "danger", or the ARIA attribute where one exists (aria-busy,aria-current). Tone names aresuccess,warninganddanger; the CSS maps them to--sb-color-primary,--sb-color-warningand--sb-color-destructive. - Target the part, not the tag. Avoid descendant selectors on bare tags (
svg,p,span) inside a component; they style content added later by accident. - No inline
styleprops, except custom properties set from JS for values CSS cannot know. - Class names are kebab-case.
Secondary patterns
- Logical properties:
padding-block,margin-inline,min-inline-size,border-block-end. - Layout: flex or grid with
gap; avoid sibling margins.
이 스킬의 파일
이 스킬에는 보조 파일이 없습니다.