kavachOS

Error codes

All error codes and their meanings.

KavachOS returns structured errors in the following shape:

interface KavachError {
  code: string;    // machine-readable error code
  message: string; // human-readable description
  details?: Record<string, unknown>; // additional context
}

All SDK functions that can fail return a Result<T> discriminated union rather than throwing:

const result = await kavach.authorize(agentId, { action: 'write', resource: 'mcp:github:*' });

if (!result.allowed) {
  console.log(result.reason); // e.g. "RATE_LIMITED"
}

For REST API calls, errors are returned as JSON with the corresponding HTTP status code:

{
  "code": "AGENT_NOT_FOUND",
  "message": "Agent agt_01abc does not exist or has been revoked."
}

Error code reference

Agent errors

CodeHTTP statusDescription
AGENT_NOT_FOUND404No agent with the given ID exists.
AGENT_LIMIT_EXCEEDED422The user has reached their maxPerUser agent limit.
AGENT_REVOKED403The agent has been explicitly revoked and cannot be used.
AGENT_EXPIRED403The agent's expiresAt is in the past.

Permission errors

CodeHTTP statusDescription
PERMISSION_DENIED403The agent does not have a permission matching the requested resource and action.
RATE_LIMITED429The agent has exceeded its maxCallsPerHour constraint for this resource.
OUTSIDE_TIME_WINDOW403The current time falls outside the permission's timeWindow constraint.
IP_NOT_ALLOWED403The request IP is not in the permission's ipAllowlist.
REQUIRES_APPROVAL202The action requires human approval (requireApproval: true). An approval request has been created.

Token errors

CodeHTTP statusDescription
INVALID_TOKEN401The token cannot be verified (bad signature, malformed, or unknown).
TOKEN_EXPIRED401The token's exp claim is in the past.

Delegation errors

CodeHTTP statusDescription
DELEGATION_DEPTH_EXCEEDED422The delegation would exceed the maxDepth limit.
INSUFFICIENT_PERMISSIONS403The delegating agent is attempting to grant permissions it does not hold.
DELEGATION_NOT_FOUND404No delegation with the given ID exists.
DELEGATION_EXPIRED403The delegation chain's expiresAt is in the past.

MCP / OAuth errors

CodeHTTP statusDescription
MCP_CLIENT_NOT_FOUND401The OAuth client_id is not registered.
MCP_INVALID_GRANT400The authorization code or refresh token is invalid, expired, or already consumed.
MCP_INVALID_REDIRECT_URI400The redirect_uri does not match the registered client.
MCP_PKCE_FAILED400The code_verifier does not match the stored code_challenge.
MCP_SCOPE_INSUFFICIENT403The token does not carry the required scopes for this endpoint.
MCP_CLIENT_DISABLED403The OAuth client has been disabled by an administrator.

General errors

CodeHTTP statusDescription
BAD_REQUEST400The request body or parameters failed validation.
UNAUTHORIZED401No valid credential was provided.
FORBIDDEN403The credential is valid but does not have access to this resource.
NOT_FOUND404The requested resource does not exist.
INTERNAL_ERROR500An unexpected error occurred. Check server logs for details.

On this page