# Errors and approvals

> The errors an MCP or public API client can receive, how the approval flow works end to end, and how to retry safely.

Source: https://docs.deerapp.co/en/developers/errors_and_approvals/

## Three kinds of error

A client can be refused at three levels. Check them in this order.

| Level | When | Shape |
| --- | --- | --- |
| HTTP | The request never reached a tool: missing token, wrong origin, too many requests. | A non-200 status with `{ "ok": false, "code": "..." }`. |
| JSON-RPC | The MCP message itself is wrong: unknown method, unknown tool, bad arguments object. | A JSON-RPC `error` with a numeric `code` and a `message`. |
| Tool | The tool ran its checks and refused, or the action failed. | A normal `result` with `isError: true` and a JSON object holding a `code`. |

Codes are stable strings meant for programs. Deer never returns provider responses or internal details in an error.

## HTTP errors

```json
{"ok":false,"code":"MCP_CREDENTIAL_REQUIRED"}
```

| Status | Code | Meaning and fix |
| --- | --- | --- |
| `400` | `INVALID_INPUT` | The body is not valid JSON, or a public action input failed validation. |
| `400` | `MCP_VERSION_UNSUPPORTED` | The `MCP-Protocol-Version` header names a version Deer does not support. |
| `400` | JSON-RPC `-32600` | The body is not a single JSON-RPC 2.0 message. Batches are refused here. |
| `401` | `MCP_CREDENTIAL_REQUIRED` | The token is missing, malformed, revoked or for another workspace, its owner no longer has MCP access, or MCP is unavailable in the workspace. The response includes `WWW-Authenticate: Bearer`. |
| `403` | `ORIGIN_REJECTED` | An MCP request came from a web page on another site. |
| `403` | `ORIGIN_NOT_ALLOWED` | A public action `POST` came from a site other than Deer's. |
| `405` | none | `GET` or `DELETE` on the MCP endpoint. Use `POST`. |
| `413` | `MCP_REQUEST_TOO_LARGE` | The MCP body exceeds 15,029,592 bytes. The JSON-RPC error is `-32600` and `data.limit` gives the limit. |
| `413` | `REQUEST_FAILED` | The public action body exceeds 2 KB. |
| `429` | `REQUEST_FAILED` | Too many requests. Wait before retrying. |
| `500` | `REQUEST_FAILED` | An unexpected server error. Retry later. |

A `401` does not say which of the reasons applies. Check that the connection is **Active** in **Settings**, **MCP**, that its owner is still a workspace member with MCP access, and that you copied the whole token.

## JSON-RPC errors

```json
{"jsonrpc":"2.0","id":4,"error":{"code":-32602,"message":"Unknown tool"}}
```

| Code | Message | Meaning |
| --- | --- | --- |
| `-32601` | `Method not found` | Deer supports `initialize`, `ping`, `tools/list` and `tools/call`. |
| `-32602` | `Invalid initialization` | `initialize` is missing `protocolVersion`, `capabilities` or `clientInfo`. |
| `-32602` | `Invalid tool request` | `tools/call` params need a `name` and, optionally, an `arguments` object. |
| `-32602` | `Unknown tool` | The name is not one of the MCP tools. |
| `-32602` | `Invalid approval ID` | `_moeen_approval` is not a UUID, or was sent to a tool that never needs approval. |

## Tool errors

When a tool refuses, the text content holds an object with a `code`:

```json
{"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"{\"code\":\"RECORD_UNAVAILABLE\"}"}],"isError":true}}
```

