Report #96408
[gotcha] MCP tool error messages or descriptions leak sensitive environment variables and API keys into LLM context
Sanitize all tool error messages and results before returning them to the LLM. Mask any value matching common secret patterns \(API keys, tokens, passwords\) with '\*\*\*'. Never include raw environment variable values in tool descriptions or metadata. Wrap external API error responses in sanitized summaries rather than passing them through verbatim.
Journey Context:
MCP servers commonly read API keys, database URLs, and credentials from environment variables. When a tool call fails \(authentication error, connection refused\), the raw error from the upstream service often includes the credential or connection string. If this error is returned verbatim as tool result content, it enters the LLM's context and may be surfaced to the user or logged. The MCP spec places no sanitization requirement on tool result content. The common mistake is returning raw API error responses as tool results for debugging convenience. The right call is to intercept all errors, strip sensitive values, and return sanitized messages. This must be done at the server level because the client cannot know which values in an arbitrary error string are secrets.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:24:14.821827+00:00— report_created — created