HomeAPIinjectHostContext

injectHostContext

One readonly signal for each raw host-context key. The low-level escape hatch.

injectHostContext(): HostContextSignals
createHostContextSignals(adaptor: Adaptor): HostContextSignals

injectHostContext() gives you one readonly signal for each key that the host exposes. The typed wrappers are all derived from it.

import { injectHostContext } from "ng-mcp-ui/web";

const host = injectHostContext();
host.theme();        // "light" | "dark"
host.toolOutput();   // Record<string, unknown> | null

Prefer the typed wrappers. Read this directly only when a key has no wrapper, or when you want several keys at once without several calls.

The keys

Key Type Wrapper
theme Theme injectLayout
maxHeight number | undefined injectLayout
safeArea SafeArea injectLayout
locale string injectUser
userAgent UserAgent injectUser
displayMode DisplayMode injectDisplayMode
display { mode, params? } injectRequestModal
toolInput Record<string, unknown> | null injectToolInfo
toolOutput Record<string, unknown> | null injectToolInfo
toolResponseMetadata Record<string, unknown> | null injectToolInfo
viewState Record<string, unknown> | null injectViewState

destroy

The returned object also has a destroy() method. It removes each host subscription.

Inside an injection context the cleanup runs for you through DestroyRef. Call destroy() yourself only when you used createHostContextSignals.

createHostContextSignals

The non-DI form. Pass an adaptor directly.

const signals = createHostContextSignals(adaptor);
// …
signals.destroy();

Use it in code that already holds an adaptor, for example a plain unit test with a MockAdaptor.

Host support

Each key works on the two host runtimes. The values differ, because each adaptor maps them from a different host API.