Repository navigation
Conversation
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.
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional
prefersContrastfield toHostContextso hosts can tell Views the user's contrast preference, as discussed in #431.Why
A View's own
prefers-contrastmedia 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 (unlikeprefers-color-scheme, which a host can set withcolor-schemeon the iframe). Electron hosts also don't pass the operating system setting through (electron/electron#55917).HostContextis the one channel that reaches Views in every host.What
prefersContrast?: "no-preference" | "more" | "less", separate fromtheme, with values mirroring the CSSprefers-contrastmedia feature.customis left out, as innavigator.preferences.contrast, because it's tied to forced colors, which the browser already applies to the View directly."more"), omit the field when the preference is unknown, and sendstyles.variablesthat already reflect the preference.McpUiContrastPreferencetype andMcpUiContrastPreferenceSchema, 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
preferencesobject.host-context-changedis 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.theme. Forward compatibility for closedHostContextfields (an unrecognized value currently failsui/initializein SDK-based Views) affects every field, so I've kept this consistent with the existing ones rather than deciding it here.basic-hostchange and a View-side helper likeapplyDocumentTheme. Both are easy follow-ups if you'd like them.HostContextand in-frame media queries): https://github.com/schne324/mcp-apps-a11y-probe