getsentry / getsentry/sentry-javascript

MCP server wrapper misses messages delivered during transport start

Fechada
#23,977 1 comentário 0 reações 0 responsáveis Ver no GitHub
Bug javascript Node.js
Linguagem predominante
TypeScript
Estrelas
8.7k
Forks
1.8k
Merge médio
1d 18h
PRs com merge (30d)
541

Descrição

## 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`).

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece rastreando wrapMcpServerWithSentry pelo fluxo de connect() do servidor encapsulado e pela chamada a transport.start(), comparando a configuração de callbacks do MCP SDK v1 e v2. Reproduza a solicitação initialize enfileirada com pares de InMemoryTransport vinculados e, em seguida, verifique se a primeira solicitação é capturada exatamente uma vez nos modos Sentry-only e enableOpenTelemetrySetup, enquanto receiver, erros, promise, o formato das propriedades e o comportamento pós-conexão permanecem intactos.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
typescript
Domínio
observability
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
55/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.