Decorators & GPT Apps
This page covers server-side decorators for linking tools to UI components, and ChatGPT-specific providers and hooks.@UIApp Decorator
Links an MCP tool to a React UI component for ext-apps hosts (Claude Desktop, MCP-compatible hosts). When a tool decorated with@UIApp is called, the host will:
- Execute the tool and get the result
- Fetch the linked UI component as an HTML resource
- Render the UI in an iframe with the tool result
Basic Usage
Use a path string (e.g.,
'./WeatherCard') for the component to avoid importing browser code in your server bundle. The CLI will resolve and build the component separately.With Custom URI
Options
The UI Component
Your UI component receives the tool result viauseToolResult:
@GPTApp Decorator
Links an MCP tool to a React UI component specifically for ChatGPT GPT Actions.Options
GPTAppProvider
Context provider for ChatGPT Apps using the nativewindow.openai SDK.
Basic Setup
Props
useGptApp
Access the GPT App context including connection state and theme.useGptTool
Call MCP tools via ChatGPT’s SDK with loading and error states.Basic Usage
Return Value
useAuth
Handle OAuth authentication flows in GPT Apps. This hook integrates with ChatGPT’s native OAuth linking UI.Basic Usage
How It Works
- When a tool returns
_meta["mcp/www_authenticate"], ChatGPT displays an OAuth linking prompt - The
useAuthhook detects this and updatesisAuthenticatedstate - Calling
login()triggers the OAuth flow by calling an auth-required tool - After successful OAuth, ChatGPT automatically retries the tool call
Return Value
AuthUser Type
With Protected Tools
CombineuseAuth with tools that require authentication:
Server-Side Auth Errors
For the auth flow to work, your server tool should return MCP-compliant auth errors:Environment Differences
ext-apps vs ChatGPT
Shared Features
Both environments support:- Tool execution
- Theme awareness (light/dark)
- Auto-applied styles via
@leanmcp/ui/styles.css - Testing with
MockAppProvider
Complete GPT App Example
Related
- @leanmcp/ui Overview - Introduction to MCP-native React components
- UI Components - Pre-built MCP components
- UI Hooks - All available React hooks
- Authentication Overview - Server-side authentication with
@Authenticated - OAuth Server & Proxy - Build OAuth authorization servers
- Auth & Payment Guide - Complete authentication integration guide

