Kontext is the identity control plane for AI agents. The server SDK is the runtime bridge: your MCP server requests credentials per tool call, while Kontext handles policy enforcement, token brokering, and audit logging centrally. The SDK also handles OAuth metadata, bearer token verification, CORS, session management, and MCP transport, so you can focus on tools and business logic.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.
Install
Minimal example
What the middleware handles
When you callkontext.middleware(), it mounts an Express router that handles:
- OAuth metadata —
GET /.well-known/oauth-authorization-serverresponds with authorization server metadata, andGET /.well-known/oauth-protected-resource{mcpPath}(default/.well-known/oauth-protected-resource/mcp) responds with protected resource metadata (RFC 9728). MCP clients use both for discovery. - MCP transport —
POST /mcphandles the Streamable HTTP MCP transport. Configurable via themcpPathoption. - Bearer auth — Every request is verified against the authorization server’s JWKS. Pass a custom
verifierto override. - CORS — Pre-configured for browser-based MCP clients like the MCP Inspector.
- Session management — Each session gets tracked, with auto-cleanup after 1 hour of inactivity.
Getting integration credentials
Inside your tool handlers, callkontext.require() with an integration name and either the current user’s Kontext token or a known external end-user ID:
userId mode.
Next steps
- Middleware — Configure the Express middleware, session hooks, and custom verifiers.
- Credentials — Deep dive on
require(), error handling, and the elicitation flow. - Production — Deployment checklist for running in production.
- Server Types — Full type reference for
Kontext,MiddlewareOptions, andIntegrationCredential.