# Errors

Tool refusals use one stable JSON shape:

```json
{
  "code": "conflict",
  "message": "idempotency key was already used with a different body",
  "details": {"tool": "start_case"},
  "retryable": false
}
```

`details` is optional. `retryable` says whether repeating the exact same request
can succeed without a human or state change.

## HTTP and JSON-RPC mapping

REST tool calls return the refusal as the HTTP response body, using the status
in the table below. JSON-RPC returns an error object whose `data` field carries
the same refusal shape. Its transport-level mapping is:

- `-32600`: invalid request envelope.
- `-32601`: unknown JSON-RPC method.
- `-32602`: invalid or missing JSON-RPC params.
- `-32001`: authentication failed; inspect `error.data.code` for the refusal.
- `-32000`: the named tool refused or failed; inspect `error.data.code` for the
  stable refusal code and retryability.

The status mapping below is generated from Docket's live MCP error registry.

| Code | HTTP status |
| --- | --- |
| `conflict` | `409` |
| `forbidden` | `403` |
| `illegal_transition` | `409` |
| `internal` | `500` |
| `invalid_request` | `400` |
| `needs_approval` | `409` |
| `not_available` | `501` |
| `not_found` | `404` |
| `stale_token` | `409` |
| `timer_not_due` | `409` |
| `unauthorized` | `401` |

## What to do

- `401`: the token is missing, malformed, unknown, expired or revoked. Stop and
  ask the administrator for a replacement. Never retry the same credential.
- `403`: the token is valid but the tenant header, role or scope does not permit
  the request. Stop and report the request; do not widen scope yourself.
- `404`: the case, process or draft does not exist in the authenticated tenant.
  Check the identifier from the current response. A cross-tenant identifier is
  intentionally indistinguishable from a missing one.
- `409`: the request conflicts with current state. `illegal_transition`,
  `needs_approval`, `stale_token` and `timer_not_due` mean do not force the
  action. Re-read the allowed next step, wait for a human where required, and
  continue only from the returned state.
- `501`: the capability is not available in this deployment. Stop and report it
  instead of retrying; an operator must enable the required decision provider.
- `500`: an unexpected server failure. Stop state-changing work, report the
  request id, and retry only reads unless an operator confirms it is safe.

Always include the request id or JSON-RPC response id in an incident report,
never the bearer token.
