MCP Apps Kit - v0.5.0
    Preparing search index...

    Class OpenAIAdapter

    Index

    Constructors

    Methods

    • Call a server tool

      Parameters

      • name: string

        Tool name

      • args: Record<string, unknown>

        Tool arguments

      Returns Promise<unknown>

      Tool result

    • Configure logging transport settings

      Parameters

      • config: OpenAIAdapterLogConfig

        Logging configuration

      Returns void

    • Connect to the host platform Called during client initialization

      Returns Promise<void>

    • Get file download URL May throw on unsupported platforms

      Parameters

      • fileId: string

        File ID

      Returns Promise<{ downloadUrl: string }>

      Download URL

    • Get host capabilities Returns capabilities advertised during handshake

      Returns HostCapabilities

    • Get host version information Returns host name and version

      Returns HostVersion

    • Get persisted widget state On MCP Apps: Returns null (silent no-op for graceful degradation) On ChatGPT: Returns session-scoped state

      Type Parameters

      • S

      Returns S

      State or null if not set

    • Get current tool input

      Returns Record<string, unknown>

    • Get current tool metadata

      Returns Record<string, unknown>

    • Get current tool output

      Returns Record<string, unknown>

    • Check if the adapter is connected

      Returns boolean

    • Log to host console

      Parameters

      • level: string

        Log level

      • data: unknown

        Data to log

      Returns void

    • Subscribe to host context changes

      Parameters

      • handler: (context: HostContext) => void

        Callback for context changes

      Returns () => void

      Unsubscribe function

    • Subscribe to teardown events

      Parameters

      • handler: (reason?: string) => void

        Callback for teardown

      Returns () => void

      Unsubscribe function

    • Subscribe to tool cancellation

      Parameters

      • handler: (reason?: string) => void

        Callback for cancellation

      Returns () => void

      Unsubscribe function

    • Subscribe to tool input changes

      Parameters

      • handler: (input: unknown) => void

        Callback for tool input

      Returns () => void

      Unsubscribe function

    • Subscribe to partial/streaming tool input

      Parameters

      • _handler: (input: unknown) => void

      Returns () => void

      Unsubscribe function

    • Subscribe to tool results

      Parameters

      • handler: (result: unknown) => void

        Callback for tool results

      Returns () => void

      Unsubscribe function

    • Open an external link

      Parameters

      • url: string

        URL to open

      Returns Promise<void>

    • Read an MCP resource

      Parameters

      • uri: string

        Resource URI

      Returns Promise<{ contents: ResourceContent[] }>

      Resource contents

    • Request widget close May be a no-op on some platforms

      Returns void

    • Request a different display mode

      Parameters

      • mode: string

        Target display mode

      Returns Promise<{ mode: string }>

      Actual mode applied

    • Send a log message to the host via the protocol

      Parameters

      • level:
            | "error"
            | "debug"
            | "info"
            | "warning"
            | "notice"
            | "critical"
            | "alert"
            | "emergency"

        Log level

      • data: unknown

        Data to log

      Returns Promise<void>

    • Send batched log entries to the server

      Parameters

      • entries: LogEntry[]

        Array of log entries to send

      Returns Promise<{ processed: number }>

      Number of entries processed

    • Send a message to the conversation

      Parameters

      • content: { text: string; type: string }

        Message content

      Returns Promise<void>

    • Send size changed notification to host

      Parameters

      • params: SizeChangedParams

        Size parameters (width, height)

      Returns Promise<void>

    • Set handler for tool calls from the host

      Parameters

      • _handler: CallToolHandler

      Returns void

    • Set handler for listing app-exposed tools

      Parameters

      • _handler: ListToolsHandler

      Returns void

    • Set persisted widget state On MCP Apps: Silent no-op (graceful degradation) On ChatGPT: Persists session-scoped state

      Type Parameters

      • S

      Parameters

      • state: S

        State to persist

      Returns void

    • Update model context (ext-apps v0.4.0+)

      On ChatGPT, this method uses setState() internally, which calls the OpenAI SDK's setWidgetState(). In ChatGPT, setWidgetState() exposes data to the AI model context, making it visible to the model.

      ChatGPT Implementation Details:

      • Uses setState/setWidgetState (exposes to AI + persists for session)
      • Each call replaces the previous context (not accumulated)
      • Context persists for the widget's session lifetime
      • Be mindful of data size when sending large structured content

      MCP Apps Implementation:

      • Pure context update via native protocol feature
      • No persistence, only sent to model with next user message

      Reserved Keys:

      • Keys starting with underscore (_) in structuredContent are filtered
      • Internal keys use double-underscore prefix (__mcp_*)

      Use updateModelContext() for context-focused use cases (informing the model about app state), and setState() for persistence-focused use cases. Note: On ChatGPT, both methods expose state to the AI model.

      Parameters

      Returns Promise<void>

    • Upload a file May throw on unsupported platforms

      Parameters

      • file: File

        File to upload

      Returns Promise<{ fileId: string }>

      File ID