@kontext-dev/js-sdk package is the developer entry point to the Kontext identity control plane. Use it to build agents with runtime identity, connect to external systems with short-lived scoped credentials, and keep policy and audit control centralized in Kontext.
@kontext-dev/[email protected]includes hard-cutover runtime integration semantics, includingconnectType: "user_token"for per-user API key flows andkontext.require(..., { userId })for confidential server-side exchanges keyed by an external end-user ID.
Choose a path
Server SDK
Build MCP servers with middleware, scoped credentials, and production controls.
Client SDK
Build app-facing clients with auth, tool execution, and token storage.
Frameworks
Integrate with Vercel AI SDK, Cloudflare Agents, and React.
Management SDK
Automate applications, integrations, service accounts, sessions, and traces.
Install
Subpath exports
The package supports both root exports and subpath exports. Subpath imports are recommended when you want the narrowest surface area.| Import Path | Export | Purpose |
|---|---|---|
@kontext-dev/js-sdk | createKontextClient, createKontextOrchestrator, Kontext (+ shared types/errors) | Root convenience entry point |
@kontext-dev/js-sdk/client | createKontextClient | Client SDK factory |
@kontext-dev/js-sdk/server | Kontext | Server SDK class |
@kontext-dev/js-sdk/ai | toKontextTools | Vercel AI SDK adapter |
@kontext-dev/js-sdk/react | useKontext, KontextProvider, useKontextContext | React hooks and provider |
@kontext-dev/js-sdk/react/cloudflare | useKontextAgent, useKontextContext | React hooks for Cloudflare Agents |
@kontext-dev/js-sdk/cloudflare | withKontext, KontextCloudflareOAuthProvider, DurableObjectKontextStorage | Cloudflare Agents adapter |
@kontext-dev/js-sdk/management | KontextManagementClient | Management API client |
@kontext-dev/js-sdk/mcp | KontextMcp | Low-level MCP client |
@kontext-dev/js-sdk/errors | KontextError, translateError, isKontextError, isNetworkError, isUnauthorizedError | Error types, translation, and guards |
@kontext-dev/js-sdk/verify | KontextTokenVerifier | Token verification |
@kontext-dev/js-sdk/oauth | OAuth utilities | OAuth helpers |
Peer dependencies
Install peer dependencies based on which entry points you use.| Package | Version | Required For |
|---|---|---|
@modelcontextprotocol/sdk | ^1.26.0 | Server SDK (@kontext-dev/js-sdk/server) |
express | ^4.21.0 or ^5.0.0 | Server SDK (@kontext-dev/js-sdk/server) |
ai | ^4.0.0 | Vercel AI adapter (@kontext-dev/js-sdk/ai) |
react | ^18.0.0 or ^19.0.0 | React adapter (@kontext-dev/js-sdk/react) |
agents | >=0.4.0 | Cloudflare adapter (@kontext-dev/js-sdk/cloudflare) |
Environment variables
| Variable | Used By | Description |
|---|---|---|
KONTEXT_CLIENT_SECRET | Server SDK | Client secret for token exchange. Set this instead of passing clientSecret in code. |
KONTEXT_TOKEN_ISSUER | Server SDK | Custom token issuer URL(s). Comma-separated for multiple issuers. |
KONTEXT_CLIENT_ID | Cloudflare adapter | Application client ID. Read automatically by the withKontext mixin. |
KONTEXT_CLIENT_SECRET automatically. You do not need to pass it in the constructor if the environment variable is set.