-
Notifications
You must be signed in to change notification settings - Fork 49
feat: experimental OpenAI Apps SDK compatibility #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ochafik
wants to merge
9
commits into
main
Choose a base branch
from
ochafik/openai-compatibility
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add transparent support for OpenAI's Apps SDK environment alongside MCP.
## Changes
### New: `src/openai/` module
- `transport.ts` - OpenAITransport implementing MCP Transport interface
- `types.ts` - TypeScript types for OpenAI Apps SDK (`window.openai`)
- `transport.test.ts` - Comprehensive tests
### Updated: `src/app.ts`
- Add `experimentalOAICompatibility` option (default: `true`)
- Auto-detect platform: check for `window.openai` → use OpenAI, else MCP
- `connect()` creates appropriate transport automatically
### Updated: `src/react/useApp.tsx`
- Add `experimentalOAICompatibility` prop to `UseAppOptions`
- Pass through to App constructor
## Usage
Apps work transparently in both environments:
```typescript
// Works in both MCP hosts and ChatGPT
const app = new App(appInfo, capabilities);
await app.connect(); // Auto-detects platform
// Force MCP-only mode
const app = new App(appInfo, capabilities, {
experimentalOAICompatibility: false
});
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
- Dynamic capability detection based on window.openai availability - Report availableDisplayModes when requestDisplayMode is available - Include toolResponseMetadata as _meta in tool-result notification - registerAppTool adds openai/outputTemplate metadata automatically - registerAppResource registers both MCP and OpenAI (+skybridge) variants - Preserve custom MIME types in OpenAI resource callback 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
commit: |
The learn_threejs tool was added in #173, which adds a second option in the Tool dropdown. This updates the golden snapshot to match. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Change _meta: null to _meta: undefined in OpenAI transport - Register default no-op handlers for all tool notifications in App constructor The SDK's Protocol class throws 'Unknown message type' for unhandled notifications. Now all tool-related notifications have default handlers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Test that null _meta is converted to undefined in OpenAI transport - Test that default no-op handlers accept tool notifications without error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Check for both null and undefined before delivering tool-result notification. Previously null passed through and was stringified. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Handle different shapes of toolOutput from ChatGPT:
- Array of content blocks: use directly
- Single content block {type, text}: wrap in array
- Object with just {text}: extract and wrap
- Other: stringify as fallback
This prevents double-stringification when ChatGPT passes content
in different formats.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
When toolOutput contains structuredContent, include it in the tool-result notification. Also auto-extract structuredContent from plain objects that aren't content arrays. This allows apps to access structured data directly without parsing JSON from text content. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Enable MCP Apps to run transparently in ChatGPT by bridging the MCP Apps protocol to OpenAI's
window.openaiAPI.Client-side: Same app code works in both environments:
Server-side: Single registration serves both platforms:
Motivation
MCP Apps and OpenAI Apps SDK solve similar problems with different protocols. Rather than forcing developers to maintain two codebases, this PR allows a single MCP App to run in both:
PostMessageTransportOpenAITransportThis aligns with broader cross-platform goals discussed in #169 (A2UI interoperability) and #34 (iframe-embed reuse pattern).
Design Principles
experimentalOAICompatibility(default:true) enables transparent platform detection.window.openaiactually supports.Protocol Mapping
Fully Bridged (App → Host)
ui/initializetools/callcallTool()ui/messagesendFollowUpMessage()ui/open-linkopenExternal()ui/request-display-moderequestDisplayMode()ui/notifications/size-changednotifyIntrinsicHeight()Fully Bridged (Host → App)
toolInputui/notifications/tool-inputtoolOutputui/notifications/tool-resulttoolResponseMetadata_metain tool-resultCapability Detection
Capabilities are reported dynamically based on actual
window.openaiavailability:serverTools!!openai.callToolhostCapabilitiesopenLinks!!openai.openExternalhostCapabilitieslogginghostCapabilitiesavailableDisplayModes!!openai.requestDisplayModehostContextThis addresses part of #41 (display mode negotiation) by accurately reporting available modes.
Server-Side Dual Registration
The server helpers automatically handle platform differences:
_meta.ui.resourceUri_meta["openai/outputTemplate"](auto-added)ui://weather/widget.htmlui://weather/widget.html+skybridgetext/html;profile=mcp-apptext/html+skybridgeWhen you call
registerAppResource(), it registers two resources:+skybridgesuffixCustom MIME types in the callback are preserved; only the default MCP MIME type is converted to skybridge.
Not Bridged (Would Require Spec Additions)
widgetState/setWidgetStateviewpropertyrequestClose()uploadFile()/getFileDownloadUrl()requestModal()Test Coverage
isOpenAIEnvironment)toolInput,toolOutput,_meta)Breaking Changes
None. The
experimentalOAICompatibilityoption defaults totruebut falls back gracefully whenwindow.openaiis not present.Related Issues: #169, #41, #62, #34, #147
Related PRs: #125
🤖 Generated with Claude Code