> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kontext.security/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Install and configure the Kontext TypeScript SDK for agents with runtime identity and scoped credentials.

The `@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/js-sdk@1.1.0` includes hard-cutover runtime integration semantics, including `connectType: "user_token"` for per-user API key flows and `kontext.require(..., { userId })` for confidential server-side exchanges keyed by an external end-user ID.

## Choose a path

<CardGroup cols={2}>
  <Card title="Server SDK" icon="server" href="/server/overview">
    Build MCP servers with middleware, scoped credentials, and production controls.
  </Card>

  <Card title="Client SDK" icon="desktop" href="/client/overview">
    Build app-facing clients with auth, tool execution, and token storage.
  </Card>

  <Card title="Frameworks" icon="puzzle-piece" href="/frameworks/vercel-ai">
    Integrate with Vercel AI SDK, Cloudflare Agents, and React.
  </Card>

  <Card title="Management SDK" href="/sdks/management">
    Automate applications, integrations, service accounts, sessions, and traces.
  </Card>
</CardGroup>

Type signatures and interfaces are in the [API Reference](/sdks/typescript/client).

## Install

```bash theme={"system"}
npm install @kontext-dev/js-sdk
```

## 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`) |

Your package manager will warn about missing peer dependencies when you import an entry point that needs them.

## 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.                 |

The server SDK reads `KONTEXT_CLIENT_SECRET` automatically. You do not need to pass it in the constructor if the environment variable is set.
