From f1c5ef1a8d9f5cec8e465f1d8f7571b21048ed2e Mon Sep 17 00:00:00 2001 From: ihrpr Date: Tue, 15 Apr 2025 20:40:26 +0100 Subject: [PATCH] apply suggested changes --- src/client/streamableHttp.ts | 9 ++++++--- src/shared/protocol.ts | 23 ++--------------------- src/shared/transport.ts | 10 ++++++---- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/client/streamableHttp.ts b/src/client/streamableHttp.ts index 770b5d72..44bda015 100644 --- a/src/client/streamableHttp.ts +++ b/src/client/streamableHttp.ts @@ -23,17 +23,20 @@ export class StreamableHTTPError extends Error { /** * Options for starting or authenticating an SSE connection */ -export interface StartSSEOptions { +interface StartSSEOptions { /** * The ID of the last received event, used for resuming a disconnected stream */ lastEventId?: string; + /** * The callback function that is invoked when the last event ID changes */ onLastEventIdUpdate?: (event: string) => void + /** - * When reconnecting to a long-running SSE stream, we need to make sure that message id matches + * Override Message ID to associate with the replay message + * so that response can be associate with the new resumed request. */ replayMessageId?: string | number; } @@ -358,7 +361,7 @@ export class StreamableHTTPClientTransport implements Transport { this.onclose?.(); } - async send(message: JSONRPCMessage | JSONRPCMessage[], options?: { resumptionToken?: string, onresumptiontoken?: (event: string) => void }): Promise { + async send(message: JSONRPCMessage | JSONRPCMessage[], options?: { resumptionToken?: string, onresumptiontoken?: (token: string) => void }): Promise { try { // If client passes in a lastEventId in the request options, we need to reconnect the SSE stream const lastEventId = options?.resumptionToken diff --git a/src/shared/protocol.ts b/src/shared/protocol.ts index 3b098193..289c68d3 100644 --- a/src/shared/protocol.ts +++ b/src/shared/protocol.ts @@ -22,7 +22,7 @@ import { Result, ServerCapabilities, } from "../types.js"; -import { Transport } from "./transport.js"; +import { Transport, TransportSendOptions } from "./transport.js"; /** * Callback for progress notifications. @@ -82,26 +82,7 @@ export type RequestOptions = { * If not specified, there is no maximum total timeout. */ maxTotalTimeout?: number; - - /** - * May be used to indicate to the transport which incoming request to associate this outgoing request with. - */ - relatedRequestId?: RequestId; - - /** - * The resumption token used to continue long-running requests that were interrupted. - * - * This allows clients to reconnect and continue from where they left off, if supported by the transport. - */ - resumptionToken?: string; - - /** - * A callback that is invoked when the resumption token changes, if supported by the transport. - * - * This allows clients to persist the latest token for potential reconnection. - */ - onresumptiontoken?: (token: string) => void; -}; +} & TransportSendOptions; /** * Options that can be given per notification. diff --git a/src/shared/transport.ts b/src/shared/transport.ts index 601a86af..5d559674 100644 --- a/src/shared/transport.ts +++ b/src/shared/transport.ts @@ -1,19 +1,21 @@ import { JSONRPCMessage, RequestId } from "../types.js"; /** - * Options for sending a JSON-RPC message. - */ -export interface TransportSendOptions { + * Options for sending a JSON-RPC message. + */ +export type TransportSendOptions = { /** * If present, `relatedRequestId` is used to indicate to the transport which incoming request to associate this outgoing message with. - */ + */ relatedRequestId?: RequestId; + /** * The resumption token used to continue long-running requests that were interrupted. * * This allows clients to reconnect and continue from where they left off, if supported by the transport. */ resumptionToken?: string; + /** * A callback that is invoked when the resumption token changes, if supported by the transport. *