getsentry / getsentry/sentry-javascript

MCP server wrapper misses messages delivered during transport start

已關閉
#23,977 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Bug javascript Node.js
主要語言
TypeScript
星號
8.7k
分支
1.8k
平均合併
1 天 18 小時
30 天內合併 PR
541

描述

## Problem

`wrapMcpServerWithSentry` instruments an MCP transport only after the wrapped
server's `connect()` promise resolves. Both supported MCP TypeScript SDK
generations install their transport callbacks and then call
`transport.start()` before that promise resolves.

A transport is allowed to deliver already-buffered messages from `start()`.
The official `InMemoryTransport` does this in both SDK v1.30.0 and v2.0.0. If
an `initialize` request is queued before the server connects, that first
request reaches the server before Sentry wraps `onmessage`, so no MCP span is
created for it.

## Reproduction

1. Create an official linked `InMemoryTransport` pair.
2. Start `Client.connect()` first so its `initialize` request is queued on the
server transport.
3. Connect a server wrapped with `wrapMcpServerWithSentry`.
4. Inspect the emitted MCP spans.

## Actual behavior

The queued `initialize` request is handled during `transport.start()` and is
missing from Sentry. Later requests are instrumented after `connect()`
completes.

## Expected behavior

- Instrument the callbacks after the MCP SDK installs them but before
`transport.start()` can deliver its first message.
- Preserve the transport's `start()` receiver, promise, errors and property
shape.
- Restore the temporary interception after the connection attempt.
- Preserve the existing post-connect behavior for transports whose `start`
method cannot be intercepted or is not invoked.
- Capture the first request exactly once in MCP SDK v1 and v2, both in v11's
default Sentry-only mode and its optional Sentry-managed
OpenTelemetry-compatible mode (`enableOpenTelemetrySetup: true`).

貢獻指南

開啟貢獻指南

研究方向

首先追蹤 wrapMcpServerWithSentry 經過包裝伺服器的 connect() 流程以及 transport.start() 呼叫,同時比較 MCP SDK v1 和 v2 的回呼設定。使用成對連接的 InMemoryTransport 重現佇列中的 initialize 請求,然後驗證在 Sentry-only 和 enableOpenTelemetrySetup 模式下,第一個請求都恰好被擷取一次,同時 receiver、錯誤、promise、屬性形狀以及連線後的行為保持不變。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
typescript
領域
observability
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
活躍
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。