Install
Quick start
createKontextClient is the main entry point. It returns a KontextClient that handles authentication, tool discovery, and tool execution.
Two modes
The client operates in one of two modes depending on whether you pass aurl.
Single-endpoint mode
Passurl to connect directly to a specific MCP server:
Hybrid mode
Omiturl to use the Kontext gateway, which aggregates tools from multiple integrations:
client.tools.list().
Configuration reference
Callbacks
onAuthRequired
Fires when the client needs the user to log in. You receive aURL pointing to the OAuth authorization page. Return the callback URL (as a string or URL) to complete the flow inline, or return void to handle the callback separately via client.auth.handleCallback().
onIntegrationRequired
Fires when a tool call fails because the user has not connected the underlying integration. You receive the connect URL and integration metadata. Open this URL so the user can authorize the integration.onStateChange
Fires on every state transition. Useful for driving loading indicators and error UI.Client state
The client tracks astate property that follows this lifecycle:
Event listeners
Subscribe to state changes and errors withclient.on(). The function returns an unsubscribe callback.
on("stateChange") and the onStateChange config callback fire on every transition. Use whichever pattern fits your application — on() is better when you need to add and remove listeners dynamically.
Next steps
- Tools — Discover and execute MCP tools.
- Authentication — OAuth sign-in, callbacks, and session management.
- Storage — Persist tokens with custom storage backends.
- Client Types — Full type reference for
KontextClient,KontextClientConfig, andKontextTool.