Skip to content

Conversation

@jonathanhefner
Copy link
Member

Apply host-provided safe area insets as padding on main containers across all examples. This ensures content doesn't render under system UI elements like phone notches.

React apps use useState + onhostcontextchanged handler with initial fetch via getHostContext() in useEffect. Vanilla JS apps apply padding in the handler and invoke it after connect().

🤖 Generated with Claude Code

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/ext-apps/@modelcontextprotocol/ext-apps@202

commit: 2453b0c

// Connect to host
app.connect();
app.connect().then(() => {
const ctx = app.getHostContext();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this behavior (triggerring the onhostcontextchanged with the initial host context) be part of the connect flow?

Copy link
Member Author

@jonathanhefner jonathanhefner Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, it merely sets this._hostContext (does not trigger onhostcontextchanged):

ext-apps/src/app.ts

Lines 1029 to 1069 in 38126f7

override async connect(
transport: Transport = new PostMessageTransport(window.parent),
options?: RequestOptions,
): Promise<void> {
await super.connect(transport);
try {
const result = await this.request(
<McpUiInitializeRequest>{
method: "ui/initialize",
params: {
appCapabilities: this._capabilities,
appInfo: this._appInfo,
protocolVersion: LATEST_PROTOCOL_VERSION,
},
},
McpUiInitializeResultSchema,
options,
);
if (result === undefined) {
throw new Error(`Server sent invalid initialize result: ${result}`);
}
this._hostCapabilities = result.hostCapabilities;
this._hostInfo = result.hostInfo;
this._hostContext = result.hostContext;
await this.notification(<McpUiInitializedNotification>{
method: "ui/notifications/initialized",
});
if (this.options?.autoResize) {
this.setupSizeChangedNotifications();
}
} catch (error) {
// Disconnect if initialization fails.
void this.close();
throw error;
}
}

Copy link
Collaborator

@liady liady Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanhefner yes, that’s what I meant - I see in the examples that onhostcontextchanged is explicitly triggered from within the connect callback. Do we want this to be part of the connect logic itself in the SDK, rather than requiring developers to remember to call it manually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to that, but my interpretation was that this behavior was intentional — onhostcontextchanged would only be called in response to ui/notifications/host-context-changed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd keep its current behaviour to mean explicitly ui/notifications/host-context-changed happened for now.

app.connect().then(() => {
const ctx = app.getHostContext();
if (ctx) {
app.onhostcontextchanged(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no such getter actually

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, good catch! TIL this is a known limitation of TypeScript: microsoft/TypeScript#295.

I've updated the commit to use an explicit handler function instead.

Apply host-provided safe area insets as padding on main containers
across all examples. This ensures content doesn't render under
system UI elements like phone notches.

React apps use `useState` + `onhostcontextchanged` handler with
initial fetch via `getHostContext()` in `useEffect`. Vanilla JS
apps apply padding in the handler and invoke it after `connect()`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ochafik ochafik merged commit 79670b4 into modelcontextprotocol:main Jan 8, 2026
14 of 15 checks passed
@ochafik ochafik mentioned this pull request Jan 9, 2026
ochafik added a commit that referenced this pull request Jan 9, 2026
Merge latest changes from main including:
- Vue, Svelte, Preact, and Solid basic server examples (#141)
- safeAreaInsets support (#202)
- E2E test fixes (#206)
- npm publishing for examples (#184)
- ui.resourceUri optional (#210)
- Method names as consts (#192)
- toolInfo.id optional (#216)
- PostMessageTransport security fixes (#207, #208)
- Server-utils.ts refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants