ui/initialize handshake. Two optional fields on McpUiHostContext carry them:
Both fields are optional in the MCP Apps
2026-01-26 specification, so a host may omit either one. The host can also change them later with a ui/notifications/host-context-changed notification, which sends only the fields that changed.
Read locale and time zone
With the vanilla SDK, read the values afterconnect() and merge later changes:
useLocale() and useTimeZone() re-render the component when the host context changes. useLocale() falls back to "en-US". useTimeZone() falls back to the time zone of the browser running the View.
Guard against bad values
The host sends plain strings.Intl constructors throw a RangeError for a malformed language tag or an unknown time zone, and one bad value can crash the whole View. Check both values once and fall back:
useLocale() and useTimeZone() return the host value as-is, so wrap them with these helpers if a host or test might send an invalid string.
Send raw values from the server, format in the View
Your MCP server does not receive the host context. Tool calls carry only the arguments the model or View sends. So keepstructuredContent locale-neutral and let the View format it:
Pre-formatted strings such as
"Nov 19, 2:30 PM" lock the View into one language and one time zone, and the model can misread them on the next turn.
The content text you return is for the model, not the user. The model writes its reply in the user’s language on its own, so plain English text in content works fine. Keep it factual and unambiguous, and use the same ISO formats there.
When the server needs the locale
Some tools need the locale on the server, for example to search a localized catalog or to build a PDF. Two ways to get it there:-
From the View. Pass the locale as an argument to
callServerTool(). This works for follow-up calls the View makes. -
From the model. Add an optional
localeproperty to the tool’s input schema with a description such as"BCP 47 tag for the user's language, for example de-DE". The model fills it from the conversation. Validate it on the server and fall back to a default, because the model can omit it or guess wrong.
Translate UI strings
The host does not translate your View. Ship message catalogs inside the resource bundle and pick one by locale, falling back from the full tag to the language and then to your default:_meta.ui.csp.connectDomains, or the host’s CSP blocks the request. Hosts may also cache the resource HTML, so a catalog fix in a separately hosted file can reach users before a new bundle does, which is worth keeping in mind when you version strings.
Keep strings short. Inline Views are small, and German or Finnish labels often run much longer than English ones. Test them at narrow container widths.
Right-to-left languages
Setdir="rtl" for Arabic, Hebrew, Persian, Urdu, and other right-to-left scripts. Set lang too, so screen readers pick the right voice, as described in the accessibility guide.
margin-inline-start, padding-inline-end, inset-inline-start, text-align: start) instead of left and right, so the layout flips without a second stylesheet. Tailwind’s ms-*, me-*, ps-*, pe-*, start-*, and end-* utilities map to these properties. Icons that show direction, such as back arrows and carousel chevrons, need to flip as well.
The host chrome around your iframe follows the host’s own language setting. Your View only controls its own document.
Test locales and time zones
The sunpeak inspector sendslocale and timeZone in the host context, so you can check a View without changing your OS settings:
- Sidebar. Edit the Locale and Time Zone fields. The inspector sends a
host-context-changednotification, which also checks that your View handles a change after load. The inspector saves these values for later sessions. - URL. Add
?locale=ar-EGto the inspector URL to start in that locale. - E2E tests. Pass
localeas a render option. Theinspectorfixture forwards extra options as URL parameters.
timezoneId option controls the timeZone your View receives in tests.
Add a visual regression screenshot for one right-to-left locale and one long-string locale such as de-DE. Those two cases catch most layout breaks.
Checklist
- Read
localeandtimeZonefrom host context and handle later changes. - Validate both values before passing them to
Intl. - Send ISO timestamps, minor-unit amounts, and currency codes from the server. Format in the View.
- Pass the locale to server tools explicitly when the server needs it.
- Bundle translations, or allow their origin in
connectDomains. - Set
langanddiron the document root and use logical CSS properties. - Test at least one non-English, one right-to-left, and one non-local time zone case.
Related
getHostContext()for every host context fieldonhostcontextchangedfor partial context updatesuseLocaleanduseTimeZonein the sunpeak framework- Accessibility and Layout for the rest of the View’s environment