MCP Shipyard
← Rules catalog

MCP tool output contains a secret: API keys, tokens and database URLs in results

Shipyard flags tool results and errors that contain key, token, JWT or connection-string patterns. Strip them before they reach the model.

blockererrors.secrets-in-outputGeneral, Claude, ChatGPT

Remove keys, tokens and connection strings from every tool result and error message. The rule errors.secrets-in-output is a blocker. OpenAI's server guidance, which the rule cites, says to keep secrets, access tokens and unnecessary personal data out of results.

What you see

  • A scan reports errors.secrets-in-output per tool: "<tool> output looks like it contains: <kind>", where the kind is one of the patterns below.
  • Only tools the scan actually called (fixture calls) can be checked. A tool with no fixture is not tested by this rule.

Why it happens

Output that reaches the model is also shown to the user, logged by the client, and may be kept in conversation history. Secrets usually leak by accident:

  1. An upstream error body is passed through, and it echoes a request header or a connection string.
  2. A debug field such as config or env is returned with the result.
  3. A failed database call returns the driver's message including the URI.
  4. A tool that returns "the request I made" includes the Authorization header.

The patterns the rule looks for: OpenAI-style sk- keys, Stripe-style sk_live_ or rk_test_ keys, GitHub tokens (ghp_ and similar), AWS access key ids (AKIA plus 16 characters), database URIs with a password (postgres, mysql, mongodb, redis, amqp), Bearer tokens, private key blocks and JWTs.

Check it yourself

Call each tool with a valid fixture and a deliberately bad input, then search the text:

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":"does-not-exist"}}}' \
 | grep -E -i 'sk-|sk_live_|ghp_|AKIA|://[^ ]+:[^ ]+@|Bearer |BEGIN .*PRIVATE KEY|eyJ'

Fix

  • Catch upstream errors and return your own message: "Order not found. Use list_orders for valid ids."
  • Allow-list the fields a tool returns instead of serialising whole objects.
  • Never return request headers, environment values or connection settings.
  • Log the full error server-side with a correlation id and return only the id.
  • If a real secret was exposed, rotate it. Removing it from output does not undo the exposure.

Verify

Re-run the call and the grep, then re-scan. Also review errors.stack-trace-leak.

Which clients care

Tagged general, Claude and ChatGPT.

Source

OpenAI MCP server guide: https://developers.openai.com/plugins/build/mcp-server

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