Skip to main content
MCP Apps SDK
import { App } from "@modelcontextprotocol/ext-apps";

Overview

updateModelContext pushes app state into the host’s model context. This data becomes available to the model on future turns without triggering an immediate response — unlike sendMessage, which injects a message into the conversation and may prompt the model to reply. Each call to updateModelContext overwrites any previously set context. To clear the context, call it with empty content. This is useful for keeping the model informed about what the user is viewing or doing in the app, such as the current page, selected items, or filter state.

Signature

async updateModelContext(
  params: {
    content?: ContentBlock[];
    structuredContent?: Record<string, unknown>;
  },
  options?: RequestOptions,
): Promise<void>

Parameters

params
object
required
The context update parameters. Provide at least one of content or structuredContent.
content
ContentBlock[]
Array of content blocks (text, images, etc.) to set as the model context. The model can read these on subsequent turns.
structuredContent
Record<string, unknown>
Structured data to set as the model context. Useful for passing typed objects, configuration, or state that the model can reference.
options
RequestOptions
Optional request configuration.
signal
AbortSignal
An AbortSignal to cancel the request.

Returns

Resolves with void on success. Throws on transport or protocol failure.

Usage

Set text context

await app.updateModelContext({
  content: [{
    type: "text",
    text: `User is viewing page ${currentPage} of ${totalPages}`,
  }],
});

Set structured context

await app.updateModelContext({
  structuredContent: {
    selectedItems: ["item-1", "item-5"],
    filters: { category: "electronics", priceRange: [100, 500] },
  },
});

Clear previous context

await app.updateModelContext({ content: [] });
For large follow-up messages, offload data to updateModelContext first, then send a brief trigger via sendMessage:
await app.updateModelContext({
  content: [{ type: "text", text: fullTranscript }],
});
await app.sendMessage({
  role: "user",
  content: [{ type: "text", text: "Summarize the key points" }],
});