Which flow do I need?
| I want to… | Flow | SDK |
|---|---|---|
| Build an app where users connect accounts and agents call tools on their behalf | Authorization Code + PKCE | Client SDK |
| Build an MCP server that requests credentials inside tool handlers | Credential exchange via kontext.require() | Server SDK |
| Manage infrastructure (create apps, configure integrations, set policies) | Client Credentials | Management SDK or REST API |
How Kontext relates to your IdP
Kontext does not replace your identity provider for humans. Your users keep signing in through Okta, Google, Azure AD, or whatever IdP you use today.Applications: Authorization Code + PKCE
When your application needs to act on behalf of a user, it uses the standard OAuth2 authorization code flow with PKCE.Step 1: Redirect to authorization
Step 2: User grants consent
The user sees what permissions are being requested and approves. One approval per session.Step 3: Exchange code for tokens
Step 4: Use access token
Use the access token to call MCP tools viaPOST /mcp, or pass it to kontext.require() on your server to exchange it for integration credentials.
The Client SDK handles this entire flow automatically. See the Client SDK for details.
Refreshing tokens
Server-side credential exchange
Once your application has a user’s access token (from the PKCE flow above), your server exchanges it for integration-specific credentials usingkontext.require():
Service accounts: Client Credentials
Service accounts authenticate using OAuth2 client credentials. This is a machine-to-machine flow with no user interaction. Use this flow when your backend needs to manage infrastructure: create applications, configure integrations, set policies./api/v1/*). Service accounts cannot invoke tools or access integration credentials. They are for infrastructure management only.
What’s next
Quickstart
See these flows in action with a working example
Server SDK: Credentials
Exchange user tokens for integration credentials
Client SDK
Handle auth flows, tool execution, and storage
Errors
Handle auth errors, connection errors, and policy denials