Skip to main content
sunpeak API

Overview

The usePlatform hook returns the platform type reported by the host. It is a convenience wrapper around useHostContext.
This returns the host-reported platform from McpUiHostContext.platform, not a runtime detection. For runtime host detection (ChatGPT vs Claude), see detectHost.

Wraps onhostcontextchanged

MCP Apps SDK reference

Import

import { usePlatform } from 'sunpeak';

Signature

function usePlatform(): HostPlatform | undefined

Returns

return
'web' | 'desktop' | 'mobile' | undefined
The platform type reported by the host. undefined if the host does not report a platform.

Usage

import { usePlatform } from 'sunpeak';

function MyResource() {
  const platform = usePlatform();

  return (
    <div className={platform === 'mobile' ? 'p-2 text-sm' : 'p-4'}>
      Running on {platform ?? 'unknown platform'}
    </div>
  );
}
The platform value comes from McpUiHostContext.platform.