Install
Complete example
KontextProvider
Wrap your app with KontextProvider to manage the OAuth popup lifecycle. The provider internally uses the useKontext hook and passes its state to all child components via React Context.
popupFeatures— A string passed towindow.open()to control popup size and position. Defaults to"width=600,height=700".onAuthComplete— Called when the auth popup closes.
useKontext hook
The low-level hook for popup handling. Use it directly when you want to wire MCP updates yourself (for example with useAgent from agents/react).
authenticating—truewhile the OAuth popup is open and the user is signing in. Use this to show a loading state.onMcpUpdate— A callback function that receives MCP state updates. Pass this to your agent framework to keep tool state in sync.handleElicitationUrl— A function that opens a popup for integration-specific OAuth. Call this when a user needs to connect a new integration (GitHub, Slack, etc.).
OAuth popup flow
The SDK handles OAuth entirely through popups:KontextProviderdetects the user needs to authenticate.- A popup opens to the Kontext authorization page.
- The user signs in and grants consent.
- The popup redirects to the backend’s OAuth callback handler, the authorization code is exchanged for tokens, and the popup closes.
authenticatingflips tofalseand your app has a valid session.
Integration with Cloudflare useAgent
Pass onMcpUpdate to the useAgent hook to sync MCP tool state between your Cloudflare Agent and the React frontend:
onMcpUpdate keeps the frontend in sync.
If you’re already using KontextProvider, you can skip this manual wiring and use useKontextAgent() from @kontext-dev/js-sdk/react/cloudflare.
Integration connection popups
When a user needs to connect an integration they haven’t authorized yet, callhandleElicitationUrl with the connection URL:
useKontextContext
Access the raw provider state if you need lower-level control:
KontextProvider. If you’re integrating with Cloudflare Agents, prefer useKontextAgent for most cases.
Next steps
- Cloudflare Agents — Build the backend agent that pairs with your React frontend.
- Vercel AI SDK — Use Kontext tools with
generateTextandstreamText. - How Kontext Works — Understand the Kontext architecture and credential flow.