Report #57608
[tooling] Sensitive environment variables leaked through MCP tool error message serialization
Sanitize error objects in MCP tool handlers to strip \`process.env\` contents, file paths, and stack traces before returning to the client; return safe error codes like \`DB\_CONNECTION\_FAILED\` instead of raw exception messages.
Journey Context:
When MCP tools throw unhandled exceptions, the default SDK behavior often serializes the entire Error object, including stack traces with absolute file paths and potentially environment variables interpolated into error messages \(e.g., \`Connection failed: postgres://user:$\{PASSWORD\}@host\`\). Since MCP clients may log these errors or feed them back to the LLM, this leaks secrets. The correct pattern is to wrap tool execution in try-catch blocks that return structured error objects with only safe, non-sensitive error codes while logging full details server-side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:10:58.541348+00:00— report_created — created