[v2] Expose the JSON-RPC request id to callers of request() (onRequestId)

Abierto
#3,061 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Arham-Begani ya está trabajando en esto.

Desde el 24/10/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript
Área
api

Línea de trabajo

Start with _requestWithSchemaViaCodec in packages/core-internal/src/shared/protocol.ts and trace how Protocol.request() builds and sends the JSON-RPC message. Check the RequestOptions definitions and related request tests to see how options are passed through. Done means the generated request id is available to callers before sending, with coverage for the callback or chosen return API.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

v1 v2
Summary

Protocol.request() assigns the JSON-RPC id internally (this._requestMessageId++) and never exposes it to the caller. An extension that opens a long-lived request, and then receives notifications correlated to that request, can't tell which request a given notification belongs to.

Why it matters

In the Events extension (SEP-3415, see #2945), a client may hold several events/stream requests open at once. Each stream starts with a notifications/events/active that confirms the subscription. On transports without per-request streams (stdio), the client needs the request id to match that notification to the open that produced it.

In @mastra/mcp we first bound each open to the first unclaimed active notification. That can mismatch subscriptions when one confirmation arrives late after a timeout. We now work around it by wrapping transport.send to observe the outgoing message and read its id. That relies on internal envelope details.

Proposal

Expose the id through a RequestOptions callback, for example onRequestId?: (id: RequestId) => void, invoked synchronously before the message is sent. An alternative would be a lower-level API that returns { id, result } for the request.

Versions

We hit this on @modelcontextprotocol/[email protected]. It's still present on main (c05225a6), in _requestWithSchemaViaCodec in packages/core-internal/src/shared/protocol.ts.

Lenguaje dominante
TypeScript
Estrellas
13.8k
Forks
2.5k
Merge medio
6 d 23 h
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modelcontextprotocol/typescript-sdk

Todos los issues de modelcontextprotocol/typescript-sdk

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.