Skip to main content

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:
  1. Execute the tool and get the result
  2. Fetch the linked UI component as an HTML resource
  3. 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 via useToolResult:

@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 native window.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

  1. When a tool returns _meta["mcp/www_authenticate"], ChatGPT displays an OAuth linking prompt
  2. The useAuth hook detects this and updates isAuthenticated state
  3. Calling login() triggers the OAuth flow by calling an auth-required tool
  4. After successful OAuth, ChatGPT automatically retries the tool call

Return Value

AuthUser Type

With Protected Tools

Combine useAuth 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