Skip to main content

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
The upstream service sees only clean, authenticated traffic. No SDK changes required on the upstream side.

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
If you own the upstream service and can add the KavachOS SDK directly, that’s more flexible. The gateway is best when you can’t or don’t want to touch upstream code.

Quick start

The fastest path is the one-liner:
This starts a gateway on port 3000 that proxies all traffic to 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

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 whose path pattern and method (if set) match the incoming request wins.

Glob patterns

Patterns use standard glob syntax via micromatch:

Auth flow per request

  1. Check if the path is /_kavach/health, serve locally, no upstream
  2. Handle CORS preflight if cors is configured
  3. Match the request against policies (path + method)
  4. If the matched policy is public: true or requireAuth: false, skip auth
  5. Otherwise extract the Authorization: Bearer <token> header
  6. Validate the token against KavachOS, reject with 401 if invalid
  7. Check global rate limit (keyed by agent ID or IP), reject with 429 if exceeded
  8. Check policy-level rate limit, reject with 429 if exceeded
  9. Check requiredPermissions if any, reject with 403 if insufficient
  10. Proxy the request to the upstream
  11. Record an audit entry if audit: true
  12. 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

In Docker, the standalone mode works as a sidecar:

Configuration reference

string
URL of the upstream service to proxy to
string
default:"\"/\""
Base path prefix. Default: ”/“
Kavach
KavachOS instance created with createKavach()
GatewayPolicy[]
Array of path-based access policies
CorsConfig
CORS configuration
{ windowMs: number; max: number }
Global rate limit applied to all requests
boolean
default:"true"
Record an audit entry for every request. Default: true
boolean
default:"false"
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.
Last modified on April 18, 2026