Skip to content

fix(transport): make debug logging opt-in for message privacy - #803

Open
gabrieledellamalva wants to merge 4 commits into
modelcontextprotocol:mainfrom
gabrieledellamalva:fix/postmessage-opt-in-logger
Open

gabrieledellamalva wants to merge 4 commits into
modelcontextprotocol:mainfrom
gabrieledellamalva:fix/postmessage-opt-in-logger

Conversation

@gabrieledellamalva

@gabrieledellamalva gabrieledellamalva commented Oct 9, 2026 •

Copy link
Copy Markdown

Overview

Privacy / AI agent transport hardening — fixes #786.

PostMessageTransport currently calls console.debug for outgoing and incoming JSON-RPC messages and for messages from unrelated iframe sources. This is noisy in multi-app hosts and can expose raw tool messages in developer consoles or captured browser logs even when the host never requested diagnostic logging.

Changes

  • Make debug logging opt-in via an optional third constructor argument: { logger?: Pick<Console, "debug"> }.
  • Keep existing two-argument constructors and message delivery compatible.
  • Preserve source validation, silent rejection of unrelated/non-JSON-RPC traffic, and the existing console.error path for malformed JSON-RPC messages.
  • Add regression tests covering zero default debug output and an explicitly provided logger.

Scope / security notes

This is defense-in-depth for diagnostic logging and privacy. It is not an authorization boundary, message encryption, a sanitizer for malformed-message error logs, or an MCP tool-permission firewall. Embedders that choose to enable a logger are responsible for protecting their debug output.

Validation

  • Two targeted Bun regression tests added to existing transport suite.
  • Fixed the logger test mock's TypeScript argument typing after a local compiler failure.
  • Local macOS / Bun 1.4.2: bun test src/message-transport.test.ts — 20 passed, 0 failed.
  • Local npm run build — passed.
  • Local npm test — 441 passed, 1 skipped, 0 failed.
  • Formatting-only follow-up commit 0936aa1 applied to both changed files; the final npm run prettier check is not independently confirmed yet.
  • Upstream CI currently reports action_required (GitHub Actions permission/approval), not executed test results.

Closes #786 upon merge.

@gabrieledellamalva gabrieledellamalva changed the title fix(transport): make PostMessageTransport debug logging opt-in fix(transport): make debug logging opt-in for message privacy Oct 9, 2026
@gabrieledellamalva
gabrieledellamalva marked this pull request as ready for review October 9, 2026 21:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostMessageTransport: make debug logging opt-in (or accept a logger)

1 participant