Skip to content

Commit 5125741

Browse files
committed
refactor: use app.updateModelContext() instead of raw request
1 parent 9e5ba2f commit 5125741

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
type McpUiHostContext,
1010
applyDocumentTheme,
1111
} from "@modelcontextprotocol/ext-apps";
12-
import { z } from "zod";
1312
import "./global.css";
1413
import "./mcp-app.css";
1514

@@ -331,25 +330,19 @@ function updateSendButton() {
331330
}
332331

333332
function updateModelContext() {
333+
const caps = app.getHostCapabilities();
334+
if (!caps?.updateModelContext) return;
335+
334336
const text = getUnsentText();
335337
log.info("Updating model context:", text || "(empty)");
336338

337-
// EXPERIMENTAL: Updates model context with current transcript
338-
// See https://github.com/modelcontextprotocol/ext-apps/pull/125
339339
app
340-
.request(
341-
{
342-
method: "ui/update-model-context",
343-
params: {
344-
role: "user",
345-
content: text
346-
? [{ type: "text", text: `[Live transcript]: ${text}` }]
347-
: [],
348-
},
349-
} as unknown as Parameters<typeof app.request>[0],
350-
z.object({}) as any,
351-
)
352-
.catch((e) => {
340+
.updateModelContext({
341+
content: text
342+
? [{ type: "text", text: `[Live transcript]: ${text}` }]
343+
: [],
344+
})
345+
.catch((e: unknown) => {
353346
log.warn("Failed to update model context:", e);
354347
});
355348
}

0 commit comments

Comments
 (0)