# Errors

Canonical URL: https://developers.iagenify.com/sdk/mcp/errors/
Language: en

Every MCP refusal, what it means, and which end to look at — the address, the token, the server or the protocol.

Status: 11 codes · IaGenifyError · the server's message is carried

## The address {#address}

| Code | Status | Means |
| --- | --- | --- |
| url_required | 400 | No address was given. |
| url_not_https | 400 | Plain http. The token would travel unencrypted. |
| url_blocked | 400 | It does not resolve to a public address. |
| mcp_redirect | 502 | The server answered with a redirect. They are never followed — the destination was never checked. |

## The token {#token}

| Code | Status | Means |
| --- | --- | --- |
| mcp_token_malformed | 400 | It contains a space. Paste the token alone. |
| mcp_token_required | 401 | The server wants one and none was given. |
| mcp_unauthorized | 401 | It was refused. Rotate it with `update()`. |

## The server {#server}

| Code | Status | Means |
| --- | --- | --- |
| mcp_unreachable | 502 | No answer at all. |
| mcp_timeout | 504 | Past the ceiling — 30 s listing, 60 s calling. |
| mcp_http_error | 502 | A refusal at the HTTP level. |
| mcp_bad_response | 502 | The answer was not a readable protocol message. |
| mcp_error | 502 | A protocol error. **The server's own message is carried.** |
| mcp_protocol_unsupported | 502 | No revision in common. |

> **mcp_error carries the server's words**
>
> It is the one to read rather than interpret: whoever operates the server wrote that message, and it usually names the real cause — a missing capability, an unsupported version, a header that does not match the body.

## Handling them {#handling}

```javascript
import { IaGenifyError } from "iagenify";

try {
  await api.mcp.call("example", "search_docs", { query });
} catch (err) {
  if (!(err instanceof IaGenifyError)) throw err;

  switch (err.code) {
    case "mcp_unauthorized": return rotateToken();
    case "mcp_timeout":
    case "mcp_unreachable":  return markServerDown();
    default:                 throw err;
  }
}
```

## The last one is remembered {#lasterror}

A connection keeps `lastError`, so a server whose token expired or whose address moved shows it in [list()](/sdk/ref/mcp/list) rather than only failing inside a run.

- [Errors](/sdk/concepts/errors): The error classes.
- [Address check](/sdk/mcp/address-check): Where the first three come from.

```python
from iagenify import IaGenifyError

try:
    api.mcp.call("example", "search_docs", {"query": query})
except IaGenifyError as error:
    if error.code == "mcp_unauthorized":
        rotate_token()
    elif error.code in ("mcp_timeout", "mcp_unreachable", "mcp_http_error"):
        mark_server_down()
    else:
        raise
```
