---
title: "Errors"
description: "Report failures from Nuxt MCP tools as isError results the model can recover from, and pass evlog, H3, Nitro and Nuxt error details on safely."
canonical_url: "https://mcp-toolkit.nuxt.dev/1.x/core/tools/errors"
---
# Errors

> Report failures from Nuxt MCP tools as isError results the model can recover from, and pass evlog, H3, Nitro and Nuxt error details on safely.

MCP has two kinds of failure. A **tool error** is a normal result with `isError: true`: the model reads the message and can retry, ask the user, or try another tool. A **protocol error** is a JSON-RPC error: the request itself was wrong, and the model usually never sees it as conversation content. Throwing from a handler produces a tool error unless you choose otherwise.

## What the client receives

Select what happened to see the exact payload the client receives, and what observers record:

<core-error-mapping>



</core-error-mapping>

Every case, with links to the error codes:

| What happens | What the client receives |
| --- | --- |
| Handler throws an `Error` | `isError: true` with `error.message` |
| Handler throws an H3 error (`createError` from `nuxt/server`, or H3's `HTTPError`) | `isError: true` with `[status] message` and the serialized `data` |
| Handler throws an evlog error (`createError` from `evlog`) | `isError: true` with `[status] message`, then its `why`, `fix` and `link` |
| Handler returns `{ isError: true, content }` | That result as is |
| Arguments fail `inputSchema` | `isError: true` listing each invalid field; the handler does not run |
| Return value fails `outputSchema` | JSON-RPC error `-32603`, [`mcp.OUTPUT_SCHEMA_MISMATCH`](https://mcp-toolkit.nuxt.dev/1.x/reference/errors#mcpoutput_schema_mismatch), listing each failing field |
| Token lacks a required scope | JSON-RPC error `-32003` (HTTP `403` on the modern revision), [`mcp.INSUFFICIENT_SCOPE`](https://mcp-toolkit.nuxt.dev/1.x/reference/errors#mcpinsufficient_scope). See [scopes](https://mcp-toolkit.nuxt.dev/1.x/authentication/scopes). |
| Tool name does not exist | JSON-RPC error `-32602` `Tool not found` |

## Throw a readable error

The message is what the model reads, so write it for the model: say what was wrong and what to do next.

```ts [server/mcp/tools/divide.ts]
import { z } from 'zod'
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpTool({
  description: 'Divide one number by another',
  inputSchema: z.object({ numerator: z.number(), denominator: z.number() }),
  outputSchema: z.object({ quotient: z.number() }),
  handler: ({ numerator, denominator }) => {
    if (denominator === 0) throw new Error('The denominator must not be zero. Ask the user for another value.')
    return { quotient: numerator / denominator }
  },
})
```

An error result isn't validated against `outputSchema`, so a failure never has to fit the success shape.

| Prefer | Over |
| --- | --- |
| `No order with ID "A-19". Call list-orders to find valid IDs.` | `Not found` |
| `The date range can't exceed 90 days. Split the request into smaller ranges.` | `Invalid range` |
| `The billing service is unavailable. Try again in a minute.` | The upstream stack trace |

## Status codes and data

Throw an H3 error when the status and structured details help the model decide what to do:

```ts [server/mcp/tools/get-order.ts]
import { z } from 'zod'
import { createError } from 'nuxt/server'
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'
import { findOrder } from '../../services/orders'

export default defineMcpTool({
  description: 'Get an order by ID',
  inputSchema: z.object({ id: z.string() }),
  handler: async ({ id }, event) => {
    const order = await findOrder(id, event.context.oauth?.sub)
    if (!order) throw createError({ status: 404, message: 'Order not found', data: { id } })
    return order
  },
})
```

The model receives:

```text
[404] Order not found
{
  "id": "A-19"
}
```

## Explain the failure with evlog

[evlog](https://evlog.dev)'s `createError` takes a `why`, a `fix` and a `link` alongside the message. The toolkit sends them to the model on their own lines, so it knows what to try next:

```ts [server/mcp/tools/charge.ts]
import { z } from 'zod'
import { createError } from 'evlog'
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'
import { charge } from '../../services/billing'

export default defineMcpTool({
  description: 'Charge the saved card',
  inputSchema: z.object({ amount: z.number() }),
  handler: async ({ amount }, event) => {
    const result = await charge(event.context.oauth?.sub, amount)
    if (result.declined) {
      throw createError({
        message: 'Payment failed',
        status: 402,
        why: 'The card was declined',
        fix: 'Ask the user for another card',
        link: 'https://example.com/errors/payment',
      })
    }
    return result.receipt
  },
})
```

The model receives:

```text
[402] Payment failed
Why: The card was declined
Fix: Ask the user for another card
More info: https://example.com/errors/payment
```

An error from an evlog [error catalog](https://evlog.dev/learn/catalogs) also carries its code, which the model sees on the first line: `[402] billing.PAYMENT_DECLINED: Payment failed`.

evlog is not a dependency: the toolkit recognises its errors by their brand.

## What never leaks

Only errors your app throws through H3 or evlog expose a status and details. Every other error reports only its `message`, including a failed `$fetch` or `ofetch` call whose error holds the upstream response body. That way, an internal API's response never reaches the client by accident.

The message itself is still sent, so check what your dependencies put in it. Catch errors from libraries that include queries, file paths, or credentials in their messages, log the details on the server, and throw a safe message instead:

```ts
try {
  return await db.query(sql, params)
}
catch (error) {
  console.error('report query failed', error)
  throw new Error('The report could not be generated. Try a shorter date range.')
}
```

## Return an error without throwing

Return a result with `isError: true` when you've already built a message, such as a partial failure from a batch:

```ts
return {
  isError: true,
  content: [{ type: 'text', text: `Imported 18 of 20 rows. Rows 4 and 11 have no email.` }],
}
```

With an `outputSchema`, wrap it in [`toolResult()`](https://mcp-toolkit.nuxt.dev/1.x/core/tools/structured-output#add-your-own-content-blocks). [Observers](https://mcp-toolkit.nuxt.dev/1.x/observability/hooks-observers) report a returned error as `tool_error` and a thrown one as `error`, so dashboards can tell expected refusals from crashes.

## Protocol-level errors

A tool never needs to throw a protocol error. The MCP specification reserves them for requests the server can't serve at all, such as an unknown tool or a malformed call, and the toolkit raises those itself. Anything your handler throws is a tool execution error, which the model reads and can recover from. The errors the toolkit raises are listed, with their `why` and `fix`, in the [errors reference](https://mcp-toolkit.nuxt.dev/1.x/reference/errors).

## Cancelled calls

When the client cancels or disconnects, `event.context.mcp.signal` aborts. Let the resulting `AbortError` propagate instead of catching it and returning a result nobody will read. See [progress and cancellation](https://mcp-toolkit.nuxt.dev/1.x/core/tools/progress-cancellation).


## Sitemap

See the full [sitemap](https://mcp-toolkit.nuxt.dev/sitemap.md) for all pages.
