MCP Shipyard
← Rules catalog

MCP tool errors leaking stack traces, file paths or SQL errors

Return a short, actionable message and log the stack trace server-side. The MCP spec requires servers to sanitize tool output.

minorerrors.stack-trace-leakGeneral, Claude

Keep stack traces, file paths and database errors out of tool results. The rule errors.stack-trace-leak is a minor finding for general clients and Claude, reported as a warning. It looks at fixture call output for stack frames, node_modules, Python tracebacks, source file paths with line numbers, ECONNREFUSED, SQLSTATE and "relation ... does not exist".

What you see

  • A scan reports <tool> returned internal details.
  • The model sees a wall of internals, often repeats it to the user, and still cannot tell what to change.

Why it happens

The handler catches an exception and returns String(error) or error.stack as the tool text. Frameworks may do this by default in debug mode.

The MCP tools specification separates two kinds of failure. Protocol errors are JSON-RPC errors. Tool execution errors, such as API failures, input validation errors and business logic errors, go in the result with isError: true, and should contain "actionable feedback that language models can use to self-correct". Its security section says servers MUST validate all tool inputs and "sanitize tool outputs". Claude's review criteria also require actionable error messages and fail generic errors with no detail (see errors.unhelpful-message).

Check it yourself

Call a tool with an invalid argument:

curl -s -X POST https://mcp.acme.example/mcp \
  -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_order","arguments":{"order_id":"not-an-id"}}}' \
 | jq -r '.result.content[0].text'

Fix

try { return await loadOrder(id); }
catch (e) {
  logger.error({ err: e, tool: "get_order", id });          // full detail stays here
  return { isError: true, content: [{ type: "text",
    text: "Order not-an-id was not found. Order ids look like ORD-1042; use list_orders to find one." }] };
}
  1. Log the exception with its trace on your side.
  2. Return what was wrong and what to do next.
  3. Map known failures (not found, not allowed, bad format, upstream timeout) to specific messages.
  4. Turn off debug error pages in production.

Verify

The curl output is a short sentence with a next step and no paths or SQL. Re-scan. Also check errors.secrets-in-output, because stack traces often contain connection strings.

Which clients care

General and Claude, per the rule.

Source

MCP tools specification: https://modelcontextprotocol.io/specification/2026-07-28/server/tools

Run a free scan at https://mcpshipyard.com/scan to check every rule at once.

Check every rule at once

A free scan runs this check and the other 152 against your live URL.

Scan a server