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

Overview

sendMessage sends a message from the View into the host’s chat interface, appearing as if the user typed it. This enables the app to drive the conversation — for example, submitting a user selection, asking a follow-up question, or triggering the model to act on data displayed in the UI. The message is always sent with role: "user". The host may reject the message (for example, if sending is rate-limited or disabled), in which case isError will be true in the response.

Signature

async sendMessage(
  params: { role: "user"; content: ContentBlock[] },
  options?: RequestOptions,
): Promise<{ isError?: boolean }>

Parameters

params
object
required
The message parameters.
role
"user"
required
The message role. Currently only "user" is supported.
content
ContentBlock[]
required
Array of content blocks to include in the message. Supports text, images, and other standard MCP content block types.
options
RequestOptions
Optional request configuration.
signal
AbortSignal
An AbortSignal to cancel the request.

Returns

result
object
isError
boolean
true if the host rejected the message. When absent or false, the message was accepted.

Usage

Send a text message

const result = await app.sendMessage({
  role: "user",
  content: [{ type: "text", text: "Show me details for item #42" }],
});

if (result.isError) {
  console.error("Host rejected the message");
}

Send a message based on user interaction

function onItemSelected(itemId: string) {
  app.sendMessage({
    role: "user",
    content: [{
      type: "text",
      text: `Tell me more about ${itemId}`,
    }],
  });
}

Combine with updateModelContext for large payloads

When you need to send a large amount of data along with a message, offload the data to model context first, then send a brief trigger message:
await app.updateModelContext({
  content: [{ type: "text", text: fullTranscript }],
});
await app.sendMessage({
  role: "user",
  content: [{ type: "text", text: "Summarize the key points" }],
});