ChatGPT Apps Builder
Complete workflow for building, testing, and deploying ChatGPT Apps from concept to production.
Commands
- -
/chatgpt-apps new - Create a new ChatGPT App - INLINECODE1 - Add an MCP tool to your app
- INLINECODE2 - Add a widget to your app
- INLINECODE3 - Configure authentication
- INLINECODE4 - Set up database
- INLINECODE5 - Validate your app
- INLINECODE6 - Run tests
- INLINECODE7 - Deploy to production
- INLINECODE8 - Resume working on an app
Table of Contents
- 1. Create New App
- Add MCP Tool
- Add Widget
- Add Authentication
- Add Database
- Generate Golden Prompts
- Validate App
- Test App
- Deploy App
- Resume App
1. Create New App
Purpose: Create a new ChatGPT App from concept to working code.
Workflow
Phase 1: Conceptualization
- 1. Ask for the app idea
"What ChatGPT App would you like to build? Describe what it does and the problem it solves."
- 2. Analyze against UX Principles
-
Conversational Leverage: What can users accomplish through natural language?
-
Native Fit: How does this integrate with ChatGPT's conversational flow?
-
Composability: Can tools work independently and combine with other apps?
- 3. Check for Anti-Patterns
- Static website content display
- Complex multi-step workflows requiring external tabs
- Duplicating ChatGPT's native capabilities
- Ads or upsells
- 4. Define Use Cases
Create 3-5 primary use cases with user stories.
Phase 2: Design
- 1. Tool Topology
- Query tools (readOnlyHint: true)
- Mutation tools (destructiveHint: false)
- Destructive tools (destructiveHint: true)
- Widget tools (return UI with _meta)
- External API tools (openWorldHint: true)
- 2. Widget Design
For each widget:
-
id - unique identifier (kebab-case)
-
name - display name
-
description - what it shows
-
mockData - sample data for preview
- 3. Data Model
Design entities and relationships.
- 4. Auth Requirements
- Single-user (no auth needed)
- Multi-user (Auth0 or Supabase Auth)
Phase 3: Implementation
Generate complete application with this structure:
CODEBLOCK0
Critical Requirements:
- -
Server class from INLINECODE14 - INLINECODE15 for session management
- Widget URIs: INLINECODE16
- Widget MIME type: INLINECODE17
- INLINECODE18 in tool responses
- INLINECODE19 with
openai/outputTemplate on tools
Phase 4: Testing
- - Run setup: INLINECODE21
- Start dev: INLINECODE22
- Preview widgets: INLINECODE23
- Test MCP connection
Phase 5: Deployment
- - Generate Dockerfile and render.yaml
- Deploy to Render
- Configure ChatGPT connector
2. Add MCP Tool
Purpose: Add a new MCP tool to your ChatGPT App.
Workflow
- 1. Gather Information
- What does this tool do?
- What inputs does it need?
- What does it return?
- 2. Classify Tool Type
-
Query (readOnlyHint: true) - Fetches data
-
Mutation (destructiveHint: false) - Creates/updates data
-
Destructive (destructiveHint: true) - Deletes data
-
Widget - Returns UI content
-
External (openWorldHint: true) - Calls external APIs
- 3. Design Input Schema
Create Zod schema with appropriate types and descriptions.
- 4. Generate Tool Handler
Use
chatgpt-mcp-generator agent to create:
- Tool handler in
server/tools/
- Zod schema export
- Type exports
- Database queries (if needed)
- 5. Register Tool
Update
server/index.ts with metadata:
CODEBLOCK1
- 6. Update State
Add tool to
.chatgpt-app/state.json.
Tool Naming
Use kebab-case:
list-items,
create-task, INLINECODE30
Annotations Guide
| Scenario | readOnlyHint | destructiveHint | openWorldHint |
|---|
| List/Get | true | false | false |
| Create/Update |
false | false | false |
| Delete | false | true | false |
| External API | varies | varies | true |
3. Add Widget
Purpose: Add inline HTML widgets with HTML/CSS/JS and Apps SDK integration.
5 Widget Patterns
- 1. Card Grid - Multiple items in grid
- Stats Dashboard - Key metrics display
- Table - Tabular data
- Bar Chart - Simple visualizations
- Detail Widget - Single item details
Workflow
- 1. Gather Information
- Widget purpose and data
- Visual design (cards, table, chart, etc.)
- Interactivity needs
- 2. Define Data Shape
Document expected structure with TypeScript interface.
- 3. Add Widget Config
CODEBLOCK2
- 4. Add Widget HTML
Generate HTML with:
- Preview mode support (
window.PREVIEW_DATA)
- OpenAI Apps SDK integration (
window.openai.toolOutput)
- Event listeners (
openai:set_globals)
- Polling fallback (100ms, 10s timeout)
- 5. Create/Update Tool
Link tool to widget via
widgetId.
- 6. Test Widget
Preview at
/preview/{widget-id} with mock data.
Widget HTML Structure
CODEBLOCK3
4. Add Authentication
Purpose: Configure authentication using Auth0 or Supabase Auth.
When to Add
- - Multiple users
- Persistent private data per user
- User-specific API credentials
Providers
Auth0:
- - Enterprise-grade
- OAuth 2.1, PKCE flow
- Social logins (Google, GitHub, etc.)
Supabase Auth:
- - Simpler setup
- Email/password default
- Integrates with Supabase database
Workflow
- 1. Choose Provider
Ask user preference based on needs.
- 2. Guide Setup
-
Auth0: Create application, configure callback URLs, get credentials
-
Supabase: Already configured with database setup
- 3. Generate Auth Code
Use
chatgpt-auth-generator agent to create:
- Session management middleware
- User subject extraction
- Token validation
- 4. Update Server
Add auth middleware to protect routes.
- 5. Update Environment
CODEBLOCK4
- 6. Test
Verify login flow and user isolation.
5. Add Database
Purpose: Configure PostgreSQL database using Supabase.
When to Add
- - Persistent user data
- Multi-entity relationships
- Query/filter capabilities
Workflow
- 1. Check Supabase Setup
Verify account and project exist.
- 2. Gather Credentials
- Project URL
- Anon key (public)
- Service role key (server-side)
- 3. Define Entities
For each entity, specify:
- Fields and types
- Relationships
- Indexes
- 4. Generate Schema
Use
chatgpt-database-generator agent to create SQL with:
-
id (UUID primary key)
-
user_subject (varchar, indexed)
-
created_at (timestamptz)
-
updated_at (timestamptz)
- RLS policies for user isolation
- 5. Setup Connection Pool
CODEBLOCK5
- 6. Apply Migrations
Run SQL in Supabase dashboard or via migration tool.
Query Pattern
Always filter by user_subject:
CODEBLOCK6
6. Generate Golden Prompts
Purpose: Generate test prompts to validate ChatGPT correctly invokes tools.
Why Important
- - Measure precision/recall
- Enable iteration
- Post-launch monitoring
3 Categories
- 1. Direct Prompts - Explicit tool invocation
- "Show me my task list"
- "Create a new task called..."
- 2. Indirect Prompts - Outcome-based, ChatGPT should infer tool
- "What do I need to do today?"
- "Help me organize my work"
- 3. Negative Prompts - Should NOT trigger tool
- "What is a task?"
- "Tell me about project management"
Workflow
- 1. Analyze Tools
Review each tool's purpose and inputs.
- 2. Generate Prompts
For each tool, create:
- 5+ direct prompts
- 5+ indirect prompts
- 3+ negative prompts
- 2+ edge case prompts
- 3. Best Practices
- Tool descriptions start with "Use this when..."
- State limitations clearly
- Include examples in descriptions
- 4. Save Output
Write to
.chatgpt-app/golden-prompts.json:
{
"toolName": {
"direct": ["prompt1", "prompt2"],
"indirect": ["prompt1", "prompt2"],
"negative": ["prompt1", "prompt2"],
"edge": ["prompt1", "prompt2"]
}
}
7. Validate App
Purpose: Validation suite before deployment.
10 Validation Checks
- 1. Required Files
- package.json
- tsconfig.server.json
- setup.sh (executable)
- START.sh (executable)
- server/index.ts
- .env.example
- 2. Server Implementation
- Uses
Server from MCP SDK
- Has
StreamableHTTPServerTransport
- Session management with Map
- Correct request handlers
- 3. Widget Configuration
-
widgets array exists
- Each has id, name, description, templateUri, mockData
- URIs match pattern INLINECODE47
- 4. Tool Response Format
- Returns
structuredContent (not just
content)
- Widget tools have
_meta with INLINECODE51
- 5. Resource Handler Format
- MIME type:
text/html+skybridge
- Returns
_meta with serialization and CSP
- 6. Widget HTML Structure
- Preview mode support
- Event listeners for Apps SDK
- Polling fallback
- Render guard
- 7. Endpoint Existence
-
/health - Health check
-
/preview - Widget index
-
/preview/:widgetId - Widget preview
-
/mcp - MCP endpoint
- 8. Package.json Scripts
- Has
build:server
- Has
start with HTTP_MODE=true
- Has
dev with watch mode
- NO web build scripts (web/, ui/, client/)
- 9. Annotation Validation
- readOnlyHint set correctly
- destructiveHint for delete operations
- openWorldHint for external APIs
- 10. Database Validation (if enabled)
- Tables have required fields
- user_subject indexed
- RLS policies enabled
Common Errors
| Error | Fix |
|---|
| Missing structuredContent | Add to tool response |
| Wrong widget URI |
Use ui://widget/{id}.html |
| No session management | Add Map
|
| Missing _meta | Add to tool definition and response |
| Wrong MIME type | Use text/html+skybridge |
Critical: Check file existence FIRST before other validations!
8. Test App
Purpose: Run automated tests using MCP Inspector and golden prompts.
4 Test Categories
- 1. MCP Protocol
- Server starts without errors
- Handles initialize
- Lists tools correctly
- Lists resources correctly
- 2. Schema Validation
- Tool schemas are valid Zod
- Required fields marked
- Types match implementation
- 3. Widget Tests
- All widgets render in preview mode
- Mock data loads correctly
- No console errors
- 4. Golden Prompt Tests
- Direct prompts trigger correct tools
- Indirect prompts work as expected
- Negative prompts don't trigger tools
Workflow
- 1. Start Server in Test Mode
CODEBLOCK8
- 2. Run MCP Inspector
Test protocol compliance:
- Initialize connection
- List tools
- Call each tool with valid inputs
- Check responses
- 3. Schema Validation
Verify schemas compile and match implementation.
- 4. Golden Prompt Tests
Use ChatGPT to test prompts:
- Record which tool was called
- Compare to expected tool
- Calculate precision/recall
- 5. Generate Report
CODEBLOCK9
Fixing Failures
For each failure, explain:
- - What failed
- Why it failed
- How to fix (with code example)
9. Deploy App
Purpose: Deploy ChatGPT App to Render with PostgreSQL and health checks.
Prerequisites
- - ✅ Validation passed
- ✅ Tests passed
- ✅ Git repository clean
- ✅ Environment variables ready
Workflow
- 1. Pre-flight Check
- Run validation
- Run tests
- Check database connection (if enabled)
- 2. Generate render.yaml
CODEBLOCK10
- 3. Generate Dockerfile
CODEBLOCK11
- 4. Deploy
Option A: Automated (if Render MCP available)
Use Render MCP agent to deploy.
Option B: Manual
- Push to GitHub
- Connect repo in Render dashboard
- Set environment variables
- Deploy
- 5. Verify Deployment
- Health check: https://{app}.onrender.com/health
- MCP endpoint: https://{app}.onrender.com/mcp
- Tool discovery works
- Widgets render
- 6. Configure ChatGPT Connector
- URL: https://{app}.onrender.com/mcp
- Test in ChatGPT
10. Resume App
Purpose: Resume building an in-progress ChatGPT App.
Workflow
- 1. Load State
Read .chatgpt-app/state.json:
CODEBLOCK12
- 2. Display Progress
Show current status:
- App name
- Current phase
- Completed items (tools, widgets)
- Pending items (auth, validation, deployment)
- 3. Offer Next Steps
Based on phase:
Concept Phase:
- "Let's design the tools and widgets"
- "Shall we start implementation?"
Implementation Phase:
- "Add another tool?"
- "Add a widget?"
- "Set up authentication?"
- "Set up database?"
Testing Phase:
- "Generate golden prompts?"
- "Run validation?"
- "Run tests?"
Deployment Phase:
- "Deploy to Render?"
- "Configure ChatGPT connector?"
- 4. Continue Work
Based on user's choice, invoke the appropriate workflow section.
Best Practices
- 1. Always save state after each major step
- Validate before moving forward (especially before deployment)
- Use agents for code generation (chatgpt-mcp-generator, chatgpt-auth-generator, etc.)
- Test at every phase (preview widgets, test tools, run golden prompts)
- Keep it conversational - guide the user naturally through the workflow
- Explain trade-offs when offering choices (Auth0 vs Supabase, etc.)
- Show examples when introducing new concepts
State Management
The .chatgpt-app/state.json file tracks progress:
CODEBLOCK13
Command Reference
CODEBLOCK14
Getting Started
When the user invokes any chatgpt-app command:
- 1. Check if
.chatgpt-app/state.json exists - If yes → use Resume App workflow
- If no → use Create New App workflow
Always guide users through the natural progression:
Concept → Implementation → Testing → Deployment
ChatGPT 应用构建器
从概念到生产,构建、测试和部署 ChatGPT 应用的完整工作流程。
命令
- - /chatgpt-apps new - 创建新的 ChatGPT 应用
- /chatgpt-apps add-tool - 向应用添加 MCP 工具
- /chatgpt-apps add-widget - 向应用添加组件
- /chatgpt-apps add-auth - 配置身份认证
- /chatgpt-apps add-database - 设置数据库
- /chatgpt-apps validate - 验证应用
- /chatgpt-apps test - 运行测试
- /chatgpt-apps deploy - 部署到生产环境
- /chatgpt-apps resume - 继续开发应用
目录
- 1. 创建新应用
- 添加 MCP 工具
- 添加组件
- 添加身份认证
- 添加数据库
- 生成黄金提示词
- 验证应用
- 测试应用
- 部署应用
- 继续开发应用
1. 创建新应用
目的: 从概念到可运行代码,创建新的 ChatGPT 应用。
工作流程
第一阶段:概念化
- 1. 询问应用创意
您想构建什么 ChatGPT 应用?请描述它的功能以及解决的问题。
- 2. 根据用户体验原则分析
-
对话杠杆:用户通过自然语言能完成什么?
-
原生适配:如何与 ChatGPT 的对话流程集成?
-
可组合性:工具能否独立工作并与其他应用组合?
- 3. 检查反模式
- 静态网站内容展示
- 需要外部标签页的复杂多步骤工作流
- 重复 ChatGPT 的原生功能
- 广告或追加销售
- 4. 定义用例
创建 3-5 个主要用例及用户故事。
第二阶段:设计
- 1. 工具拓扑
- 查询工具(readOnlyHint: true)
- 变更工具(destructiveHint: false)
- 破坏性工具(destructiveHint: true)
- 组件工具(返回带有 _meta 的 UI)
- 外部 API 工具(openWorldHint: true)
- 2. 组件设计
每个组件:
- id - 唯一标识符(短横线命名)
- name - 显示名称
- description - 显示内容描述
- mockData - 预览示例数据
- 3. 数据模型
设计实体和关系。
- 4. 认证需求
- 单用户(无需认证)
- 多用户(Auth0 或 Supabase Auth)
第三阶段:实现
生成具有以下结构的完整应用:
{应用名称}/
├── package.json
├── tsconfig.server.json
├── setup.sh
├── START.sh
├── .env.example
├── .gitignore
└── server/
└── index.ts
关键要求:
- - 来自 @modelcontextprotocol/sdk/server/index.js 的 Server 类
- 用于会话管理的 StreamableHTTPServerTransport
- 组件 URI:ui://widget/{组件-id}.html
- 组件 MIME 类型:text/html+skybridge
- 工具响应中的 structuredContent
- 工具上的 _meta 包含 openai/outputTemplate
第四阶段:测试
- - 运行设置:./setup.sh
- 启动开发:./START.sh --dev
- 预览组件:http://localhost:3000/preview
- 测试 MCP 连接
第五阶段:部署
- - 生成 Dockerfile 和 render.yaml
- 部署到 Render
- 配置 ChatGPT 连接器
2. 添加 MCP 工具
目的: 向 ChatGPT 应用添加新的 MCP 工具。
工作流程
- 1. 收集信息
- 这个工具做什么?
- 需要什么输入?
- 返回什么?
- 2. 分类工具类型
-
查询(readOnlyHint: true)- 获取数据
-
变更(destructiveHint: false)- 创建/更新数据
-
破坏性(destructiveHint: true)- 删除数据
-
组件 - 返回 UI 内容
-
外部(openWorldHint: true)- 调用外部 API
- 3. 设计输入模式
使用适当的类型和描述创建 Zod 模式。
- 4. 生成工具处理器
使用 chatgpt-mcp-generator 代理创建:
- server/tools/ 中的工具处理器
- Zod 模式导出
- 类型导出
- 数据库查询(如果需要)
- 5. 注册工具
使用元数据更新 server/index.ts:
typescript
{
name: my-tool,
_meta: {
openai/toolInvocation/invoking: 加载中...,
openai/toolInvocation/invoked: 完成,
openai/outputTemplate: ui://widget/my-widget.html, // 如果是组件
}
}
- 6. 更新状态
将工具添加到 .chatgpt-app/state.json。
工具命名
使用短横线命名:list-items、create-task、show-recipe-detail
注解指南
| 场景 | readOnlyHint | destructiveHint | openWorldHint |
|---|
| 列表/获取 | true | false | false |
| 创建/更新 |
false | false | false |
| 删除 | false | true | false |
| 外部 API | 视情况而定 | 视情况而定 | true |
3. 添加组件
目的: 使用 HTML/CSS/JS 和 Apps SDK 集成添加内联 HTML 组件。
5 种组件模式
- 1. 卡片网格 - 网格中的多个项目
- 统计面板 - 关键指标展示
- 表格 - 表格数据
- 柱状图 - 简单可视化
- 详情组件 - 单个项目详情
工作流程
- 1. 收集信息
- 组件用途和数据
- 视觉设计(卡片、表格、图表等)
- 交互需求
- 2. 定义数据形状
使用 TypeScript 接口记录预期结构。
- 3. 添加组件配置
typescript
const widgets: WidgetConfig[] = [
{
id: my-widget,
name: 我的组件,
description: 显示数据,
templateUri: ui://widget/my-widget.html,
invoking: 加载中...,
invoked: 就绪,
mockData: { /
示例 / },
},
];
- 4. 添加组件 HTML
生成包含以下内容的 HTML:
- 预览模式支持(window.PREVIEW_DATA)
- OpenAI Apps SDK 集成(window.openai.toolOutput)
- 事件监听器(openai:set_globals)
- 轮询回退(100ms,10s 超时)
- 5. 创建/更新工具
通过 widgetId 将工具链接到组件。
- 6. 测试组件
使用模拟数据在 /preview/{组件-id} 预览。
组件 HTML 结构
javascript
(function() {
let rendered = false;
function render(data) {
if (rendered || !data) return;
rendered = true;
// 渲染逻辑
}
function tryRender() {
if (window.PREVIEWDATA) { render(window.PREVIEWDATA); return; }
if (window.openai?.toolOutput) { render(window.openai.toolOutput); }
}
window.addEventListener(openai:set_globals, tryRender);
const poll = setInterval(() => {
if (window.openai?.toolOutput || window.PREVIEW_DATA) {
tryRender();
clearInterval(poll);
}
}, 100);
setTimeout(() => clearInterval(poll), 10000);
tryRender();
})();
4. 添加身份认证
目的: 使用 Auth0 或 Supabase Auth 配置身份认证。
何时添加
- - 多用户
- 每个用户的持久化私有数据
- 用户特定的 API 凭据
提供商
Auth0:
- - 企业级
- OAuth 2.1,PKCE 流程
- 社交登录(Google、GitHub 等)
Supabase Auth: