Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions examples/sheet-music-server/src/mcp-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Sheet Music App - renders ABC notation with abcjs and provides audio playback
*/
import { App } from "@modelcontextprotocol/ext-apps";
import { App, type McpUiHostContext } from "@modelcontextprotocol/ext-apps";
import ABCJS from "abcjs";
import "abcjs/abcjs-audio.css";
import "./global.css";
Expand Down Expand Up @@ -109,18 +109,20 @@ app.ontoolinput = (params) => {

app.onerror = console.error;

app.onhostcontextchanged = (params) => {
if (params.safeAreaInsets) {
mainEl.style.paddingTop = `${params.safeAreaInsets.top}px`;
mainEl.style.paddingRight = `${params.safeAreaInsets.right}px`;
mainEl.style.paddingBottom = `${params.safeAreaInsets.bottom}px`;
mainEl.style.paddingLeft = `${params.safeAreaInsets.left}px`;
function handleHostContextChanged(ctx: McpUiHostContext) {
if (ctx.safeAreaInsets) {
mainEl.style.paddingTop = `${ctx.safeAreaInsets.top}px`;
mainEl.style.paddingRight = `${ctx.safeAreaInsets.right}px`;
mainEl.style.paddingBottom = `${ctx.safeAreaInsets.bottom}px`;
mainEl.style.paddingLeft = `${ctx.safeAreaInsets.left}px`;
}
};
}

app.onhostcontextchanged = handleHostContextChanged;

app.connect().then(() => {
const ctx = app.getHostContext();
if (ctx) {
app.onhostcontextchanged(ctx);
handleHostContextChanged(ctx);
}
});
8 changes: 5 additions & 3 deletions examples/transcript-server/src/mcp-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ app.onteardown = async () => {

app.onerror = log.error;

app.onhostcontextchanged = (ctx: McpUiHostContext) => {
function handleHostContextChanged(ctx: McpUiHostContext) {
if (ctx.safeAreaInsets) {
mainEl.style.paddingTop = `${ctx.safeAreaInsets.top}px`;
mainEl.style.paddingRight = `${ctx.safeAreaInsets.right}px`;
Expand All @@ -78,7 +78,9 @@ app.onhostcontextchanged = (ctx: McpUiHostContext) => {
if (ctx.theme) {
applyDocumentTheme(ctx.theme);
}
};
}

app.onhostcontextchanged = handleHostContextChanged;

// ============================================================================
// Audio Capture
Expand Down Expand Up @@ -546,6 +548,6 @@ app.connect().then(() => {
log.info("Connected to host");
const ctx = app.getHostContext();
if (ctx) {
app.onhostcontextchanged?.(ctx);
handleHostContextChanged(ctx);
}
});
Loading