Low-level MCP client
createKontextClient instead — this is for advanced use cases where you need raw MCP transport control.
Methods
| Method | Returns | Description |
|---|---|---|
listTools() | Promise<Tool[]> | List available MCP tools. |
callTool(name, args?) | Promise<CallToolResult> | Execute a tool by name. |
handleCallback(url) | Promise<void> | Complete the OAuth callback. |
disconnect() | Promise<void> | Close the MCP connection. |
clearAuth() | Promise<void> | Remove stored tokens. |
isCallback(url) | boolean | Check if a URL is an OAuth callback. |
createConnectSession() | Promise<ConnectSessionResult> | Create a connect page session. |
listRuntimeIntegrations() | Promise<RuntimeIntegrationRecord[]> | List available integrations and their status. |
Properties
| Property | Type | Description |
|---|---|---|
isConnected | boolean | Whether the MCP connection is active. |
sessionId | string? | Current session ID, if connected. |
Runtime integration shape
listRuntimeIntegrations() returns records with explicit connect semantics:
connectType: "user_token", prompt the user to provide an API key/token in the connect UI flow.
For admin-managed shared tokens, the runtime record uses connectType: "none" together with authMode: "server_token". Treat these as read-only runtime entries: there is nothing for the end user to connect.
The runtime integration parser is strict: unknown or missing connectType values throw kontext_runtime_integrations_invalid_response.
Error types
Error classes
| Class | Typical code | Description |
|---|---|---|
AuthorizationRequiredError | kontext_authorization_required | User needs to sign in. |
IntegrationConnectionRequiredError | kontext_integration_connection_required | Integration needs user connection (OAuth or API key). Has connectUrl. |
OAuthError | varies (for example kontext_oauth_token_exchange_failed) | OAuth flow failed. |
ConfigError | varies (for example kontext_config_missing_client_id) | SDK misconfiguration. |
NetworkError | kontext_network_error | Connection failure. |
HttpError | varies (for example kontext_not_found, kontext_rate_limited) | HTTP error with status code. |
Type guards
| Function | Checks |
|---|---|
isKontextError(err) | Any KontextError subclass. |
isNetworkError(err) | Network-level failures (DNS, timeout, refused). |
isUnauthorizedError(err) | 401 responses. |
Error translation
translateError(err) normalizes MCP JSON-RPC errors, Streamable HTTP failures, unauthorized responses, and browser/network failures into KontextError subclasses or kontext_* codes.
Use it when you are working directly with KontextMcp, raw MCP SDK errors, or custom wrappers and want the same classification behavior as the higher-level client/orchestrator.
Token verification
Additional methods
| Method | Returns | Description |
|---|---|---|
verifyOrNull(token) | Promise<VerifiedTokenClaims | null> | Returns claims if valid, null if invalid. Simpler API when you don’t need error details. |
clearCache() | void | Clear the JWKS cache, forcing a fresh fetch on next verification. |
OAuth utilities
createKontextClient or the React adapter, which handle OAuth automatically.