Skip to content

Commit edbe4f5

Browse files
antonpk1claude
andcommitted
docs: add styles field to MCP Apps specification
- Add styles field to HostContext interface with reference to Theming section - Add Theming section documenting 36 standardized CSS variables - Document Host/App behavior for theming including light-dark() usage - Add Design Decision #4 explaining CSS variables approach - Include JSON example showing light-dark() pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f8c0ffa commit edbe4f5

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

specification/draft/apps.mdx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ interface HostContext {
401401
};
402402
/** Current color theme preference */
403403
theme?: "light" | "dark";
404+
/** CSS variables for theming. See Theming section for standardized variable names. */
405+
styles?: Record<string, string>;
404406
/** How the UI is currently displayed */
405407
displayMode?: "inline" | "fullscreen" | "pip";
406408
/** Display modes the host supports */
@@ -437,6 +439,8 @@ interface HostContext {
437439

438440
All fields are optional. Hosts SHOULD provide relevant context. Guest UIs SHOULD handle missing fields gracefully.
439441

442+
For `styles`, apps SHOULD provide CSS fallback values (e.g., `var(--color-text-primary, #171717)`) to handle hosts that don't supply styles.
443+
440444
Example:
441445

442446
```json
@@ -450,13 +454,64 @@ Example:
450454
"hostInfo": { "name": "claude-desktop", "version": "1.0.0" },
451455
"hostContext": {
452456
"theme": "dark",
457+
"styles": {
458+
"--color-background-primary": "light-dark(#ffffff, #171717)",
459+
"--color-text-primary": "light-dark(#171717, #fafafa)",
460+
"--font-family-sans": "system-ui, sans-serif"
461+
},
453462
"displayMode": "inline",
454463
"viewport": { "width": 400, "height": 300 }
455464
}
456465
}
457466
}
458467
```
459468

469+
### Theming
470+
471+
Hosts pass CSS custom properties via `HostContext.styles` for visual cohesion with the host environment.
472+
473+
#### Standardized Variables
474+
475+
| Category | Variables |
476+
|----------|-----------|
477+
| Background | `--color-background-primary`, `--color-background-secondary`, `--color-background-tertiary`, `--color-background-inverted` |
478+
| Text | `--color-text-primary`, `--color-text-secondary`, `--color-text-tertiary`, `--color-text-inverted` |
479+
| Icons | `--color-icon-primary`, `--color-icon-secondary`, `--color-icon-tertiary`, `--color-icon-inverted` |
480+
| Borders | `--color-border-primary`, `--color-border-secondary` |
481+
| Accents | `--color-accent-info`, `--color-accent-danger`, `--color-accent-success`, `--color-accent-warning` |
482+
| Font Family | `--font-family-sans` |
483+
| Font Sizes | `--font-size-heading`, `--font-size-body`, `--font-size-caption` |
484+
| Font Weights | `--font-weight-regular`, `--font-weight-emphasized` |
485+
| Line Heights | `--font-leading-regular`, `--font-leading-tight` |
486+
| Composite Styles | `--font-style-heading`, `--font-style-body`, `--font-style-body-emphasized`, `--font-style-caption`, `--font-style-caption-emphasized` |
487+
| Border Radius | `--border-radius-small`, `--border-radius-medium`, `--border-radius-large`, `--border-radius-full` |
488+
| Border Width | `--border-width-regular` |
489+
490+
#### Host Behavior
491+
492+
- Hosts MAY provide any subset of standardized variables
493+
- Hosts MAY use CSS `light-dark()` function for theme-aware values
494+
- `theme` indicates the active mode; `styles` provides the concrete CSS values
495+
496+
#### App Behavior
497+
498+
- Apps SHOULD use fallback values for CSS variables: `var(--color-text-primary, #171717)`
499+
- This ensures graceful degradation when hosts omit `styles` or specific variables
500+
- When the host uses `light-dark()` values, apps MUST set `color-scheme` on their document:
501+
```css
502+
:root { color-scheme: light dark; }
503+
```
504+
505+
Example CSS:
506+
507+
```css
508+
.container {
509+
background: var(--color-background-primary, #ffffff);
510+
color: var(--color-text-primary, #171717);
511+
font: var(--font-style-body, 400 16px/1.4 system-ui);
512+
}
513+
```
514+
460515
### MCP Apps Specific Messages
461516

462517
MCP Apps introduces additional JSON-RPC methods for UI-specific functionality:
@@ -1046,6 +1101,24 @@ This proposal synthesizes feedback from the UI CWG and MCP-UI community, host im
10461101
- **Include external URLs in MVP:** This is one of the easiest content types for servers to adopt, as it's possible to embed regular apps. However, it was deferred due to concerns around model visibility, inability to screenshot content, and review process.
10471102
- **Support multiple content types:** Deferred to maintain a lean MVP.
10481103

1104+
#### 4. Host Theming via CSS Variables
1105+
1106+
**Decision:** Provide a standardized set of CSS custom properties for visual cohesion.
1107+
1108+
**Rationale:**
1109+
1110+
- CSS variables are universal, framework-agnostic, and require no runtime
1111+
- Apps apply styles via `var(--name)` with fallbacks for graceful degradation
1112+
- Limited variable set (colors, typography, borders) ensures hosts can realistically provide all values
1113+
- Spacing intentionally excluded—layouts break when spacing varies from original design
1114+
- No UI component library—no single library works across all host environments
1115+
1116+
**Alternatives considered:**
1117+
1118+
- **Full design system:** Rejected as too prescriptive; hosts have different aesthetics
1119+
- **Inline styles in tool results:** Rejected; separating theming from data enables caching and updates
1120+
- **CSS-in-JS injection:** Rejected; framework-specific and security concerns with injected code
1121+
10491122
### Backward Compatibility
10501123

10511124
The proposal builds on the existing core protocol. There are no incompatibilities.

0 commit comments

Comments
 (0)