fix(mcp): redact secrets from open_session, close_session, and server logs

Merged
OK
2mo ago
+93-21

e2e mcp returned engine and app errors to the client without secret redaction. call results passed the session ledger, but nothing else did. An endAttempt that throws with a configured password in its message put the value verbatim into the close_session "Cleanup:" line. A failed open did the same with the open error.

  • Every fixed tool (open_session, tools, call, close_session) now goes through one wrapper in SessionHost.toolSpecs(). It turns a thrown failure into an error result and redacts the text with processSecrets, which holds every value any session resolved or derived (packages/e2e/src/mcp/session.ts, redacting). The duplicate catch in server.ts is gone.
  • The config's static secrets go into processSecrets as soon as the config loads. Before this, a session registered them only after its engine launched, so an open failure had no ledger to redact with.
  • The teardown text is redacted with processSecrets at the source. closeAll also writes it to stderr as the shutdown summary, and no tool boundary sees that write.
  • Host log lines (engine notices, catalog warnings, sessions that end on their own) are redacted before they reach stderr and the client's notifications/message.

Text from a config that throws while it evaluates is not redacted: its secrets are not resolved yet, the same as for e2e run.

Out of scope: in the e2e mcp process, user code's own console.log / stderr output (project tools, config top-level code) still reaches stderr raw. e2e run redacts worker output with StreamRedactor, and the MCP command has no equivalent. That needs its own change.

Verified

Ran it locally: yes

  • packages/e2e/tests/integration/mcp-session-host.test.ts: two new cases fail on main and pass here. One checks a secret in an endAttempt error, both through close_session and through the closeAll shutdown summary. The other checks a secret in a startAttempt error and in an engine init log line, before any session exists. Mutation-checked: dropping the static registration, the tool wrapper, the teardown redaction, or the log redaction each fails a case.
  • The built CLI (e2e mcp) on the testbed, driven by a real MCP stdio client. The config wraps web() so endAttempt (target leaky-close) or startAttempt (target leaky-open) throws ... failed for admin:<password>, with credential admin / verify-pw-42:
mainthis branch
Cleanup: ENGINE_FAILURE: attempt end failed: endAttempt failed for admin:verify-pw-42Cleanup: ENGINE_FAILURE: attempt end failed: endAttempt failed for admin:<secret:admin.password>
ENGINE_FAILURE: startAttempt failed for admin:verify-pw-42ENGINE_FAILURE: startAttempt failed for admin:<secret:admin.password>