createKavach() accepts a KavachConfig object. The only required field is database. Everything else is optional and enables features incrementally.
Common development setup
A minimal config for local development with email/password auth and no email sending:Top-level options
Database connection config. Required.
Agent identity settings.
MCP OAuth 2.1 authorization server.
Human auth adapter and session config.
Anomaly detection thresholds.
CIBA async approval flow config.
Graduated autonomy trust scoring.
OpenTelemetry integration via hooks.
Lifecycle hooks for sandboxing and custom validation.
Base URL for the auth server (e.g. https://auth.example.com).
Secret key used to sign tokens. Min 32 characters.
Database config
Database driver to use.
File path for SQLite, connection string for Postgres/MySQL. Not used with D1.
D1Database binding from the Worker environment. Required when provider is “d1”.
Skip automatic CREATE TABLE IF NOT EXISTS on init. Use when you manage migrations externally (Flyway, drizzle-kit push, etc.). Defaults to false.
Agent config
Controls the agent identity lifecycle.Enable agent identity management.
Maximum number of agents a single user can create.
Permission strings assigned to every new agent unless overridden.
Write every agent action to the audit log regardless of permission outcome.
Default token expiry duration string (e.g. “7d”, “24h”, “30m”).
MCP config
Enables the OAuth 2.1 authorization server for MCP-compliant tool access.Enable the MCP authorization server.
Token issuer URL. Appears as the iss claim in JWTs.
Base path for MCP endpoints.
Secret used to sign JWTs. Min 32 characters. Defaults to the top-level secret.
Access token lifetime in seconds. Defaults to 3600 (1 hour).
Refresh token lifetime in seconds. Defaults to 604800 (7 days).
Authorization code lifetime in seconds. Defaults to 600 (10 minutes).
Reject all MCP requests without a valid Bearer token.
Custom OAuth scopes supported by this server.
Allowed resource URIs for RFC 8707 resource indicators.
URL of your login page. Users are redirected here when unauthenticated.
URL of your consent page. Users are redirected here to approve scopes.
preRegisteredClients
OAuth clients registered at startup (first-party apps, CLIs, test fixtures).
getAdditionalClaims
Async function to add custom claims to issued tokens.
Auth config
Connects KavachOS to your existing auth provider so it can resolve the human user behind incoming requests.auth is omitted, kavach.auth.resolveUser() always returns null (manual user management mode).
See Auth adapters for all adapter options.
Session config
Signing secret for session JWTs. Min 32 characters.
Session lifetime in seconds.
Name of the session cookie.
Password reset config
Requiresauth.session to be configured. The caller provides an email-sending callback.
Callback to deliver the reset email. Receives email, raw token, and constructed URL.
Base URL for the reset page. Token is appended as ?token=…
Reset token lifetime in seconds.
Revoke all sessions when the password is successfully reset.
Minimum new password length.
Maximum new password length.
Session freshness config
Controls when sessions are considered “fresh” for sensitive operations like password changes and passkey registration.Maximum session age in seconds to be considered fresh.
Plugins
KavachOS features are composable. Enable what you need:| Plugin | Import | What it does |
|---|---|---|
emailPassword | kavachos/auth | Email + password with verification and reset |
passkey | kavachos/auth | WebAuthn/FIDO2 biometric auth |
magicLink | kavachos/auth | Passwordless email links |
emailOtp | kavachos/auth | One-time password codes via email |
twoFactor | kavachos/auth | TOTP 2FA with backup codes |
multiSession | kavachos/auth | Session limits and device management |
organization | kavachos/auth | Organizations with RBAC |
apiKeys | kavachos/auth | Static API key management |
admin | kavachos/auth | User management, banning, impersonation |
stripe | kavachos/auth | Stripe billing integration |
polar | kavachos/auth | Polar payment integration |
Anomaly config
Calls per agent per hour before flagging as high-frequency. Defaults to 500.
Denial rate percentage that triggers an alert. Defaults to 50.
Flag access outside these hours (0-23) as off-hours anomaly. Optional.
Environment variables pattern
Never hardcode secrets in config. Pass them through environment variables:Dev vs production example
Next steps
Auth adapters
Connect to better-auth, Auth.js, or Clerk.
Database setup
SQLite, Postgres, or MySQL configuration.
Framework adapters
Mount KavachOS on your framework.