Skip to main content
kavachNextjs(kavach, options?) returns named route handlers { GET, POST, PATCH, DELETE, OPTIONS } for the Next.js App Router. Mount them in a catch-all route file so all KavachOS paths are handled.

Install

Setup

1

Create the kavach instance

Create this in a shared module so it is initialized once at server startup:
2

Create the catch-all route

Create app/api/kavach/[...kavach]/route.ts. The [...kavach] segment catches every sub-path under /api/kavach/.
The basePath option defaults to /api/kavach. If you mount at a different path such as /api/auth/kavach, pass basePath: '/api/auth/kavach' so the dispatcher can strip the prefix correctly.

Options

MCP endpoints

When mcp is passed, the following endpoints are available:

Endpoint reference

Full example

Do not define createKavach inside the route file if you need the instance elsewhere in your app. Export it from lib/kavach.ts and import it where needed to avoid creating multiple instances.
Last modified on April 29, 2026