Skip to content

Error Codes

AHP uses JSON-RPC 2.0 error codes. In addition to the standard JSON-RPC codes, AHP defines application-specific error codes in the -32000 to -32099 range.

JSON Schema: errors.schema.json

Standard JSON-RPC Codes

These codes are defined by the JSON-RPC 2.0 specification:

CodeNameDescription
-32700Parse errorInvalid JSON
-32600Invalid requestNot a valid JSON-RPC request
-32601Method not foundUnknown method name
-32602Invalid paramsInvalid method parameters
-32603Internal errorUnspecified server error

AHP Application Codes

CodeNameDescription
-32001SessionNotFoundThe referenced session URI does not exist
-32002ProviderNotFoundThe requested agent provider is not registered
-32003SessionAlreadyExistsA session with the given URI already exists
-32004TurnInProgressThe operation requires no active turn, but one is in progress
-32005UnsupportedProtocolVersionThe server cannot speak any of the protocol versions offered by the client in InitializeParams.protocolVersions. The data field of the JSON-RPC error MAY be an UnsupportedProtocolVersionErrorData advertising the protocol versions the server is willing to speak.
-32006ContentNotFoundThe requested content URI does not exist
-32007AuthRequiredA command failed because the client has not authenticated for a required protected resource. The data field of the JSON-RPC error MUST be an AuthRequiredErrorData describing the resources that require authentication.
-32008NotFoundThe requested file, folder, or URI does not exist
-32009PermissionDeniedThe client is not permitted to access the requested resource. Servers SHOULD return this when a client attempts to read or browse a path outside the allowed set (e.g. outside the session's working directory or workspace roots). The data field of the JSON-RPC error MAY be a PermissionDeniedErrorData advertising a resourceRequest that, if granted, would unlock the operation.
-32010AlreadyExistsThe target resource already exists and the operation does not allow overwriting (e.g. resourceWrite with createOnly: true).
-32011ConflictAn optimistic-concurrency precondition failed. Returned when a request carries a precondition token that no longer matches the receiver's current state — for example, resourceWrite with an ifMatch etag that has been superseded by a concurrent write. Callers SHOULD re-read the resource (e.g. via resourceResolve) and decide whether to retry the operation with the fresh token or surface the conflict to the user.

Error Response Format

All error responses follow the JSON-RPC 2.0 error format:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32002,
    "message": "No agent registered for provider 'unknown'",
    "data": {}
  }
}

The data field is OPTIONAL and MAY contain additional structured information about the error. Its shape is not defined by the protocol.

Typed Error Data

A handful of error codes carry a typed data payload. The mapping is captured by AhpErrorDetailsMap; the typed AhpError<C> union narrows data based on the code.

AuthRequiredErrorData

Details carried in the data field of an AuthRequired (-32007) error.

Wraps the protected resource list in { resources: [...] } rather than returning a bare array, so additional fields can be added in future versions without breaking the wire shape.

FieldTypeDescription
resourcesProtectedResourceMetadata[]Protected resources that require authentication.

PermissionDeniedErrorData

Details carried in the data field of a PermissionDenied (-32009) error.

The receiver MAY advertise a resourceRequest payload describing the access that, if granted, would unlock the operation. The caller MAY then issue resourceRequest with that payload to negotiate access.

FieldTypeRequiredDescription
requestResourceRequestParamsNoThe resource access that, if granted via resourceRequest, would unlock the operation. Omitted when no specific access grant would resolve the denial (for example, when the resource is fundamentally inaccessible).

UnsupportedProtocolVersionErrorData

Details carried in the data field of an UnsupportedProtocolVersion (-32005) error.

FieldTypeDescription
supportedVersionsstring[]Protocol versions the server is willing to speak.

Each entry is either a SemVer MAJOR.MINOR.PATCH string (e.g. "0.1.0") or a SemVer range constraint (e.g. "&gt;=0.1.0 &lt;0.3.0" or "^0.2.0").

AhpErrorDetailsMap

Maps each AHP error code that carries structured data to the type of that data.

Error codes not present in this map either have no data payload or carry an unspecified payload that callers SHOULD treat as unknown.

FieldTypeDescription
[AhpErrorCodes.AuthRequired]AuthRequiredErrorData
[AhpErrorCodes.PermissionDenied]PermissionDeniedErrorData
[AhpErrorCodes.UnsupportedProtocolVersion]UnsupportedProtocolVersionErrorData

AhpErrorCode

Union type of all AHP application error codes.

(typeof AhpErrorCodes)[keyof typeof AhpErrorCodes]

JsonRpcErrorCode

Union type of all JSON-RPC error codes.

(typeof JsonRpcErrorCodes)[keyof typeof JsonRpcErrorCodes]

AhpErrorCodeWithData

AHP error codes that carry a structured data payload.

keyof AhpErrorDetailsMap

AhpError

A typed JSON-RPC error object whose data is narrowed by code.

Distributes over the AhpErrorCode union so narrowing on code reveals the precise data type. For codes listed in {@link AhpErrorDetailsMap} data is required; for all other codes data is an optional unknown.

ts
function handle(err: AhpError) {
  if (err.code === AhpErrorCodes.PermissionDenied) {
    err.data.request; // typed as ResourceRequestParams | undefined
  }
}

C extends AhpErrorCode ? C extends keyof AhpErrorDetailsMap ? { /** The error code. / readonly code: C; /* Human-readable error message. / readonly message: string; /* Structured detail payload mandated by [AhpErrorDetailsMap](#ahperrordetailsmap). / readonly data: AhpErrorDetailsMap[C]; } : { /* The error code. / readonly code: C; /* Human-readable error message. / readonly message: string; /* Optional, unspecified detail payload. */ readonly data?: unknown; } : never

Version Introduction

All error codes listed above were introduced in protocol version 1.

Released under the MIT License.