用途:指导开发者创建 ChatGPT Apps,即在 ChatGPT 对话中渲染富交互界面的自定义应用。整体采用三层架构:ChatGPT UI 中的 iframe 组件、ChatGPT 后端、以及提供工具与资源的 MCP 服务器(HTTP/SSE)。流程为:用户提示 → 模型调用工具 → 服务器返回结构化数据 → 组件渲染 → 模型叙述结果。
主要能力:组件通过 window.openai 与宿主通信。可读 toolInput、toolOutput、toolResponseMetadata、widgetState 等状态;可调用 callTool、sendFollowUpMessage、setWidgetState、uploadFile、getFileDownloadUrl;可请求 displayMode(inline/pip/fullscreen)、requestModal、notifyIntrinsicHeight、openExternal、requestClose;还可读取 theme、displayMode、maxHeight、safeArea、userAgent、locale 等只读上下文。callTool 需工具元数据 "openai/widgetAccessible": true。
使用方式:工具需设置 _meta,如 "openai/outputTemplate" 指向组件 HTML 的 URI,另有 widgetAccessible、visibility、toolInvocation/invoking、invoked、fileParams 等。响应分三类:structuredContent 供模型与组件使用,content 为可选文本,_meta 仅组件可见。组件以资源注册,MIME 类型必须为 text/html+skybridge,并可配置 widgetPrefersBorder、widgetDomain、widgetCSP(connect/resource/frame domains)。React 侧官方提供 useOpenAiGlobal、useWidgetState、useToolInput、useToolOutput、useToolResponseMetadata 等 Hook 模式。
启动与调试:FastMCP 模板依赖 mcp[cli]>=1.9.2、uvicorn>=0.32.0 等;运行 python main.py,服务默认在 http://localhost:8001;用 ngrok http 8001 暴露;然后在 https://chatgpt.com/apps 开启 Developer mode,创建应用并填写 MCP Server URL,开发阶段可选 No Auth。开始步骤包括创建 MCP 服务器、定义组件 HTML、设置工具元数据、返回结构化响应、通过 ngrok 暴露并注册。
适用场景与限制:适合为 ChatGPT 构建带可视化 UI 的自定义应用。组件须自包含,样式建议内联,调用前应检查 window.openai 是否存在,且必须在真实 ChatGPT 中测试,浏览器预览不含 window.openai。资料未提供收费标准、平台兼容范围与性能数据。