Skip to main content
Kontext is the identity control plane for AI agents. The client SDK is the developer path to that control plane: authenticate users, discover tools, and execute actions with credentials scoped at runtime and audited centrally.

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 a url.

Single-endpoint mode

Pass url to connect directly to a specific MCP server:
Use this when your application talks to one MCP server and you know its endpoint.

Hybrid mode

Omit url to use the Kontext gateway, which aggregates tools from multiple integrations:
In hybrid mode, the client routes tool calls through the gateway and can also connect to integrations directly. Tool IDs can come from gateway listings or internal integration normalization, so always use the IDs returned by client.tools.list().

Configuration reference

Callbacks

onAuthRequired

Fires when the client needs the user to log in. You receive a URL 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 a state property that follows this lifecycle:

Event listeners

Subscribe to state changes and errors with client.on(). The function returns an unsubscribe callback.
Both 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, and KontextTool.