> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Result Or Error

> Explains differences between tool runtime errors and MCP JSON-RPC protocol errors, how they appear in UI and logs, and recommended handling for models versus orchestration

Welcome back. In this demonstration we compare two distinct error categories you’ll encounter when calling tools via MCP/JSON-RPC: tool (runtime) errors and protocol (MCP/JSON-RPC) errors. We’ll show representative request/response payloads, how each appears in the UI and server logs, and the correct place to handle them.

This guide is useful when designing error handling for tool orchestration or when training models to react to tool outcomes.

## Setup

Start with a clean environment. In the tools list there is a tool reachable at:

```bash theme={null}
127.0.0.1:6274/?MCP_INSPECTOR_API_TOKEN=96ee8ad5ce54a086d330442a9626457c4572a2bb3734a304df3ba41997583c0f
```

The tool is named `flaky_lookup` and exposes two execution modes in the UI: “Anticipated” and “Protocol”. We’ll run both to demonstrate the differences.

## Anticipated (tool-level) error

Select **Anticipated** and execute the tool. The UI returns a tool error:

```text theme={null}
Tool Error

Error executing tool flaky_lookup: The carrier's tracking API returned 503. Try again in a minute.
```

Inspecting the Messages / Requests view shows the request and the tool’s response. The response contains an execution payload with `content` that describes the failure. A simplified excerpt looks like:

```json theme={null}
{
  "id": "some-id",
  "request_metadata": { /* ... */ },
  "content": {
    "type": "error",
    "text": "The carrier's tracking API returned 503. Try again in a minute.",
    "is_error": true,
    "result_type": "complete"
  }
}
```

Key points:

* `is_error: true` indicates the tool execution failed at runtime.
* `result_type: "complete"` indicates the tool finished its execution path (albeit unsuccessfully), so the request is marked as complete in the UI.
* The model receives this `content` payload and can make decisions (retry, fallback, or ask for human input).

Server logs typically surface the same error on stderr (tool runtime logs are commonly written to stderr; MCP protocol traffic often uses stdout). Example server log excerpt:

```text theme={null}
15:07:10 Tool `flaky_lookup` failed: "Error executing tool flaky_lookup: The carrier's tracking API returned 503. Try again in a minute."
15:06:41 shipment-tracker ready on stdio
```

Why this matters

* Tool/runtime errors are actionable by the model because the error message is present in the tool’s `content`. The model can decide how to proceed (e.g., schedule a retry, switch to a fallback tool, or ask for clarification).
* Operators can monitor stderr for these runtime failures and correlate them with tool responses in the UI.

## Protocol (MCP/JSON-RPC) error

Now clear the view and select **Protocol**, then execute the tool. In this scenario the MCP server rejects the call before the tool process runs. The UI displays a different failure:

```text theme={null}
Tool Call Failed

Tool Error

shipment-tracker is in maintenance and cannot serve lookups
```

Inspecting the protocol layer shows a JSON-RPC style error response rather than a `content` error blob. A simplified JSON-RPC rejection looks like:

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "some-id",
  "error": {
    "code": 12345,
    "message": "shipment-tracker is in maintenance and cannot serve lookups"
  }
}
```

Notice the differences:

* There is no `content` payload with `is_error` for the model to read.
* This is a protocol-level rejection: the MCP/JSON-RPC layer refused or could not route the request, so the tool never executed.
* Protocol errors typically indicate operational conditions (maintenance, invalid request, authentication/authorization failures) that must be handled by the orchestration layer rather than by the model.

Protocol (JSON-RPC/MCP) errors are not intended to be surfaced to the model as tool output. They are rejections at the protocol layer and generally cannot be acted on by the model in the same way as tool runtime errors.

Protocol-level rejections usually do not produce the same stderr runtime exception that tool-level failures do, because the tool process isn’t invoked. Instead, the MCP server returns a JSON-RPC `error` object directly to the caller.

## Key differences and takeaways

Tool errors are runtime failures produced by a tool and are intentionally surfaced to the model (via `content` with `is_error: true`) so the model can act. Protocol errors are MCP/JSON-RPC-level rejections returned before tool execution; they are represented as an `error` object in the JSON-RPC response and are not actionable by the model in the same way.

Summary table: Tool error vs Protocol error

| Aspect | Tool error (runtime) | Protocol error (MCP/JSON-RPC) |
| - | - | - |
| Origin | Tool or upstream runtime (e.g., external API returned 503) | MCP / JSON-RPC layer (e.g., maintenance mode, invalid request) |
| Response shape | `content` payload with `is_error: true` and `result_type` | JSON-RPC `error` object with `code` and `message` |
| Visibility to model | Visible — model can read and act on the error | Not visible as a tool result — model cannot typically act on it |
| Server logs | Often logged to stderr by the tool/runtime | Usually returned by the protocol layer; tool runtime may not run, so no tool stderr |
| Recommended handler | Let model handle (retry strategy, fallback tools) | Orchestration-level handling (retry, alert, surface user-friendly message) |

## Recommended handling patterns

* Handle tool/runtime errors at the model level:
  * Provide the model with the `content` error payload so it can choose retries, fallbacks, or clarifying questions.
  * Implement retry/backoff and fallback tool strategies when upstream services are flaky.
* Handle protocol errors at the orchestration layer:
  * Detect JSON-RPC `error` responses and perform orchestration-level actions (retry the request, alert operators, or surface a clear message to end users).
  * Do not rely on the model to interpret protocol errors as recoverable tool failures.
* Logging and monitoring:
  * Correlate stderr tool runtime logs with the `content` responses in the UI to diagnose runtime failures.
  * Monitor MCP/JSON-RPC error codes to detect systemic operational issues (maintenance windows, auth failures).

References

* JSON-RPC specification: [https://www.jsonrpc.org/specification](https://www.jsonrpc.org/specification)
* Best practices for error handling in orchestration systems: consider integrating structured logs and alerts for protocol-level failures

By designing your error handling with these distinctions in mind, you’ll ensure that actionable failures are exposed to the model while orchestration-level problems are handled reliably outside the model’s reasoning context.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/model-context-protocol-associate-mcpa-certification/module/31dedbc5-6173-4700-b50e-7a581095c897/lesson/357ee376-53f6-4c0f-9a4e-54dcbf3eecc6)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.