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

Overview

readServerResource reads a resource from the originating MCP server by URI. The request is proxied through the host, so the View never communicates directly with the server. This is useful for fetching data, binary assets (images, video, audio), or structured content that a server exposes via MCP Resources. The returned ReadResourceResult contains a contents array where each item is either a text resource (with a text field) or a binary resource (with a base64-encoded blob field).

Signature

async readServerResource(
  params: { uri: string },
  options?: RequestOptions,
): Promise<ReadResourceResult>

Parameters

params
object
required
uri
string
required
The URI of the resource to read. Must match a URI registered on the MCP server via registerAppResource or a standard MCP resource.
options
RequestOptions
Optional request configuration such as timeout or abort signal.

Returns

ReadResourceResult
object
contents
(TextResourceContents | BlobResourceContents)[]
Array of resource contents. Each entry includes a uri and mimeType, plus either a text field (for text resources) or a blob field (base64-encoded binary).

Usage

Reading a binary resource

const result = await app.readServerResource({ uri: "videos://bunny-1mb" });

const content = result.contents[0];
if (content && "blob" in content) {
  const binary = Uint8Array.from(atob(content.blob), (c) => c.charCodeAt(0));
  const blob = new Blob([binary], { type: content.mimeType });
  videoElement.src = URL.createObjectURL(blob);
}

Reading a text resource

const result = await app.readServerResource({ uri: "config://app/settings" });

const content = result.contents[0];
if (content && "text" in content) {
  const settings = JSON.parse(content.text);
  applySettings(settings);
}

Error handling

try {
  const result = await app.readServerResource({ uri: "data://reports/latest" });
  renderReport(result.contents);
} catch (error) {
  console.error("Failed to read resource:", error);
  showFallbackUI();
}