Skip to main content
sunpeak API

Overview

The useLocale hook returns the user’s locale string from the host. It is a convenience wrapper around useHostContext.

Wraps onhostcontextchanged

MCP Apps SDK reference

Import

Signature

Returns

string
BCP 47 locale string (e.g., 'en-US'). Defaults to 'en-US' when unavailable.

Usage

The locale value comes from McpUiHostContext.locale. The hook re-renders when the host sends a host-context-changed notification. It returns the host’s string without validation, so an invalid value makes Intl constructors throw a RangeError. See MCP App Localization for validation helpers, right-to-left handling, and inspector testing.