My MCP server used to simply stop working. No crash dump. No stack trace in the logs. Clients connected without complaint, then after a few hours the whole thing went mute. Requests disappeared and the AI agent on the other end received nothing but blank air.

This is a frustratingly common story in the Model Context Protocol (MCP) ecosystem. The protocol defines how AI agents discover and call external tools, but the specification assumes you will handle errors yourself. Most tutorials and starter implementations skip past that part. They focus on the happy path: annotate a function, expose it through the server, and return a clean result. They rarely show you what happens when a network blip hits your external API, or when the model hallucinates a parameter name and sends garbage input. The result is a brittle server that looks healthy but has actually been dead for hours.

Why Blank Responses Are Worse Than Crashes

When an unhandled exception slips through in an MCP tool handler, the transport layer often swallows it. The server process stays alive, the socket remains open, but the client gets an empty response. This is more dangerous than a loud crash because your monitoring might not notice. The process is still running. The port is still listening. Yet every tool call returns nothing.

The AI model does not interpret silence as failure. It interprets silence as a successful call that produced no data. That blank response trains the model to improvise. It starts hallucinating facts to fill the gap, or it enters a loop of retrying the same broken call. Small issues like a transient network timeout or an invalid tool argument should never be allowed to cause this kind of behavior.

The Wrapper Pattern: Three Lines of Defense

I fixed this by wrapping every tool handler in a thin error-recovery layer. The wrapper does not try to predict every possible failure. It categorizes them and responds accordingly.

ConnectionError and TimeoutError
These arise when your server talks to an external API and the network wobbles. The instinctive fix is to restart the entire MCP server process. Do not do that. Rebooting drops active client connections, clears any in-memory state, and forces a full re-initialization. Instead, catch the connection failure and reconnect only the transport layer or HTTP client your tool uses. The server stays warm and ready for the next request immediately.

ValueError
This is what you see when the AI client sends malformed arguments. Maybe the model invented a parameter, passed a string where an integer was required, or forgot a required field. If you let this bubble up unhandled, the client gets either a crash or a blank reply. Catch it inside the wrapper, then construct a clear, specific message that tells the model exactly what went wrong. Explain which parameter failed and what was expected. Most modern AI models will read that message and self-correct on the very next turn. A vague error wastes a reasoning cycle. A precise error fixes the problem immediately.

General Exceptions
Keep a safety net. If an error falls outside the categories above, log the details for yourself and return a clean, generic failure response to the client. This prevents one weird edge case from killing the session for everyone. The server survives, the client gets a signal that something failed, and you keep enough context in your logs to debug later.

The isError Flag Is Non-Negotiable

Here is the detail that actually determines whether your fix works. MCP responses include an isError boolean field. If an exception occurs and you return an error message without setting isError to true, the client treats that error text as a successful tool result.

Imagine your external API hits a rate limit. You catch the exception and return the string "API rate limit exceeded" but leave isError as false. The client passes that string into the model's context window as if it were real tool output. The model then tries to reason over that text as if it were data. It might quote the error in a summary, or worse, it might hallucinate relationships between that error text and other facts. You have turned a temporary infrastructure hiccup into a source of misinformation.

Always set isError to true when you are returning an error payload. This gives the client a clear signal that the tool call failed, which lets the model decide whether to retry, ask for clarification, or try a different tool entirely.

Know What to Catch and What to Kill

Do not wrap your entire server in a blind try-catch that swallows everything. Some errors mean the server should stop immediately. If a required environment variable is missing on startup, or your configuration file is corrupt, no amount of request-level catching will help. Create a specific exception class for fatal errors like these and let them crash the process.

The rule is simple. If the error is temporary or isolated to a single request, catch it and recover. If the error means every subsequent request is guaranteed to fail, let the server die loudly. A fast failure on startup is infinitely better than a server that limps along for days in a broken state.

Add Observability Before You Need It

Once you have the wrapper in place, pair it with structured logging. Log every tool call and its outcome in JSON format. Include the tool name, the raw arguments, the latency, and whether it succeeded, failed, or retried.

This discipline pays off quickly. When you notice a spike in errors, you can filter by tool and spot patterns in minutes. Maybe a specific external API starts throwing timeouts at the same time every day, pointing to a scheduled maintenance window you did not know about. Maybe one tool receives consistently malformed arguments, revealing a prompt engineering flaw upstream. Plain text logs buried in stack traces make this detective work painful. Structured JSON makes it trivial.

The Production Result

I have run this wrapper pattern on two production MCP servers for the past three weeks. In that window, I have seen zero silent failures. Before adding the wrapper, I averaged roughly one unexplained failure every day. The pattern is not complex, but its impact is outsized because it separates survivable noise from real problems.

Silent failures cost more than crashes. A crash triggers your alerting system. Silence just erodes trust. One day your AI agent returns useful tool data, and the next day it starts making things up because the server stopped answering hours ago. The wrapper pattern closes that gap. It keeps your server running through minor turbulence, gives the model enough context to fix its own mistakes, and ensures that when something truly fatal goes wrong, you hear about it immediately.

If you are building MCP tools today, start with the wrapper and the isError flag. Everything else is just cleanup.