diff --git a/dashboard/seo/pages.js b/dashboard/seo/pages.js
index 1556382..20309c4 100644
--- a/dashboard/seo/pages.js
+++ b/dashboard/seo/pages.js
@@ -927,6 +927,10 @@ there is nothing else to configure.
publish_clip
Posts or schedules one clip to TikTok, Instagram or YouTube through the connected account.
+
In clients that support the MCP Apps extension (ChatGPT apps, mcp-ui hosts),
+list_clips also renders as an interactive clip picker: preview each
+9:16 clip inline, select the keepers and publish them without leaving the
+conversation. Clients without UI support see the same data as plain results.
How does this compare to the other clipping tools' agent access?
Checked 2026-08-04 on vendor developer documentation and pricing pages. This market is moving fast; verify before committing a pipeline.
diff --git a/mcp_server.py b/mcp_server.py
index 2b7b136..9d9a1ec 100644
--- a/mcp_server.py
+++ b/mcp_server.py
@@ -28,6 +28,8 @@ import httpx
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse, Response
+import mcp_ui
+
router = APIRouter()
PROTOCOL_VERSIONS = ("2025-06-18", "2025-03-26", "2024-11-05")
@@ -115,13 +117,20 @@ TOOLS = [
"title": "List a job's clips",
"description": (
"The clips of a completed job, with titles, platform-ready "
- "descriptions and download URLs."
+ "descriptions and download URLs. In MCP Apps-capable clients the "
+ "result also renders as an interactive clip picker."
),
"inputSchema": {
"type": "object",
"properties": {"job_id": {"type": "string"}},
"required": ["job_id"],
},
+ # Both spellings of the tool->template link: MCP Apps hosts read
+ # _meta.ui.resourceUri, the ChatGPT Apps SDK reads openai/outputTemplate.
+ "_meta": {
+ "ui": {"resourceUri": mcp_ui.CLIP_PICKER_URI},
+ "openai/outputTemplate": mcp_ui.CLIP_PICKER_URI,
+ },
},
{
"name": "get_quota",
@@ -370,7 +379,8 @@ async def handle_message(msg, tool_caller) -> Optional[dict]:
version = client_version if client_version in PROTOCOL_VERSIONS else PROTOCOL_VERSIONS[0]
return _rpc_result(msg_id, {
"protocolVersion": version,
- "capabilities": {"tools": {"listChanged": False}},
+ "capabilities": {"tools": {"listChanged": False},
+ "resources": {"listChanged": False}},
"serverInfo": SERVER_INFO,
"instructions": INSTRUCTIONS,
})
@@ -378,12 +388,37 @@ async def handle_message(msg, tool_caller) -> Optional[dict]:
return _rpc_result(msg_id, {})
if method == "tools/list":
return _rpc_result(msg_id, {"tools": TOOLS})
+ if method == "resources/list":
+ return _rpc_result(msg_id, {"resources": mcp_ui.RESOURCES})
+ if method == "resources/templates/list":
+ return _rpc_result(msg_id, {"resourceTemplates": []})
+ if method == "resources/read":
+ uri = (msg.get("params") or {}).get("uri") or ""
+ # Per-call URIs (ui://openshorts/clip-picker/) resolve to the same
+ # template; the data those carried was baked into the tool result.
+ if uri == mcp_ui.CLIP_PICKER_URI or uri.startswith(mcp_ui.CLIP_PICKER_URI + "/"):
+ return _rpc_result(msg_id, {"contents": [{
+ "uri": uri,
+ "mimeType": mcp_ui.MIME_TYPE,
+ "text": mcp_ui.clip_picker_html(),
+ }]})
+ return _rpc_error(msg_id, -32002, f"Resource not found: {uri}")
if method == "tools/call":
params = msg.get("params") or {}
name = params.get("name")
result, is_error = await tool_caller(name, params.get("arguments") or {})
+ content = [{"type": "text", "text": json.dumps(result, ensure_ascii=False)}]
+ # A successful list_clips additionally ships the picker with its data
+ # baked in, so hosts that render embedded resources need no bridge.
+ # Non-UI clients ignore extra content entries.
+ if name == "list_clips" and not is_error and result.get("clips"):
+ content.append({"type": "resource", "resource": {
+ "uri": f"{mcp_ui.CLIP_PICKER_URI}/{result.get('job_id', 'result')}",
+ "mimeType": mcp_ui.MIME_TYPE,
+ "text": mcp_ui.clip_picker_html(result),
+ }})
return _rpc_result(msg_id, {
- "content": [{"type": "text", "text": json.dumps(result, ensure_ascii=False)}],
+ "content": content,
"structuredContent": result,
"isError": is_error,
})
diff --git a/mcp_ui.py b/mcp_ui.py
new file mode 100644
index 0000000..54278b8
--- /dev/null
+++ b/mcp_ui.py
@@ -0,0 +1,195 @@
+"""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…
+
+ TikTok
+ Instagram
+ YouTube
+
+
+
+
+
+
+"""
+
+
+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)
diff --git a/tests/test_mcp_protocol.py b/tests/test_mcp_protocol.py
index ce20b76..8a2fa9e 100644
--- a/tests/test_mcp_protocol.py
+++ b/tests/test_mcp_protocol.py
@@ -44,7 +44,7 @@ class TestNotificationsAndErrors:
assert _run({"jsonrpc": "2.0", "method": "notifications/initialized"}) is None
def test_unknown_method_is_32601(self):
- resp = _run({"jsonrpc": "2.0", "id": 7, "method": "resources/list"})
+ resp = _run({"jsonrpc": "2.0", "id": 7, "method": "does/not-exist"})
assert resp["error"]["code"] == -32601
assert resp["id"] == 7
diff --git a/tests/test_mcp_ui.py b/tests/test_mcp_ui.py
new file mode 100644
index 0000000..bc0179d
--- /dev/null
+++ b/tests/test_mcp_ui.py
@@ -0,0 +1,102 @@
+"""MCP Apps surface: the clip picker resource and its wiring.
+
+Pure protocol-layer tests (handle_message with a fake tool_caller), same
+pattern as test_mcp_protocol.py.
+"""
+import asyncio
+
+import mcp_ui
+from mcp_server import TOOLS, handle_message
+
+
+def _run(msg, tool_caller=None):
+ async def _noop(name, args):
+ return {}, False
+ return asyncio.run(handle_message(msg, tool_caller or _noop))
+
+
+def _req(method, params=None, msg_id=1):
+ m = {"jsonrpc": "2.0", "id": msg_id, "method": method}
+ if params is not None:
+ m["params"] = params
+ return m
+
+
+class TestResourceSurface:
+ def test_initialize_advertises_resources(self):
+ resp = _run(_req("initialize", {"protocolVersion": "2025-06-18"}))
+ assert "resources" in resp["result"]["capabilities"]
+
+ def test_resources_list_contains_the_picker(self):
+ resp = _run(_req("resources/list"))
+ uris = [r["uri"] for r in resp["result"]["resources"]]
+ assert mcp_ui.CLIP_PICKER_URI in uris
+
+ def test_resources_read_serves_the_template(self):
+ resp = _run(_req("resources/read", {"uri": mcp_ui.CLIP_PICKER_URI}))
+ content = resp["result"]["contents"][0]
+ assert content["mimeType"] == mcp_ui.MIME_TYPE
+ # Template mode: no baked data, the bridge provides it.
+ assert "__OPENSHORTS_DATA__" not in content["text"]
+ assert "var inline = null;" in content["text"]
+
+ def test_resources_read_accepts_per_call_uris(self):
+ resp = _run(_req("resources/read", {"uri": mcp_ui.CLIP_PICKER_URI + "/job42"}))
+ assert resp["result"]["contents"][0]["uri"].endswith("/job42")
+
+ def test_unknown_resource_is_not_found(self):
+ resp = _run(_req("resources/read", {"uri": "ui://other/thing"}))
+ assert resp["error"]["code"] == -32002
+
+
+class TestToolWiring:
+ def test_list_clips_declares_the_template_in_meta(self):
+ tool = next(t for t in TOOLS if t["name"] == "list_clips")
+ assert tool["_meta"]["ui"]["resourceUri"] == mcp_ui.CLIP_PICKER_URI
+ assert tool["_meta"]["openai/outputTemplate"] == mcp_ui.CLIP_PICKER_URI
+
+ def test_list_clips_result_embeds_the_picker_with_data(self):
+ clips = {"job_id": "j1", "clips": [{"index": 0, "title": "A", "video_url": "http://x/v.mp4"}]}
+
+ async def fake(name, args):
+ return clips, False
+
+ resp = _run(_req("tools/call", {"name": "list_clips",
+ "arguments": {"job_id": "j1"}}), fake)
+ content = resp["result"]["content"]
+ assert content[0]["type"] == "text"
+ embedded = content[1]
+ assert embedded["type"] == "resource"
+ assert embedded["resource"]["mimeType"] == mcp_ui.MIME_TYPE
+ assert embedded["resource"]["uri"] == mcp_ui.CLIP_PICKER_URI + "/j1"
+ assert '"job_id": "j1"' in embedded["resource"]["text"]
+
+ def test_other_tools_stay_text_only(self):
+ async def fake(name, args):
+ return {"clips": [{"index": 0}]}, False # even with clips in result
+
+ resp = _run(_req("tools/call", {"name": "get_quota", "arguments": {}}), fake)
+ assert len(resp["result"]["content"]) == 1
+
+ def test_failed_list_clips_embeds_nothing(self):
+ async def fake(name, args):
+ return {"error": "job is processing", "clips": []}, True
+
+ resp = _run(_req("tools/call", {"name": "list_clips",
+ "arguments": {"job_id": "j1"}}), fake)
+ assert len(resp["result"]["content"]) == 1
+
+
+class TestTemplateSafety:
+ def test_titles_cannot_break_out_of_the_script_tag(self):
+ html = mcp_ui.clip_picker_html(
+ {"job_id": "j", "clips": [{"index": 0, "title": ""}]})
+ assert "