kavachOS
Framework adapters

SvelteKit

KavachOS adapter for SvelteKit.

kavachSvelteKit(kavach, options?) returns named route handlers { GET, POST, PATCH, DELETE, OPTIONS }. Mount them in a catch-all server route file so all KavachOS paths are handled.

Install

pnpm add kavachos @kavachos/sveltekit

Setup

Create the kavach instance

// src/lib/kavach.ts
import { createKavach, createMcpModule } from 'kavachos';

export const kavach = createKavach({
  database: { provider: 'postgres', url: process.env.DATABASE_URL! },
  baseUrl: process.env.AUTH_BASE_URL!,
  mcp: {
    issuer: process.env.AUTH_BASE_URL!,
    audience: process.env.MCP_BASE_URL!,
  },
});

export const mcp = createMcpModule(kavach);

Create the catch-all route

Create src/routes/api/kavach/[...path]/+server.ts. The [...path] segment catches every sub-path under /api/kavach/.

// src/routes/api/kavach/[...path]/+server.ts
import { kavachSvelteKit } from '@kavachos/sveltekit';
import { kavach, mcp } from '$lib/kavach';

const handlers = kavachSvelteKit(kavach, { mcp });

export const GET = handlers.GET;
export const POST = handlers.POST;
export const PATCH = handlers.PATCH;
export const DELETE = handlers.DELETE;
export const OPTIONS = handlers.OPTIONS;

SvelteKit passes a standard Web API Request to route handlers, so the adapter delegates directly to the KavachOS dispatcher without any conversion.

Options

interface KavachSvelteKitOptions {
  mcp?: McpAuthModule;     // enables MCP OAuth 2.1 endpoints
  basePath?: string;       // defaults to '/api/kavach'
}

MCP endpoints

When mcp is passed, the MCP OAuth 2.1 endpoints are available at:

GET  /api/kavach/.well-known/oauth-authorization-server
GET  /api/kavach/.well-known/oauth-protected-resource
POST /api/kavach/mcp/register
GET  /api/kavach/mcp/authorize
POST /api/kavach/mcp/token

Endpoint reference

MethodPathDescription
POST/agentsCreate an agent
GET/agentsList agents
GET/agents/:idGet an agent
PATCH/agents/:idUpdate an agent
DELETE/agents/:idRevoke an agent
POST/agents/:id/rotateRotate token
POST/authorizeAuthorize by agent ID
POST/authorize/tokenAuthorize by bearer token
POST/delegationsCreate delegation
GET/delegations/:agentIdList delegation chains
DELETE/delegations/:idRevoke delegation
GET/auditQuery audit logs
GET/audit/exportExport audit logs

Full example

// src/routes/api/kavach/[...path]/+server.ts
import { createKavach, createMcpModule } from 'kavachos';
import { kavachSvelteKit } from '@kavachos/sveltekit';

const kavach = createKavach({
  database: { provider: 'postgres', url: process.env.DATABASE_URL! },
  baseUrl: process.env.AUTH_BASE_URL!,
  mcp: {
    issuer: process.env.AUTH_BASE_URL!,
    audience: process.env.MCP_BASE_URL!,
  },
});

const mcp = createMcpModule(kavach);

const handlers = kavachSvelteKit(kavach, { mcp });

export const GET = handlers.GET;
export const POST = handlers.POST;
export const PATCH = handlers.PATCH;
export const DELETE = handlers.DELETE;
export const OPTIONS = handlers.OPTIONS;

On this page