Documentation Index
Fetch the complete documentation index at: https://docs.kavachos.com/llms.txt
Use this file to discover all available pages before exploring further.
What the gateway does
The KavachOS Gateway is a standalone HTTP reverse proxy. Every request to your API or MCP server passes through it first. The gateway:- Validates Bearer tokens against a KavachOS instance
- Checks agent permissions before forwarding
- Enforces global and per-route rate limits
- Records an audit trail for every request
- Handles CORS preflight
- Strips or forwards the Authorization header depending on your config
When to use it
Use the gateway when you want to add auth to something that doesn’t have it. Common cases:- A local tool server or MCP server that accepts unauthenticated connections
- A third-party API you’re exposing to agents
- A service you can’t modify but need to wrap with auth
- Staging environments where you want to restrict access
Quick start
The fastest path is the one-liner:http://localhost:8080. Requests without a valid KavachOS Bearer token are rejected with 401.
Check the health endpoint to confirm it’s running:
Configuration
CLI flags
| Flag | Default | Description |
|---|---|---|
--upstream | required | URL of the upstream service |
--port | 3000 | Port the gateway listens on |
--database | :memory: | SQLite database path for KavachOS |
--config | , | Path to a gateway.json config file |
--strip-auth | false | Remove the Authorization header before forwarding |
--no-audit | false | Disable audit trail recording |
gateway.json
For more control, put your config in a JSON file and pass it with--config:
Embedded mode
Use the gateway inside your own Node.js application without starting a separate process:Policy rules
Policies are matched in order. The first policy whosepath pattern and method (if set) match the incoming request wins.
Glob patterns
Patterns use standard glob syntax via micromatch:| Pattern | Matches |
|---|---|
/api/* | /api/users, /api/items (one level) |
/api/** | /api/users, /api/v2/users/123 (any depth) |
/health | /health exactly |
/** | everything |
Auth flow per request
- Check if the path is
/_kavach/health, serve locally, no upstream - Handle CORS preflight if
corsis configured - Match the request against policies (path + method)
- If the matched policy is
public: trueorrequireAuth: false, skip auth - Otherwise extract the
Authorization: Bearer <token>header - Validate the token against KavachOS, reject with 401 if invalid
- Check global rate limit (keyed by agent ID or IP), reject with 429 if exceeded
- Check policy-level rate limit, reject with 429 if exceeded
- Check
requiredPermissionsif any, reject with 403 if insufficient - Proxy the request to the upstream
- Record an audit entry if
audit: true - Return the upstream response with CORS headers merged in
Integration with MCP servers
The gateway works well in front of MCP tool servers. Agents that have been issued KavachOS tokens can call tools through the gateway, with permissions enforced per-route:Standalone vs embedded
| Standalone (CLI) | Embedded | |
|---|---|---|
| Setup | npx @kavachos/gateway | createGateway(config) |
| Process | Separate process | In-process |
| Framework | None required | Works with any framework |
| Hot reload | Restart required | Your app’s reload |
| Use case | Quick wrap, Docker sidecar | Full control, custom middleware |
Configuration reference
URL of the upstream service to proxy to
Base path prefix. Default: ”/“
KavachOS instance created with createKavach()
Array of path-based access policies
CORS configuration
Global rate limit applied to all requests
Record an audit entry for every request. Default: true
Remove the Authorization header before forwarding to upstream. Default: false
Rate limits are tracked in memory. If you run multiple gateway instances, each tracks limits independently. For distributed rate limiting, wrap the gateway with an external store or use a single gateway instance.