Secure error handling for MCP integrations means designing what a tool sends back when something goes wrong so the model gets enough information to recover sensibly, without leaking stack traces, internal identifiers, or details about the underlying system that a caller was never supposed to see. Error paths get far less design attention than success paths in most software, and MCP tools are no exception. That's a problem specifically here because error messages, like any other tool output, flow straight into the model's context, and a verbose error revealing a database schema, an internal file path, or another user's identifier is a real information disclosure, not just an ugly debugging artifact.
Don't return raw internal errors to the model
A raw database exception, a stack trace, or a framework-level error message often contains details about your internal architecture that have no business reaching a model's context, let alone anything that context might get repeated back to an end user. Catch these internally and translate them into a generic, safe error before they're returned as a tool result.
Give the model enough to decide what to do next
The opposite failure, returning a bare "an error occurred" with no useful detail, leaves the model unable to distinguish a permission problem from a bad parameter from a temporary outage, which often leads to unhelpful retries or a confused response to the user. Strike a balance: return enough structured detail, an error category, whether retrying makes sense, to let the model make a sensible next decision, without exposing internals.
Be careful with errors that confirm or deny existence
An error that says "record not found" versus "you don't have permission to view this record" can leak information about what exists in a system even when access is correctly denied either way. Where this distinction matters for privacy or security, prefer a single, consistent error response regardless of which case actually occurred underneath.
Watch for errors that leak through repeated probing
A single vague error tells an attacker or a manipulated model very little. A sequence of many slightly different errors across many attempts can reveal a lot, the same way error-based enumeration attacks work against conventional APIs. Rate limiting and monitoring, covered elsewhere, are part of the defense here, since error handling alone can't fully prevent an attacker from learning through repetition.
Log the full error internally even when you simplify it externally
Simplifying what a tool returns to the model doesn't mean losing the detail entirely. Log the full internal error, including stack trace and context, in your own systems, so a developer or security team investigating an issue still has what they need even though the model only ever saw a sanitized version.
Design your error taxonomy deliberately
Rather than letting each tool invent its own ad hoc error format, define a small, consistent set of error categories, permission denied, invalid input, temporary failure, not found, that every tool in your system uses the same way. A model that learns to interpret one consistent taxonomy across every tool it calls behaves more predictably than one that has to guess at the meaning of a different error format every time it calls something new, and a consistent taxonomy is also far easier to sanitize correctly across the board.
Errors during high-stakes calls deserve extra caution
An error thrown mid-way through a partially completed action, a payment that failed after a charge attempt, a message that may or may not have sent, needs error handling that clearly communicates the actual state, not just that something went wrong. A model that assumes an ambiguous failure means "nothing happened" can retry an action that actually did partially complete, turning one error into a duplicate transaction or a duplicate message.
Where TELEON fits
Where MCP tool calls pass through the TELEON gateway, the platform's audit trail can capture both the sanitized result returned to the model and, depending on configuration, more detailed internal context, giving teams a fuller picture during an investigation without exposing that same detail to the model itself.
Designing the specific sanitization rules for each tool's error paths is implementation work each team does when building the tool, since it depends on what that tool's underlying system can actually reveal.
A short checklist
- Never return raw stack traces or internal error details as tool output.
- Return enough structured detail for the model to decide whether retrying makes sense.
- Use consistent error responses where distinguishing "not found" from "not authorized" would leak information.
- Monitor for repeated probing patterns that error-based enumeration attacks rely on.
- Log full internal error detail separately from what's returned to the model.
- Review error paths specifically during any security review of a tool, not just its success path.
- Test how each tool behaves under invalid, malformed, and unauthorized input, not only valid input.
Error handling is one of the last places teams think to apply security scrutiny, mostly because an error feels like the absence of something happening rather than an event worth securing in its own right. For an MCP tool feeding results straight into a model's context, that's exactly backwards, since a careless error message can hand over exactly the kind of detail a well-designed success response would never expose.
