Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#786 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

该 issue 指向 src/message-transport.ts,特别是调用 console.debug 的代码行。首先检查 PostMessageTransport 构造函数及其当前的签名。任务是为 logger 添加一个可选的第三个参数,默认不进行日志记录。检查代码库中其他位置如何实例化该传输,以确保向后兼容性。编写一个测试来验证仅当提供了 logger 时才进行日志记录。

由索引模型根据 Issue 内容生成。

描述

Problem

PostMessageTransport calls console.debug unconditionally (src/message-transport.ts at 264d9ca, lines 77, 82, 87 and 128):

  • "Sending message" for every outgoing message except tool-input-partial
  • "Parsed message" for every valid incoming message
  • "Ignoring message from unknown source" for every message from another frame

A host cannot turn these off. The transport takes no option for it, and the only workaround is wrapping console.debug globally.

The noise grows with the number of Apps on a page. Each card's host transport listens on the same window, so a message from any View reaches every bridge. The owning bridge logs "Parsed message", and each of the other N−1 bridges logs "Ignoring message from unknown source" with the full MessageEvent. With four cards in a conversation, every View message produces four host lines, plus the View's own "Sending message" inside its frame. Size changes and host-context updates fan out the same way.

The source check is correct. Only the logging is the problem.

Prior discussion

  • #237 / #239 moved the unknown-source log from console.error to console.debug.
  • #546 skipped the log for tool-input-partial because it flooded the console.
  • #741 asked for opt-in logging or a configurable logger, and noted that full payloads, including tool-result _meta, reach the console. Its filer closed it without a change.

Proposal

Make transport logging opt-in through an options argument:

new PostMessageTransport(eventTarget, eventSource, { logger?: Pick<Console, "debug"> })

Log nothing when logger is absent. The console.error for a malformed JSON-RPC message can stay. The third argument keeps the existing constructor compatible.

Happy to open a PR if this direction works.

Seen on 1.7.5; unchanged on main as of v2.0.0.

主要语言
TypeScript
星标
2.9k
派生
387
平均合并
2 小时 54 分钟
30 天内合并 PR
7

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/ext-apps 的其他 Issue

查看 modelcontextprotocol/ext-apps 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。