fix(mcp): redact secrets from open_session, close_session, and server logs
Merged
OK
2mo ago+93+93+01234567890123456789-21-21-01234567890123456789
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 inSessionHost.toolSpecs(). It turns a thrown failure into an error result and redacts the text withprocessSecrets, which holds every value any session resolved or derived (packages/e2e/src/mcp/session.ts,redacting). The duplicate catch inserver.tsis gone. - The config's static secrets go into
processSecretsas 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
processSecretsat the source.closeAllalso 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 anendAttempterror, both throughclose_sessionand through thecloseAllshutdown summary. The other checks a secret in astartAttempterror and in an engineinitlog 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 wrapsweb()soendAttempt(targetleaky-close) orstartAttempt(targetleaky-open) throws... failed for admin:<password>, with credentialadmin/verify-pw-42:
| main | this branch |
|---|---|
Cleanup: ENGINE_FAILURE: attempt end failed: endAttempt failed for admin:verify-pw-42 | Cleanup: ENGINE_FAILURE: attempt end failed: endAttempt failed for admin:<secret:admin.password> |
ENGINE_FAILURE: startAttempt failed for admin:verify-pw-42 | ENGINE_FAILURE: startAttempt failed for admin:<secret:admin.password> |