-
Notifications
You must be signed in to change notification settings - Fork 53
Add safeAreaInsets support to all example apps
#202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add safeAreaInsets support to all example apps
#202
Conversation
commit: |
| // Connect to host | ||
| app.connect(); | ||
| app.connect().then(() => { | ||
| const ctx = app.getHostContext(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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):
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; | |
| } | |
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
79908d8 to
2453b0c
Compare
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+onhostcontextchangedhandler with initial fetch viagetHostContext()inuseEffect. Vanilla JS apps apply padding in the handler and invoke it afterconnect().🤖 Generated with Claude Code