Skip to content

Commit d61b5ab

Browse files
Merge pull request #351 from jonathanhefner/no-onhostcontextchanged-getter
Fix `onhostcontextchanged` handler invocation in examples
2 parents 040ba82 + def96b3 commit d61b5ab

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

examples/sheet-music-server/src/mcp-app.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file Sheet Music App - renders ABC notation with abcjs and provides audio playback
33
*/
4-
import { App } from "@modelcontextprotocol/ext-apps";
4+
import { App, type McpUiHostContext } from "@modelcontextprotocol/ext-apps";
55
import ABCJS from "abcjs";
66
import "abcjs/abcjs-audio.css";
77
import "./global.css";
@@ -109,18 +109,20 @@ app.ontoolinput = (params) => {
109109

110110
app.onerror = console.error;
111111

112-
app.onhostcontextchanged = (params) => {
113-
if (params.safeAreaInsets) {
114-
mainEl.style.paddingTop = `${params.safeAreaInsets.top}px`;
115-
mainEl.style.paddingRight = `${params.safeAreaInsets.right}px`;
116-
mainEl.style.paddingBottom = `${params.safeAreaInsets.bottom}px`;
117-
mainEl.style.paddingLeft = `${params.safeAreaInsets.left}px`;
112+
function handleHostContextChanged(ctx: McpUiHostContext) {
113+
if (ctx.safeAreaInsets) {
114+
mainEl.style.paddingTop = `${ctx.safeAreaInsets.top}px`;
115+
mainEl.style.paddingRight = `${ctx.safeAreaInsets.right}px`;
116+
mainEl.style.paddingBottom = `${ctx.safeAreaInsets.bottom}px`;
117+
mainEl.style.paddingLeft = `${ctx.safeAreaInsets.left}px`;
118118
}
119-
};
119+
}
120+
121+
app.onhostcontextchanged = handleHostContextChanged;
120122

121123
app.connect().then(() => {
122124
const ctx = app.getHostContext();
123125
if (ctx) {
124-
app.onhostcontextchanged(ctx);
126+
handleHostContextChanged(ctx);
125127
}
126128
});

examples/transcript-server/src/mcp-app.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ app.onteardown = async () => {
6868

6969
app.onerror = log.error;
7070

71-
app.onhostcontextchanged = (ctx: McpUiHostContext) => {
71+
function handleHostContextChanged(ctx: McpUiHostContext) {
7272
if (ctx.safeAreaInsets) {
7373
mainEl.style.paddingTop = `${ctx.safeAreaInsets.top}px`;
7474
mainEl.style.paddingRight = `${ctx.safeAreaInsets.right}px`;
@@ -78,7 +78,9 @@ app.onhostcontextchanged = (ctx: McpUiHostContext) => {
7878
if (ctx.theme) {
7979
applyDocumentTheme(ctx.theme);
8080
}
81-
};
81+
}
82+
83+
app.onhostcontextchanged = handleHostContextChanged;
8284

8385
// ============================================================================
8486
// Audio Capture
@@ -546,6 +548,6 @@ app.connect().then(() => {
546548
log.info("Connected to host");
547549
const ctx = app.getHostContext();
548550
if (ctx) {
549-
app.onhostcontextchanged?.(ctx);
551+
handleHostContextChanged(ctx);
550552
}
551553
});

0 commit comments

Comments
 (0)