"""MCP Apps surface: an embedded clip picker for UI-capable MCP clients. The pipeline returns 3-15 clips per job; choosing which ones to publish by looking at them beats reading titles out of JSON. Clients that support the MCP Apps extension (ChatGPT apps, mcp-ui hosts, Claude) render the HTML below in a sandboxed iframe; every other client ignores it and keeps working from the text/structured content exactly as before. One template, three data paths, because the ecosystem hasn't converged: 1. Baked-in JSON — the per-call embedded resource appended to a successful list_clips result carries its data inline and renders with no bridge. 2. window.openai.toolOutput — the ChatGPT Apps SDK injects the tool's structuredContent there; the tool's _meta names this template. 3. postMessage handshake — MCP Apps / mcp-ui hosts that serve the template from resources/read and push render data after the iframe reports ready. The iframe cannot fetch anything (host CSP), so the video previews use the clips' absolute URLs and everything else is inline. """ import json CLIP_PICKER_URI = "ui://openshorts/clip-picker" MIME_TYPE = "text/html;profile=mcp-app" RESOURCES = [ { "uri": CLIP_PICKER_URI, "name": "clip-picker", "title": "OpenShorts clip picker", "description": ( "Interactive picker for a job's finished clips: preview each 9:16 " "clip, select the keepers and publish them to TikTok, Instagram or " "YouTube without leaving the conversation." ), "mimeType": MIME_TYPE, }, ] # Kept as a plain string with a token instead of an f-string: the JS is full of # braces and escaping them all is how bugs get in. _TEMPLATE = """

OpenShorts clips

Waiting for clip data…
""" def clip_picker_html(data=None) -> str: """The picker HTML; ``data`` baked in when rendering a per-call resource. ``<`` is escaped in the JSON so a clip title can never close the script tag and inject markup. """ payload = "null" if data is None else json.dumps( data, ensure_ascii=False).replace("<", "\\u003c") return _TEMPLATE.replace("__OPENSHORTS_DATA__", payload)