kontext.require() inside your tool handlers to get credentials for any connected integration. The SDK handles token exchange, caching, and error handling.
There are two supported call shapes:
kontext.require("github", authInfo.token)when you have the authenticated user’s Kontext access token.kontext.require("github", { userId })when your confidential server already knows the caller’s external subject ID and external auth is configured.
IntegrationCredential shape
kontext.require() returns an IntegrationCredential object:
authorization field is ready to drop into an HTTP header:
Built-in caching
The SDK caches credentials per integration per token using an LRU cache (max 500 entries). Cache TTL is the minimum ofexpiresIn - 60s and 5 minutes. You do not need to cache credentials yourself.
Repeated calls to kontext.require("github", token) within the same session return the cached credential without a network round-trip.
The SDK keeps token-mode and userId-mode exchanges in separate cache buckets, so the two flows never collide.
Exchange by external user ID
Use{ userId } for hard-cutover partner or credential-vault flows where your backend already has a stable external identifier for the end user.
userId as the RFC 8693 subject_token with the custom type urn:kontext:user-id.
Error handling
When a user has not connected an integration,kontext.require() throws an IntegrationConnectionRequiredError. This error may include a connectUrl that the user can open in a browser to authorize the integration.
| Field | Type | Description |
|---|---|---|
integrationId | string | Integration identifier |
integrationName | string | undefined | Human-readable name |
connectUrl | string | undefined | URL for the user to authorize the integration |
code | string | Always "kontext_integration_connection_required" |
kontext.require() with { userId }, connectUrl is intentionally omitted. That mode has no bearer token available to mint a user-facing connect session, so your app must route the user through its own connect flow.
MCP clients that support elicitation will display the connectUrl to the user automatically when it is present. Return it in the tool response so the AI model can instruct the user.
requireCredentials() for credential-based integrations
Some integrations use API keys or other static credentials instead of OAuth tokens. Use requireCredentials() to resolve these.
requireCredentials() returns:
IntegrationConnectionRequiredError if the user has not provided the required credentials.
Known integrations
The SDK provides type hints for common integrations:github,slack,linear,notion,jira,confluencegmail,google-calendar,google-drive,figmastripe,shopify,salesforce,hubspot,asanadiscord,twilio,sendgrid,openai,anthropic
Next steps
- Production — Deployment checklist for running in production.
- Server Types — Full type reference for
IntegrationCredentialandIntegrationResolvedCredentials. - Errors — Full error hierarchy, error codes, and handling patterns.