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
Whenmcp is passed, the following endpoints are available: