MCPcopy Create free account
hub / github.com/modelcontextprotocol/ext-apps / waitForPageData

Function waitForPageData

examples/pdf-server/server.ts:230–249  ·  view source on GitHub ↗

* Wait for the viewer to render and submit page data. * Rejects on timeout or when the interact request is aborted upstream.

(
  requestId: string,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

228 * Rejects on timeout or when the interact request is aborted upstream.
229 */
230function waitForPageData(
231 requestId: string,
232 signal?: AbortSignal,
233): Promise<PageDataEntry[]> {
234 return new Promise<PageDataEntry[]>((resolve, reject) => {
235 const settle = (v: PageDataEntry[] | Error) => {
236 clearTimeout(timer);
237 signal?.removeEventListener("abort", onAbort);
238 pendingPageRequests.delete(requestId);
239 v instanceof Error ? reject(v) : resolve(v);
240 };
241 const onAbort = () => settle(new Error("interact request cancelled"));
242 const timer = setTimeout(
243 () => settle(new Error("Timeout waiting for page data from viewer")),
244 GET_PAGES_TIMEOUT_MS,
245 );
246 signal?.addEventListener("abort", onAbort);
247 pendingPageRequests.set(requestId, settle);
248 });
249}
250
251/**
252 * Wait for the viewer's first poll_pdf_commands call.

Callers 1

processInteractCommandFunction · 0.85

Calls 2

settleFunction · 0.85
addEventListenerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…