1
---
2
name: chatgpt-apps
3
description: Build, scaffold, refactor, and troubleshoot ChatGPT Apps SDK applications that combine an MCP server and widget UI. Use when Codex needs to design tools, register UI resources, wire the MCP Apps bridge or ChatGPT compatibility APIs, apply Apps SDK metadata or CSP or domain settings, or produce a docs-aligned project scaffold. Prefer a docs-first workflow by invoking the openai-docs skill or OpenAI developer docs MCP tools before generating code.
4
---
5
6
# ChatGPT Apps
7
8
## Overview
9
10
Scaffold ChatGPT Apps SDK implementations with a docs-first, example-first workflow, then generate code that follows current Apps SDK and MCP Apps bridge patterns.
11
12
Use this skill to produce:
13
14
- A primary app-archetype classification and repo-shape decision
15
- A tool plan (names, schemas, annotations, outputs)
16
- An upstream starting-point recommendation (official example, ext-apps example, or local fallback scaffold)
17
- An MCP server scaffold (resource registration, tool handlers, metadata)
18
- A widget scaffold (MCP Apps bridge first, `window.openai` compatibility/extensions second)
19
- A reusable Node + `@modelcontextprotocol/ext-apps` starter scaffold for low-dependency fallbacks
20
- A validation report against the minimum working repo contract
21
- Local dev and connector setup steps
22
- A short stakeholder summary of what the app does (when requested)
23
24
## Mandatory Docs-First Workflow
25
26
Use `$openai-docs` first whenever building or changing a ChatGPT Apps SDK app.
27
28
1. Invoke `$openai-docs` (preferred) or call the OpenAI docs MCP server directly.
29
2. Fetch current Apps SDK docs before writing code, especially (baseline pages):
30
- `apps-sdk/build/mcp-server`
31
- `apps-sdk/build/chatgpt-ui`
32
- `apps-sdk/build/examples`
33
- `apps-sdk/plan/tools`
34
- `apps-sdk/reference`
35
3. Fetch `apps-sdk/quickstart` when scaffolding a new app or generating a first-pass implementation, and check the official examples repo/page before inventing a scaffold from scratch.
36
4. Fetch deployment/submission docs when the task includes local ChatGPT testing, hosting, or public launch:
37
- `apps-sdk/deploy`
38
- `apps-sdk/deploy/submission`
39
- `apps-sdk/app-submission-guidelines`
40
5. Cite the docs URLs you used when explaining design choices or generated scaffolds.
41
6. Prefer current docs guidance over older repo patterns when they differ, and call out compatibility aliases explicitly.
42
7. If doc search times out or returns poor matches, fetch the canonical Apps SDK pages directly by URL and continue; do not let search failure block scaffolding.
43
44
If `$openai-docs` is unavailable, use:
45
46
- `mcp__openaiDeveloperDocs__search_openai_docs`
47
- `mcp__openaiDeveloperDocs__fetch_openai_doc`
48
49
Read `references/apps-sdk-docs-workflow.md` for suggested doc queries and a compact checklist.
50
Read `references/app-archetypes.md` to classify the request into a small number of supported app shapes before choosing examples or scaffolds.
51
Read `references/repo-contract-and-validation.md` when generating or reviewing a repo so the output stays inside a stable “working app” contract.
52
Read `references/search-fetch-standard.md` when the app is connector-like, data-only, sync-oriented, or meant to work well with company knowledge or deep research.
53
Read `references/upstream-example-workflow.md` when starting a greenfield app or when deciding whether to adapt an upstream example or use the local fallback scaffold.
54
Read `references/window-openai-patterns.md` when the task needs ChatGPT-specific widget behavior or when translating repo examples that use wrapper-specific `app.*` helpers.
55
56
## Prompt Guidance
57
58
Use prompts that explicitly pair this skill with `$openai-docs` so the resulting scaffold is grounded in current docs.
59
60
Preferred prompt patterns:
61
62
- `Use $chatgpt-apps with $openai-docs to scaffold a ChatGPT app for <use case> with a <TS/Python> MCP server and <React/vanilla> widget.`
63
- `Use $chatgpt-apps with $openai-docs to adapt the closest official Apps SDK example into a ChatGPT app for <use case>.`
64
- `Use $chatgpt-apps and $openai-docs to refactor this Apps SDK demo into a production-ready structure with tool annotations, CSP, and URI versioning.`
65
- `Use $chatgpt-apps with $openai-docs to plan tools first, then generate the MCP server and widget code.`
66
67
When responding, ask for or infer these inputs before coding:
68
69
- Use case and primary user flows
70
- Read-only vs mutating tools
71
- Demo vs production target
72
- Private/internal use vs public directory submission
73
- Backend language and UI stack
74
- Auth requirements
75
- External API domains for CSP allowlists
76
- Hosting target and local dev approach
77
- Org ownership/verification readiness (for submission tasks)
78
79
## Classify The App Before Choosing Code
80
81
Before choosing examples, repo shape, or scaffolds, classify the request into one primary archetype and state it.
82
83
- `tool-only`
84
- `vanilla-widget`
85
- `react-widget`
86
- `interactive-decoupled`
87
- `submission-ready`
88
89
Infer the archetype unless a missing detail is truly blocking. Use the archetype to choose:
90
91
- whether a UI is needed at all
92
- whether to preserve a split `server/` + `web/` layout
93
- whether to prefer official OpenAI examples, ext-apps examples, or the local fallback scaffold
94
- which validation checks matter most
95
- whether `search` and `fetch` should be the default read-only tool surface
96
97
Read `references/app-archetypes.md` for the decision rubric.
98
99
## Default Starting-Point Order
100
101
For greenfield apps, prefer these starting points in order:
102
103
1. **Official OpenAI examples** when a close example already matches the requested stack or interaction pattern.
104
2. **Version-matched `@modelcontextprotocol/ext-apps` examples** when the user needs a lower-level or more portable MCP Apps baseline.
105
3. **`scripts/scaffold_node_ext_apps.mjs`** only when no close example fits, the user wants a tiny Node + vanilla starter, or network access/example retrieval is undesirable.
106
107
Do not generate a large custom scaffold from scratch if a close upstream example already exists.
108
Copy the smallest matching example, remove unrelated demo code, then patch it to the current docs and the user request.
109
110
## Build Workflow
111
112
### 0. Classify The App Archetype
113
114
Pick one primary archetype before planning tools or choosing a starting point.
115
116
- Prefer a single primary archetype instead of mixing several.
117
- If the request is broad, infer the smallest archetype that can still satisfy it.
118
- Escalate to `submission-ready` only when the user asks for public launch, directory submission, or review-ready deployment.
119
- Call out the chosen archetype in your response so the user can correct it early if needed.
120
121
### 1. Plan Tools Before Code
122
123
Define the tool surface area from user intents.
124
125
- Use one job per tool.
126
- Write tool descriptions that start with "Use this when..." behavior cues.
127
- Make inputs explicit and machine-friendly (enums, required fields, bounds).
128
- Decide whether each tool is data-only, render-only, or both.
129
- Set annotations accurately (`readOnlyHint`, `destructiveHint`, `openWorldHint`; add `idempotentHint` when true).
130
- If the app is connector-like, data-only, sync-oriented, or intended for company knowledge or deep research, default to the standard `search` and `fetch` tools instead of inventing custom read-only equivalents.
131
- For educational/demo apps, prefer one concept per tool so the model can pick the right example cleanly.
132
- Group demo tools by learning objective: data into the widget, widget actions back into the conversation or tools, host/layout environment signals, and lifecycle/streaming behavior.
133
134
Read `references/search-fetch-standard.md` when `search` and `fetch` may be relevant.
135
136
### 2. Choose an App Architecture
137
138
Choose the simplest structure that fits the goal.
139
140
- Use a **minimal demo pattern** for quick prototypes, workshops, or proofs of concept.
141
- Use a **decoupled data/render pattern** for production UX so the widget does not re-render on every tool call.
142
143
Prefer the decoupled pattern for non-trivial apps:
144
145
- Data tools return reusable `structuredContent`.
146
- Render tools attach `_meta.ui.resourceUri` and optional `_meta["openai/outputTemplate"]`.
147
- Render tool descriptions state prerequisites (for example, "Call `search` first").
148
149
### 2a. Start From An Upstream Example When One Fits
150
151
Default to upstream examples for greenfield work when they are close to the requested app.
152
153
- Check the official OpenAI examples first for ChatGPT-facing apps, polished UI patterns, React components, file upload flows, modal flows, or apps that resemble the docs examples.
154
- Use `@modelcontextprotocol/ext-apps` examples when the request is closer to raw MCP Apps bridge/server wiring, or when version-matched package patterns matter more than ChatGPT-specific polish.
155
- Pick the smallest matching example and copy only the relevant files; do not transplant an entire showcase app unchanged.
156
- After copying, reconcile the example with the current docs you fetched: tool names/descriptions, annotations, `_meta.ui.*`, CSP, URI versioning, and local run instructions.
157
- State which example you chose and why in one sentence.
158
159
Read `references/upstream-example-workflow.md` for the selection and adaptation rubric.
160
161
### 2b. Use the Starter Script When a Low-Dependency Fallback Helps
162
163
Use `scripts/scaffold_node_ext_apps.mjs` only when the user wants a quick, greenfield Node starter and a vanilla HTML widget is acceptable, and no upstream example is a better starting point.
164
165
- Run it only after fetching current docs, then reconcile the generated files with the docs you fetched.
166
- If you choose the script instead of an upstream example, say why the fallback is better for that request.
167
- Skip it when a close official example exists, when the user already has an existing app structure, when they need a non-Node stack, when they explicitly want React first, or when they only want a plan/review instead of code.
168
- The script generates a minimal `@modelcontextprotocol/ext-apps` server plus a vanilla HTML widget that uses the MCP Apps bridge by default.
169
- The generated widget keeps follow-up messaging on the standard `ui/message` bridge and only uses `window.openai` for optional host signals/extensions.
170
- After running it, patch the generated output to match the current docs and the user request: adjust tool names/descriptions, annotations, resource metadata, URI versioning, and README/run instructions.
171
172
### 3. Scaffold the MCP Server
173
174
Generate a server that:
175
176
- Registers a widget resource/template with the MCP Apps UI MIME type (`text/html;profile=mcp-app`) or the SDK constant (`RESOURCE_MIME_TYPE`) when using `@modelcontextprotocol/ext-apps/server`
177
- Registers tools with clear names, schemas, titles, and descriptions
178
- Returns `structuredContent` (model + widget), `content` (model narration), and `_meta` (widget-only data) intentionally
179
- Keeps handlers idempotent or documents non-idempotent behavior explicitly
180
- Includes tool status strings (`openai/toolInvocation/*`) when helpful in ChatGPT
181
182
Keep `structuredContent` concise. Move large or sensitive widget-only payloads to `_meta`.
183
184
### 4. Scaffold the Widget UI
185
186
Use the MCP Apps bridge first for portability, then add ChatGPT-specific `window.openai` APIs when they materially improve UX.
187
188
- Listen for `ui/notifications/tool-result` (JSON-RPC over `postMessage`)
189
- Render from `structuredContent`
190
- Use `tools/call` for component-initiated tool calls
191
- Use `ui/update-model-context` only when UI state should change what the model sees
192
193
Use `window.openai` for compatibility and extensions (file upload, modal, display mode, etc.), not as the only integration path for new apps.
194
195
#### API Surface Guardrails
196
197
- Some examples wrap the bridge with an `app` object (for example, `@modelcontextprotocol/ext-apps/react`) and expose helper names like `app.sendMessage()`, `app.callServerTool()`, `app.openLink()`, or host getter methods.
198
- Treat those wrappers as implementation details or convenience layers, not the canonical public API to teach by default.
199
- For ChatGPT-facing guidance, prefer the current documented surface: `window.openai.callTool(...)`, `window.openai.sendFollowUpMessage(...)`, `window.openai.openExternal(...)`, `window.openai.requestDisplayMode(...)`, and direct globals like `window.openai.theme`, `window.openai.locale`, `window.openai.displayMode`, `window.openai.toolInput`, `window.openai.toolOutput`, `window.openai.toolResponseMetadata`, and `window.openai.widgetState`.
200
- If you reference wrapper helpers from repo examples, map them back to the documented `window.openai` or MCP Apps bridge primitives and call out that the wrapper is not the normative API surface.
201
- Use `references/window-openai-patterns.md` for the wrapper-to-canonical mapping and for React helper extraction patterns.
202
203
### 5. Add Resource Metadata and Security
204
205
Set resource metadata deliberately on the widget resource/template:
206
207
- `_meta.ui.csp` with exact `connectDomains` and `resourceDomains`
208
- `_meta.ui.domain` for app submission-ready deployments
209
- `_meta.ui.prefersBorder` (or OpenAI compatibility alias when needed)
210
- Optional `openai/widgetDescription` to reduce redundant narration
211
212
Avoid `frameDomains` unless iframe embeds are core to the product.
213
214
### 5a. Enforce A Minimum Working Repo Contract
215
216
Every generated repo should satisfy a small, stable contract before you consider it done.
217
218
- The repo shape matches the chosen archetype.
219
- The MCP server and tools are wired to a reachable `/mcp` endpoint.
220
- Tools have clear descriptions, accurate annotations, and UI metadata where needed.
221
- Connector-like, data-only, sync-oriented, and company-knowledge-style apps use the standard `search` and `fetch` tool shapes when relevant.
222
- The widget uses the MCP Apps bridge correctly when a UI exists.
223
- The repo includes enough scripts or commands for a user to run and check it locally.
224
- The response explicitly says what validation was run and what was not run.
225
226
Read `references/repo-contract-and-validation.md` for the detailed checklist and validation ladder.
227
228
### 6. Validate the Local Loop
229
230
Validate against the minimum working repo contract, not just “did files get created.”
231
232
- Run the lowest-cost checks first:
233
- static contract review
234
- syntax or compile checks when feasible
235
- local `/mcp` health check when feasible
236
- Then move up to runtime checks:
237
- verify tool descriptors and widget rendering in MCP Inspector
238
- test the app in ChatGPT developer mode through HTTPS tunneling
239
- exercise retries and repeated tool calls to confirm idempotent behavior
240
- check widget updates after host events and follow-up tool calls
241
- If you are only delivering a scaffold and are not installing dependencies, still run low-cost checks and say exactly what you did not run.
242
243
Read `references/repo-contract-and-validation.md` for the validation ladder.
244
245
### 7. Connect and Test in ChatGPT (Developer Mode)
246
247
For local development, include explicit ChatGPT setup steps (not just code/run commands).
248
249
- Run the MCP server locally on `http://localhost:<port>/mcp`
250
- Expose the local server with a public HTTPS tunnel (for example `ngrok http <port>`)
251
- Use the tunneled HTTPS URL plus `/mcp` path when connecting from ChatGPT
252
- In ChatGPT, enable Developer Mode under **Settings → Apps & Connectors → Advanced settings**
253
- In ChatGPT app settings, create a new app for the remote MCP server and paste the public MCP URL
254
- Tell users to refresh the app after MCP tool/metadata changes so ChatGPT reloads the latest descriptors
255
256
Note: Some docs/screenshots still use older "connector" terminology. Prefer current product wording ("app") while acknowledging both labels when giving step-by-step instructions.
257
258
### 8. Plan Production Hosting and Deployment
259
260
When the user asks to deploy or prepare for launch, generate hosting guidance for the MCP server (and widget assets if hosted separately).
261
262
- Host behind a stable public HTTPS endpoint (not a tunnel) with dependable TLS
263
- Preserve low-latency streaming behavior on `/mcp`
264
- Configure secrets outside the repo (environment variables / secret manager)
265
- Add logging, request latency tracking, and error visibility for tool calls
266
- Add basic observability (CPU, memory, request volume) and a troubleshooting path
267
- Re-test the hosted endpoint in ChatGPT Developer Mode before submission
268
269
### 9. Prepare Submission and Publish (Public Apps Only)
270
271
Only include these steps when the user intends a public directory listing.
272
273
- Use `apps-sdk/deploy/submission` for the submission flow and `apps-sdk/app-submission-guidelines` for review requirements
274
- Keep private/internal apps in Developer Mode instead of submitting
275
- Confirm org verification and Owner-role prerequisites before submission work
276
- Ensure the MCP server uses a public production endpoint (no localhost/testing URLs) and has submission-ready CSP configured
277
- Prepare submission artifacts: app metadata, logo/screenshots, privacy policy URL, support contact, test prompts/responses, localization info
278
- If auth is required, include review-safe demo credentials and test the login path end-to-end
279
- Submit for review in the Platform dashboard, monitor review status, and publish only after approval
280
281
## Interactive State Guidance
282
283
Read `references/interactive-state-sync-patterns.md` when the app has long-lived widget state, repeated interactions, or component-initiated tool calls (for example, games, boards, maps, dashboards, editors).
284
285
Use it to choose patterns for:
286
287
- State snapshots plus monotonic event tokens (`stateVersion`, `resetCount`, etc.)
288
- Idempotent retry-safe handlers
289
- `structuredContent` vs `_meta` partitioning
290
- MCP Apps bridge-first update flows with optional `window.openai` compatibility
291
- Decoupled data/render tool architecture for more complex interactive apps
292
293
## Output Expectations
294
295
When using this skill to scaffold code, produce output in this order unless the user asks otherwise:
296
297
- For direct scaffold requests, do not stop at the plan: give the brief plan, then create the files immediately.
298
299
1. Primary app archetype chosen and why
300
2. Tool plan and architecture choice (minimal vs decoupled)
301
3. Upstream starting point chosen (official example, ext-apps example, or local fallback scaffold) and why
302
4. Doc pages/URLs used from `$openai-docs`
303
5. File tree to create or modify
304
6. Implementation (server + widget)
305
7. Validation performed against the minimum working repo contract
306
8. Local run/test instructions (including tunnel + ChatGPT Developer Mode app setup)
307
9. Deployment/hosting guidance (if requested or implied)
308
10. Submission-readiness checklist (for public launch requests)
309
11. Risks, gaps, and follow-up improvements
310
311
## References
312
313
- `references/app-archetypes.md` for classifying requests into a small number of supported app shapes
314
- `references/apps-sdk-docs-workflow.md` for doc queries, page targets, and code-generation checklist
315
- `references/interactive-state-sync-patterns.md` for reusable patterns for stateful or highly interactive widget apps
316
- `references/repo-contract-and-validation.md` for the minimum working repo contract and lightweight validation ladder
317
- `references/search-fetch-standard.md` for when and how to default to the standard `search` and `fetch` tools
318
- `references/upstream-example-workflow.md` for choosing between official examples, ext-apps examples, and the local fallback scaffold
319
- `references/window-openai-patterns.md` for ChatGPT-specific extensions, wrapper API translation, and React helper patterns
320
- `scripts/scaffold_node_ext_apps.mjs` for a minimal Node + `@modelcontextprotocol/ext-apps` fallback starter scaffold
321