Skip to main content
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

DatabaseConfig
required
Database connection config. Required.
AgentConfig
Agent identity settings.
McpConfig
MCP OAuth 2.1 authorization server.
{ adapter?: AuthAdapter; session?: SessionConfig }
Human auth adapter and session config.
AnomalyConfig
Anomaly detection thresholds.
ApprovalConfig
CIBA async approval flow config.
TrustConfig
Graduated autonomy trust scoring.
TelemetryConfig
OpenTelemetry integration via hooks.
KavachHooks
Lifecycle hooks for sandboxing and custom validation.
string
Base URL for the auth server (e.g. https://auth.example.com).
string
Secret key used to sign tokens. Min 32 characters.

Database config

"sqlite" | "postgres" | "mysql" | "d1"
required
Database driver to use.
string
File path for SQLite, connection string for Postgres/MySQL. Not used with D1.
D1Database
D1Database binding from the Worker environment. Required when provider is “d1”.
boolean
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.
boolean
required
Enable agent identity management.
number
Maximum number of agents a single user can create.
string[]
Permission strings assigned to every new agent unless overridden.
boolean
Write every agent action to the audit log regardless of permission outcome.
string
Default token expiry duration string (e.g. “7d”, “24h”, “30m”).

MCP config

Enables the OAuth 2.1 authorization server for MCP-compliant tool access.
boolean
required
Enable the MCP authorization server.
string
Token issuer URL. Appears as the iss claim in JWTs.
string
Base path for MCP endpoints.
string
Secret used to sign JWTs. Min 32 characters. Defaults to the top-level secret.
number
Access token lifetime in seconds. Defaults to 3600 (1 hour).
number
Refresh token lifetime in seconds. Defaults to 604800 (7 days).
number
Authorization code lifetime in seconds. Defaults to 600 (10 minutes).
boolean
Reject all MCP requests without a valid Bearer token.
string[]
Custom OAuth scopes supported by this server.
string[]
Allowed resource URIs for RFC 8707 resource indicators.
string
URL of your login page. Users are redirected here when unauthenticated.
URL of your consent page. Users are redirected here to approve scopes.
OAuth clients registered at startup (first-party apps, CLIs, test fixtures).
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.
When auth is omitted, kavach.auth.resolveUser() always returns null (manual user management mode). See Auth adapters for all adapter options.

Session config

string
required
Signing secret for session JWTs. Min 32 characters.
number
default:"604800 (7 days)"
Session lifetime in seconds.
Name of the session cookie.

Password reset config

Requires auth.session to be configured. The caller provides an email-sending callback.
required
Callback to deliver the reset email. Receives email, raw token, and constructed URL.
string
required
Base URL for the reset page. Token is appended as ?token=…
number
default:"3600 (1h)"
Reset token lifetime in seconds.
boolean
default:"true"
Revoke all sessions when the password is successfully reset.
number
default:"8"
Minimum new password length.
number
default:"128"
Maximum new password length.
Always use an HTTPS URL for resetUrl in production. Reset tokens in plain HTTP links can be intercepted in transit or leaked via Referer headers.

Session freshness config

Controls when sessions are considered “fresh” for sensitive operations like password changes and passkey registration.
number
default:"300 (5 minutes)"
Maximum session age in seconds to be considered fresh.

Plugins

KavachOS features are composable. Enable what you need:

Anomaly config

number
Calls per agent per hour before flagging as high-frequency. Defaults to 500.
number
Denial rate percentage that triggers an alert. Defaults to 50.
{ start: number; end: number }
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

secret and mcp.signingSecret must be at least 32 characters. In production, generate them with openssl rand -base64 32.

Next steps

Migration guides

Switch from better-auth, Clerk, or other providers.

Database setup

SQLite, Postgres, or MySQL configuration.

Framework adapters

Mount KavachOS on your framework.
Last modified on April 29, 2026