| Code | Meaning and fix |
| --- | --- |
| `INVALID_INPUT` | The arguments do not match the tool's schema. Unknown fields are refused. Compare with `tools/list`. |
| `MCP_PERMISSION_REQUIRED` | The connection's scope or its owner's current permission does not allow this tool. |
| `MCP_APPROVAL_REQUIRED` | With an `approvalId`: a person must approve first. Without one, on a retry: the approval id is unknown, rejected, expired, already used or for different arguments. |
| `MCP_TOO_MANY_APPROVALS` | The connection already has 20 open approval requests. Wait for decisions or expiry. |
| `RECORD_UNAVAILABLE` | The task does not exist, or the id is a display key instead of the task `id`. |
| `PROJECT_UNAVAILABLE` | The team does not exist or you cannot open it. |
| `PROJECT_ARCHIVED` | The team is archived, so tasks cannot be added to it. |
| `ASSIGNEE_UNAVAILABLE` | A person id is not a member of the workspace. |
| `TASK_DEPENDENCY_CYCLE` | The blockers would make a task block itself. |
| `SUBTASK_UNAVAILABLE` | There is no subtask at that `index`. |
| `CHANNEL_UNAVAILABLE` | A comment channel is not linked to the task's team or is not open to you. |
| `FILE_TOO_LARGE` | Comment attachments exceed the count or size limit. |
| `MODULE_DISABLED` | Tasks is turned off for this workspace. |
| `MCP_TOOL_FAILED` | An unexpected error while running the tool. |

If the owner's role lacks the tool's scope entirely, the object also carries a bilingual message: `{"ok":false,"message":{...},"code":"MCP_PERMISSION_REQUIRED"}`.

Once the input passes validation, every refusal is written to the audit log with the status `denied` or `failed`, and the client as the actor.

If a tool returns `IDEMPOTENCY_CONFLICT`, the same retry key was used with different arguments. Use a new key for a new write. See [Retry a write](https://docs.deerapp.co/en/connect/mcp_tools/#retry-writes).

## Approval required

Destructive and External actions requested by a non-human actor stop for a person. Over MCP this applies to `tasks.delete`.

#### The client calls the tool
The client sends `tasks.delete` with a task id. Deer checks the connection, the owner's permission and that the task is visible to the owner.

#### Deer stores an approval request
Nothing is deleted. The result has `isError: true`, the code `MCP_APPROVAL_REQUIRED` and an `approvalId`. The audit log records `pending-approval`.

#### The client tells the user
Show the user that the request is waiting in Deer. Do not loop on the call: repeating it returns the same `approvalId`.

#### A person decides
The connection owner opens **Settings**, then **MCP**, and selects **Approve deletion** or **Reject** under **Approval requests**. They need permission to change tasks. If the task changed since the request, Deer refuses to approve it.

#### The client retries once
Within 15 minutes of the first call, the client repeats the call with the same arguments and `_moeen_approval`. Deer checks the approval, the arguments and the task version, runs the action and marks the approval used.

The full request and response pair is in [MCP tools](https://docs.deerapp.co/en/connect/mcp_tools/#approval-flow). AI uses the same rule in conversations, where the person who asked approves the proposed action. See [Approvals](https://docs.deerapp.co/en/ai/approvals/).

## Retries and idempotency

- **Rate limits.** On `429`, back off and retry later. Spread requests rather than sending bursts.
- **Server errors.** On `500` or `MCP_TOOL_FAILED`, retry later with increasing delays, after checking that a write did not already succeed.
- **Validation and permission.** Do not retry `INVALID_INPUT`, `MCP_PERMISSION_REQUIRED` or a `401` unchanged. Fix the input, the scope or the token first.
- **Retrying an MCP write.** If the tool accepts `_moeen_idempotency_key`, repeat the call with the same key and arguments within 24 hours. If the first call had no key, check whether the change happened before sending it again.
- **Some writes are safe to repeat.** `tasks.set_status`, `tasks.assign`, `tasks.set_subtask` and `tasks.update` set a value, so repeating the same call leaves the same result.
- **Deletion runs once.** An approval id can be used once, so a repeated retry cannot delete twice.

The Deer interface sends an idempotency key with every write. A repeat with the same key and input returns the first result, and the same key with different input is refused with `IDEMPOTENCY_CONFLICT`. See [Idempotency](https://docs.deerapp.co/en/developers/hybrid_model/#idempotency).

Work that leaves Deer, such as sending mail or running an app tool, is never retried automatically after an uncertain outcome. Deer marks it for a person to check in the app concerned.

- [MCP tools](https://docs.deerapp.co/en/connect/mcp_tools/) Tool inputs and the approval example.
- [API](https://docs.deerapp.co/en/developers/api/) Endpoints and limits.
- [Audit log](https://docs.deerapp.co/en/admin/audit_log/) Review refused and approved requests.
