Skip to content

feat: add hostContext.prefersContrast - #875

Draft
schne324 wants to merge 2 commits into
modelcontextprotocol:mainfrom
schne324:feat/prefers-contrast
Draft

schne324 wants to merge 2 commits into
modelcontextprotocol:mainfrom
schne324:feat/prefers-contrast

Conversation

@schne324

@schne324 schne324 commented Nov 24, 2026 •

Copy link
Copy Markdown

Adds an optional prefersContrast field to HostContext so hosts can tell Views the user's contrast preference, as discussed in #431.

Why

A View's own prefers-contrast media query only reflects the browser and operating system. It can't see contrast settings that live in the host, such as VS Code's High Contrast themes, and there's no way for a host to override it for an iframe (unlike prefers-color-scheme, which a host can set with color-scheme on the iframe). Electron hosts also don't pass the operating system setting through (electron/electron#55917). HostContext is the one channel that reaches Views in every host.

What

  • prefersContrast?: "no-preference" | "more" | "less", separate from theme, with values mirroring the CSS prefers-contrast media feature. custom is left out, as in navigator.preferences.contrast, because it's tied to forced colors, which the browser already applies to the View directly.
  • Host behavior: determine the value from both host and operating system settings (a host high contrast theme means "more"), omit the field when the preference is unknown, and send styles.variables that already reflect the preference.
  • View behavior: prefer the field over the media query when present, and fall back to the media query when absent.
  • A note on what the field reveals to Views, and that hosts can omit it.
  • McpUiContrastPreference type and McpUiContrastPreferenceSchema, regenerated schemas, and tests.

Following the scope suggested in #431, this PR covers contrast only. Reduced motion and text scale can follow separately.

Notes for reviewers

  • Flat field rather than a preferences object. host-context-changed is shallow-merged into the View's context, so a nested object would force every partial update to resend all of its sibling fields or wipe them. Reduced motion and text scale would be added the same way, as sibling fields.
  • Closed set of values, like theme. Forward compatibility for closed HostContext fields (an unrecognized value currently fails ui/initialize in SDK-based Views) affects every field, so I've kept this consistent with the existing ones rather than deciding it here.
  • Not included: a basic-host change and a View-side helper like applyDocumentTheme. Both are easy follow-ups if you'd like them.
  • The probe MCP App from Accessibility #431 shows what a View receives today (its HostContext and in-frame media queries): https://github.com/schne324/mcp-apps-a11y-probe

Adds an optional prefersContrast field ("no-preference" | "more" | "less") to HostContext, separate from theme. Views treat unrecognized values as "no-preference", and the schema accepts them so new values don't fail ui/initialize. Refs modelcontextprotocol#431.
Keep prefersContrast a closed set like theme, revert the generator change, relate it to styles.variables, add a privacy note, and drop non-interoperability requirements.
@schne324 schne324 mentioned this pull request Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant