Skip to main content
MCP Apps SDK The host tells your View the user’s language and time zone during the 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 after connect() and merge later changes:
In the sunpeak framework, 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 keep structuredContent 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:
  1. From the View. Pass the locale as an argument to callServerTool(). This works for follow-up calls the View makes.
  2. From the model. Add an optional locale property 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.
Do not trust a locale argument for anything beyond formatting and content selection. It comes from the View or the model, so treat it like any other untrusted tool input.

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:
Bundling avoids extra network requests. If you load catalogs at runtime from another origin, list that origin in the resource’s _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

Set dir="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.
Use CSS logical properties (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 sends locale 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-changed notification, which also checks that your View handles a change after load. The inspector saves these values for later sessions.
  • URL. Add ?locale=ar-EG to the inspector URL to start in that locale.
  • E2E tests. Pass locale as a render option. The inspector fixture forwards extra options as URL parameters.
The inspector has no time zone URL parameter. Its default time zone is the inspector page’s own, and test runs skip saved sidebar values, so Playwright’s 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 locale and timeZone from 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 lang and dir on 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.