@draht/mcp 2026.11.27 → 2026.12.3-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/client.d.ts +105 -1
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +318 -33
  4. package/dist/client.js.map +1 -1
  5. package/dist/config-schema.d.ts +109 -0
  6. package/dist/config-schema.d.ts.map +1 -0
  7. package/dist/config-schema.js +105 -0
  8. package/dist/config-schema.js.map +1 -0
  9. package/dist/config.d.ts +6 -74
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/config.js +9 -2
  12. package/dist/config.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/oauth/callback.d.ts.map +1 -1
  18. package/dist/oauth/callback.js +4 -2
  19. package/dist/oauth/callback.js.map +1 -1
  20. package/dist/protocol/http-headers.d.ts +31 -0
  21. package/dist/protocol/http-headers.d.ts.map +1 -0
  22. package/dist/protocol/http-headers.js +129 -0
  23. package/dist/protocol/http-headers.js.map +1 -0
  24. package/dist/protocol/stateless.d.ts +47 -0
  25. package/dist/protocol/stateless.d.ts.map +1 -0
  26. package/dist/protocol/stateless.js +102 -0
  27. package/dist/protocol/stateless.js.map +1 -0
  28. package/dist/protocol/types.d.ts +33 -0
  29. package/dist/protocol/types.d.ts.map +1 -1
  30. package/dist/protocol/types.js +5 -0
  31. package/dist/protocol/types.js.map +1 -1
  32. package/dist/transports/streamable-http.d.ts +14 -4
  33. package/dist/transports/streamable-http.d.ts.map +1 -1
  34. package/dist/transports/streamable-http.js +81 -26
  35. package/dist/transports/streamable-http.js.map +1 -1
  36. package/dist/transports/transport.d.ts +12 -0
  37. package/dist/transports/transport.d.ts.map +1 -1
  38. package/dist/transports/transport.js.map +1 -1
  39. package/package.json +8 -2
@@ -0,0 +1,102 @@
1
+ // Wire rules of the stateless MCP revision (2026-07-28): request metadata, result types, and the
2
+ // `server/discover` result.
3
+ import { isObject, JSON_RPC_ERROR_CODES, McpError } from "./jsonrpc.js";
4
+ /** Error code of a request whose `Mcp-*` headers do not match its body (MCP 2026-07-28). */
5
+ export const HEADER_MISMATCH_ERROR_CODE = -32020;
6
+ /**
7
+ * Error codes MCP 2026-07-28 reserves: header mismatch, missing required client capability, and
8
+ * unsupported protocol version. Only servers of that revision send them.
9
+ */
10
+ export const STATELESS_ERROR_CODES = [HEADER_MISMATCH_ERROR_CODE, -32021, -32022];
11
+ /** `params` with the stateless request metadata added to its `_meta`, keeping the `_meta` keys it has. */
12
+ export function withStatelessMeta(params, meta) {
13
+ return {
14
+ ...params,
15
+ _meta: {
16
+ ...(isObject(params?._meta) ? params._meta : {}),
17
+ "io.modelcontextprotocol/protocolVersion": meta.protocolVersion,
18
+ "io.modelcontextprotocol/clientInfo": meta.clientInfo,
19
+ "io.modelcontextprotocol/clientCapabilities": meta.clientCapabilities,
20
+ ...(meta.logLevel === undefined ? {} : { "io.modelcontextprotocol/logLevel": meta.logLevel }),
21
+ },
22
+ };
23
+ }
24
+ /**
25
+ * Read the `resultType` of a stateless result (wire input). A result without one is complete; other
26
+ * result types than the base protocol's are left to the caller, which knows the extensions it supports.
27
+ */
28
+ export function readStatelessResult(method, value) {
29
+ if (!isObject(value))
30
+ throw invalid(`Invalid MCP ${method} result`);
31
+ const { resultType, inputRequests, requestState } = value;
32
+ if (resultType === undefined || resultType === "complete")
33
+ return { kind: "complete", result: value };
34
+ if (typeof resultType !== "string")
35
+ throw invalid(`Unsupported MCP ${method} result type: ${String(resultType)}`);
36
+ if (resultType !== "input_required")
37
+ return { kind: "extension", resultType, result: value };
38
+ if (inputRequests !== undefined && !isInputRequests(inputRequests)) {
39
+ throw invalid(`Invalid input requests in MCP ${method} result`);
40
+ }
41
+ if (requestState !== undefined && typeof requestState !== "string") {
42
+ throw invalid(`Invalid request state in MCP ${method} result`);
43
+ }
44
+ if (inputRequests === undefined && requestState === undefined) {
45
+ throw invalid(`MCP ${method} result requires input but names neither input requests nor request state`);
46
+ }
47
+ return { kind: "input_required", inputRequests: inputRequests ?? {}, requestState };
48
+ }
49
+ function isInputRequests(value) {
50
+ if (!isObject(value))
51
+ return false;
52
+ return Object.values(value).every((request) => isObject(request) &&
53
+ typeof request.method === "string" &&
54
+ (request.params === undefined || isObject(request.params)));
55
+ }
56
+ /** Validate a `server/discover` result (wire input), with the server's name and version from its `_meta`. */
57
+ export function validateDiscoverResult(value) {
58
+ if (!isObject(value) ||
59
+ !Array.isArray(value.supportedVersions) ||
60
+ !value.supportedVersions.every((version) => typeof version === "string") ||
61
+ !isObject(value.capabilities) ||
62
+ (value.instructions !== undefined && typeof value.instructions !== "string")) {
63
+ throw invalid("Invalid MCP server/discover result");
64
+ }
65
+ const result = value;
66
+ // Servers SHOULD name themselves, but need not.
67
+ const info = isObject(value._meta) ? value._meta["io.modelcontextprotocol/serverInfo"] : undefined;
68
+ if (!isObject(info) || typeof info.name !== "string" || typeof info.version !== "string")
69
+ return { result };
70
+ const serverInfo = {
71
+ name: info.name,
72
+ version: info.version,
73
+ ...(typeof info.title === "string" ? { title: info.title } : {}),
74
+ };
75
+ return { result, serverInfo };
76
+ }
77
+ /** The subscription a notification belongs to (`_meta`), by the id of its `subscriptions/listen` request. */
78
+ export function subscriptionIdOf(params) {
79
+ return isObject(params) && isObject(params._meta)
80
+ ? params._meta["io.modelcontextprotocol/subscriptionId"]
81
+ : undefined;
82
+ }
83
+ const SUBSCRIPTION_FLAGS = ["toolsListChanged", "promptsListChanged", "resourcesListChanged"];
84
+ /** The notification types a `notifications/subscriptions/acknowledged` agrees to (wire input); others are left out. */
85
+ export function readSubscriptionFilter(params) {
86
+ const value = isObject(params) ? params.notifications : undefined;
87
+ if (!isObject(value))
88
+ return {};
89
+ const filter = {};
90
+ for (const key of SUBSCRIPTION_FLAGS) {
91
+ if (typeof value[key] === "boolean")
92
+ filter[key] = value[key];
93
+ }
94
+ const uris = value.resourceSubscriptions;
95
+ if (Array.isArray(uris) && uris.every((uri) => typeof uri === "string"))
96
+ filter.resourceSubscriptions = uris;
97
+ return filter;
98
+ }
99
+ function invalid(message) {
100
+ return new McpError(JSON_RPC_ERROR_CODES.invalidRequest, message);
101
+ }
102
+ //# sourceMappingURL=stateless.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stateless.js","sourceRoot":"","sources":["../../src/protocol/stateless.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,4BAA4B;AAC5B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAWxE,4FAA4F;AAC5F,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,KAAK,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAsB,CAAC,0BAA0B,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAUrG,0GAA0G;AAC1G,MAAM,UAAU,iBAAiB,CAChC,MAA2C,EAC3C,IAA0B;IAE1B,OAAO;QACN,GAAG,MAAM;QACT,KAAK,EAAE;YACN,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,yCAAyC,EAAE,IAAI,CAAC,eAAe;YAC/D,oCAAoC,EAAE,IAAI,CAAC,UAAU;YACrD,4CAA4C,EAAE,IAAI,CAAC,kBAAkB;YACrE,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,kCAAkC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC7F;KACD,CAAC;AACH,CAAC;AASD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,KAAc;IACjE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;Q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,CAAC,CAAC;AACnE,CAAC","sourcesContent":["// Wire rules of the stateless MCP revision (2026-07-28): request metadata, result types, and the\n// `server/discover` result.\nimport { isObject, JSON_RPC_ERROR_CODES, McpError } from \"./jsonrpc.ts\";\nimport type {\n\tClientCapabilities,\n\tDiscoverResult,\n\tImplementation,\n\tInputRequest,\n\tLoggingLevel,\n\tSTATELESS_PROTOCOL_VERSION,\n\tSubscriptionFilter,\n} from \"./types.ts\";\n\n/** Error code of a request whose `Mcp-*` headers do not match its body (MCP 2026-07-28). */\nexport const HEADER_MISMATCH_ERROR_CODE = -32020;\n\n/**\n * Error codes MCP 2026-07-28 reserves: header mismatch, missing required client capability, and\n * unsupported protocol version. Only servers of that revision send them.\n */\nexport const STATELESS_ERROR_CODES: readonly number[] = [HEADER_MISMATCH_ERROR_CODE, -32021, -32022];\n\n/** What every stateless request declares about the client in its `_meta`. */\nexport interface StatelessRequestMeta {\n\tprotocolVersion: typeof STATELESS_PROTOCOL_VERSION;\n\tclientInfo: Implementation;\n\tclientCapabilities: ClientCapabilities;\n\tlogLevel: LoggingLevel | undefined;\n}\n\n/** `params` with the stateless request metadata added to its `_meta`, keeping the `_meta` keys it has. */\nexport function withStatelessMeta(\n\tparams: Record<string, unknown> | undefined,\n\tmeta: StatelessRequestMeta,\n): Record<string, unknown> {\n\treturn {\n\t\t...params,\n\t\t_meta: {\n\t\t\t...(isObject(params?._meta) ? params._meta : {}),\n\t\t\t\"io.modelcontextprotocol/protocolVersion\": meta.protocolVersion,\n\t\t\t\"io.modelcontextprotocol/clientInfo\": meta.clientInfo,\n\t\t\t\"io.modelcontextprotocol/clientCapabilities\": meta.clientCapabilities,\n\t\t\t...(meta.logLevel === undefined ? {} : { \"io.modelcontextprotocol/logLevel\": meta.logLevel }),\n\t\t},\n\t};\n}\n\n/** A result of a stateless request, by `resultType`. */\nexport type StatelessResult =\n\t| { kind: \"complete\"; result: unknown }\n\t| { kind: \"input_required\"; inputRequests: Record<string, InputRequest>; requestState: string | undefined }\n\t/** A result type an MCP extension defines (`upload_required`, say); the whole result, unchecked. */\n\t| { kind: \"extension\"; resultType: string; result: Record<string, unknown> };\n\n/**\n * Read the `resultType` of a stateless result (wire input). A result without one is complete; other\n * result types than the base protocol's are left to the caller, which knows the extensions it supports.\n */\nexport function readStatelessResult(method: string, value: unknown): StatelessResult {\n\tif (!isObject(value)) throw invalid(`Invalid MCP ${method} result`);\n\tconst { resultType, inputRequests, requestState } = value;\n\tif (resultType === undefined || resultType === \"complete\") return { kind: \"complete\", result: value };\n\tif (typeof resultType !== \"string\") throw invalid(`Unsupported MCP ${method} result type: ${String(resultType)}`);\n\tif (resultType !== \"input_required\") return { kind: \"extension\", resultType, result: value };\n\tif (inputRequests !== undefined && !isInputRequests(inputRequests)) {\n\t\tthrow invalid(`Invalid input requests in MCP ${method} result`);\n\t}\n\tif (requestState !== undefined && typeof requestState !== \"string\") {\n\t\tthrow invalid(`Invalid request state in MCP ${method} result`);\n\t}\n\tif (inputRequests === undefined && requestState === undefined) {\n\t\tthrow invalid(`MCP ${method} result requires input but names neither input requests nor request state`);\n\t}\n\treturn { kind: \"input_required\", inputRequests: inputRequests ?? {}, requestState };\n}\n\nfunction isInputRequests(value: unknown): value is Record<string, InputRequest> {\n\tif (!isObject(value)) return false;\n\treturn Object.values(value).every(\n\t\t(request) =>\n\t\t\tisObject(request) &&\n\t\t\ttypeof request.method === \"string\" &&\n\t\t\t(request.params === undefined || isObject(request.params)),\n\t);\n}\n\n/** Validate a `server/discover` result (wire input), with the server's name and version from its `_meta`. */\nexport function validateDiscoverResult(value: unknown): { result: DiscoverResult; serverInfo?: Implementation } {\n\tif (\n\t\t!isObject(value) ||\n\t\t!Array.isArray(value.supportedVersions) ||\n\t\t!value.supportedVersions.every((version) => typeof version === \"string\") ||\n\t\t!isObject(value.capabilities) ||\n\t\t(value.instructions !== undefined && typeof value.instructions !== \"string\")\n\t) {\n\t\tthrow invalid(\"Invalid MCP server/discover result\");\n\t}\n\tconst result = value as unknown as DiscoverResult;\n\t// Servers SHOULD name themselves, but need not.\n\tconst info = isObject(value._meta) ? value._meta[\"io.modelcontextprotocol/serverInfo\"] : undefined;\n\tif (!isObject(info) || typeof info.name !== \"string\" || typeof info.version !== \"string\") return { result };\n\tconst serverInfo = {\n\t\tname: info.name,\n\t\tversion: info.version,\n\t\t...(typeof info.title === \"string\" ? { title: info.title } : {}),\n\t};\n\treturn { result, serverInfo };\n}\n\n/** The subscription a notification belongs to (`_meta`), by the id of its `subscriptions/listen` request. */\nexport function subscriptionIdOf(params: unknown): unknown {\n\treturn isObject(params) && isObject(params._meta)\n\t\t? params._meta[\"io.modelcontextprotocol/subscriptionId\"]\n\t\t: undefined;\n}\n\nconst SUBSCRIPTION_FLAGS = [\"toolsListChanged\", \"promptsListChanged\", \"resourcesListChanged\"] as const;\n\n/** The notification types a `notifications/subscriptions/acknowledged` agrees to (wire input); others are left out. */\nexport function readSubscriptionFilter(params: unknown): SubscriptionFilter {\n\tconst value = isObject(params) ? params.notifications : undefined;\n\tif (!isObject(value)) return {};\n\tconst filter: SubscriptionFilter = {};\n\tfor (const key of SUBSCRIPTION_FLAGS) {\n\t\tif (typeof value[key] === \"boolean\") filter[key] = value[key];\n\t}\n\tconst uris = value.resourceSubscriptions;\n\tif (Array.isArray(uris) && uris.every((uri) => typeof uri === \"string\")) filter.resourceSubscriptions = uris;\n\treturn filter;\n}\n\nfunction invalid(message: string): McpError {\n\treturn new McpError(JSON_RPC_ERROR_CODES.invalidRequest, message);\n}\n"]}
@@ -7,6 +7,18 @@ export declare const LATEST_PROTOCOL_VERSION = "2025-11-25";
7
7
  */
8
8
  export declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
9
9
  export type SupportedProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];
10
+ /**
11
+ * The stateless protocol revision: no `initialize` handshake and no session; every request carries the
12
+ * protocol version and the client's info and capabilities in `_meta`.
13
+ */
14
+ export declare const STATELESS_PROTOCOL_VERSION = "2026-07-28";
15
+ /**
16
+ * How a client picks the protocol. `auto`: `initialize` first, as servers of every earlier revision
17
+ * expect; only when the server rejects it, `server/discover` for the stateless revision. A version
18
+ * (`2026-07-28`) speaks only that revision.
19
+ */
20
+ export type McpProtocolMode = "auto" | typeof STATELESS_PROTOCOL_VERSION;
21
+ export type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
10
22
  export interface Implementation {
11
23
  name: string;
12
24
  version: string;
@@ -18,6 +30,7 @@ export interface Root {
18
30
  }
19
31
  export interface ClientCapabilities {
20
32
  experimental?: Record<string, unknown>;
33
+ extensions?: Record<string, Record<string, unknown>>;
21
34
  roots?: {
22
35
  listChanged?: boolean;
23
36
  };
@@ -26,6 +39,7 @@ export interface ClientCapabilities {
26
39
  }
27
40
  export interface ServerCapabilities {
28
41
  experimental?: Record<string, unknown>;
42
+ extensions?: Record<string, Record<string, unknown>>;
29
43
  logging?: Record<string, unknown>;
30
44
  prompts?: {
31
45
  listChanged?: boolean;
@@ -50,6 +64,25 @@ export interface InitializeResult {
50
64
  serverInfo: Implementation;
51
65
  instructions?: string;
52
66
  }
67
+ /** The answer to `server/discover` (MCP 2026-07-28). */
68
+ export interface DiscoverResult {
69
+ supportedVersions: string[];
70
+ capabilities: ServerCapabilities;
71
+ instructions?: string;
72
+ _meta?: Record<string, unknown>;
73
+ }
74
+ /** Notification types a `subscriptions/listen` stream delivers (MCP 2026-07-28). */
75
+ export interface SubscriptionFilter {
76
+ toolsListChanged?: boolean;
77
+ promptsListChanged?: boolean;
78
+ resourcesListChanged?: boolean;
79
+ resourceSubscriptions?: string[];
80
+ }
81
+ /** A request the server needs answered before it can complete a request (MCP 2026-07-28). */
82
+ export interface InputRequest {
83
+ method: string;
84
+ params?: Record<string, unknown>;
85
+ }
53
86
  export interface ProgressNotification {
54
87
  progressToken: string | number;
55
88
  progress: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types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C;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,2BAA2B;IAC3C,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,CAAC,oBAAoB,GAAG,oBAAoB,CAAC,EAAE,CAAC;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC"}
@@ -4,4 +4,9 @@ export const LATEST_PROTOCOL_VERSION = "2025-11-25";
4
4
  * with their own latest one, so older versions stay accepted for servers built on older SDKs.
5
5
  */
6
6
  export const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05"];
7
+ /**
8
+ * The stateless protocol revision: no `initialize` handshake and no session; every request carries the
9
+ * protocol version and the client's info and capabilities in `_meta`.
10
+ */
11
+ export const STATELESS_PROTOCOL_VERSION = "2026-07-28";
7
12
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/protocol/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACpD;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC","sourcesContent":["import type { BlobResourceContents, ContentAnnotations, TextResourceContents } from \"./content.ts\";\nimport type { JsonRpcId } from \"./jsonrpc.ts\";\n\nexport const LATEST_PROTOCOL_VERSION = \"2025-11-25\";\n/**\n * Versions the client accepts from a server. Servers that do not support the requested version answer\n * with their own latest one, so older versions stay accepted for servers built on older SDKs.\n */\nexport const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, \"2025-06-18\", \"2025-03-26\", \"2024-11-05\"] as const;\nexport type SupportedProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];\n\nexport interface Implementation {\n\tname: string;\n\tversion: string;\n\ttitle?: string;\n}\n\nexport interface Root {\n\turi: string;\n\tname?: string;\n}\n\nexport interface ClientCapabilities {\n\texperimental?: Record<string, unknown>;\n\troots?: { listChanged?: boolean };\n\tsampling?: Record<string, unknown>;\n\telicitation?: Record<string, unknown>;\n}\n\nexport interface ServerCapabilities {\n\texperimental?: Record<string, unknown>;\n\tlogging?: Record<string, unknown>;\n\tprompts?: { listChanged?: boolean };\n\tresources?: { subscribe?: boolean; listChanged?: boolean };\n\ttools?: { listChanged?: boolean };\n\tcompletions?: Record<string, unknown>;\n}\n\nexport interface InitializeParams {\n\tprotocolVersion: string;\n\tcapabilities: ClientCapabilities;\n\tclientInfo: Implementation;\n}\n\nexport interface InitializeResult {\n\tprotocolVersion: string;\n\tcapabilities: ServerCapabilities;\n\tserverInfo: Implementation;\n\tinstructions?: string;\n}\n\nexport interface ProgressNotification {\n\tprogressToken: string | number;\n\tprogress: number;\n\ttotal?: number;\n\tmessage?: string;\n}\n\nexport interface CancelledNotification {\n\trequestId: JsonRpcId;\n\treason?: string;\n}\n\nexport interface ToolAnnotations {\n\ttitle?: string;\n\treadOnlyHint?: boolean;\n\tdestructiveHint?: boolean;\n\tidempotentHint?: boolean;\n\topenWorldHint?: boolean;\n}\n\nexport interface ToolExecution {\n\ttaskSupport?: \"forbidden\" | \"optional\" | \"required\";\n}\n\nexport interface Tool {\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tinputSchema: Record<string, unknown>;\n\toutputSchema?: Record<string, unknown>;\n\tannotations?: ToolAnnotations;\n\texecution?: ToolExecution;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListToolsResult {\n\ttools: Tool[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\n/** A resource a server lists in `resources/list`. */\nexport interface Resource {\n\turi: string;\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tmimeType?: string;\n\tsize?: number;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\n/** A family of resources, addressed by an RFC 6570 URI template, from `resources/templates/list`. */\nexport interface ResourceTemplate {\n\turiTemplate: string;\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tmimeType?: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListResourcesResult {\n\tresources: Resource[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListResourceTemplatesResult {\n\tresourceTemplates: ResourceTemplate[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ReadResourceResult {\n\tcontents: (TextResourceContents | BlobResourceContents)[];\n\t_meta?: Record<string, unknown>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/protocol/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACpD;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,uBAAuB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;AAGxH;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,YAAY,CAAC","sourcesContent":["import type { BlobResourceContents, ContentAnnotations, TextResourceContents } from \"./content.ts\";\nimport type { JsonRpcId } from \"./jsonrpc.ts\";\n\nexport const LATEST_PROTOCOL_VERSION = \"2025-11-25\";\n/**\n * Versions the client accepts from a server. Servers that do not support the requested version answer\n * with their own latest one, so older versions stay accepted for servers built on older SDKs.\n */\nexport const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, \"2025-06-18\", \"2025-03-26\", \"2024-11-05\"] as const;\nexport type SupportedProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];\n\n/**\n * The stateless protocol revision: no `initialize` handshake and no session; every request carries the\n * protocol version and the client's info and capabilities in `_meta`.\n */\nexport const STATELESS_PROTOCOL_VERSION = \"2026-07-28\";\n\n/**\n * How a client picks the protocol. `auto`: `initialize` first, as servers of every earlier revision\n * expect; only when the server rejects it, `server/discover` for the stateless revision. A version\n * (`2026-07-28`) speaks only that revision.\n */\nexport type McpProtocolMode = \"auto\" | typeof STATELESS_PROTOCOL_VERSION;\n\nexport type LoggingLevel = \"debug\" | \"info\" | \"notice\" | \"warning\" | \"error\" | \"critical\" | \"alert\" | \"emergency\";\n\nexport interface Implementation {\n\tname: string;\n\tversion: string;\n\ttitle?: string;\n}\n\nexport interface Root {\n\turi: string;\n\tname?: string;\n}\n\nexport interface ClientCapabilities {\n\texperimental?: Record<string, unknown>;\n\textensions?: Record<string, Record<string, unknown>>;\n\troots?: { listChanged?: boolean };\n\tsampling?: Record<string, unknown>;\n\telicitation?: Record<string, unknown>;\n}\n\nexport interface ServerCapabilities {\n\texperimental?: Record<string, unknown>;\n\textensions?: Record<string, Record<string, unknown>>;\n\tlogging?: Record<string, unknown>;\n\tprompts?: { listChanged?: boolean };\n\tresources?: { subscribe?: boolean; listChanged?: boolean };\n\ttools?: { listChanged?: boolean };\n\tcompletions?: Record<string, unknown>;\n}\n\nexport interface InitializeParams {\n\tprotocolVersion: string;\n\tcapabilities: ClientCapabilities;\n\tclientInfo: Implementation;\n}\n\nexport interface InitializeResult {\n\tprotocolVersion: string;\n\tcapabilities: ServerCapabilities;\n\tserverInfo: Implementation;\n\tinstructions?: string;\n}\n\n/** The answer to `server/discover` (MCP 2026-07-28). */\nexport interface DiscoverResult {\n\tsupportedVersions: string[];\n\tcapabilities: ServerCapabilities;\n\tinstructions?: string;\n\t_meta?: Record<string, unknown>;\n}\n\n/** Notification types a `subscriptions/listen` stream delivers (MCP 2026-07-28). */\nexport interface SubscriptionFilter {\n\ttoolsListChanged?: boolean;\n\tpromptsListChanged?: boolean;\n\tresourcesListChanged?: boolean;\n\tresourceSubscriptions?: string[];\n}\n\n/** A request the server needs answered before it can complete a request (MCP 2026-07-28). */\nexport interface InputRequest {\n\tmethod: string;\n\tparams?: Record<string, unknown>;\n}\n\nexport interface ProgressNotification {\n\tprogressToken: string | number;\n\tprogress: number;\n\ttotal?: number;\n\tmessage?: string;\n}\n\nexport interface CancelledNotification {\n\trequestId: JsonRpcId;\n\treason?: string;\n}\n\nexport interface ToolAnnotations {\n\ttitle?: string;\n\treadOnlyHint?: boolean;\n\tdestructiveHint?: boolean;\n\tidempotentHint?: boolean;\n\topenWorldHint?: boolean;\n}\n\nexport interface ToolExecution {\n\ttaskSupport?: \"forbidden\" | \"optional\" | \"required\";\n}\n\nexport interface Tool {\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tinputSchema: Record<string, unknown>;\n\toutputSchema?: Record<string, unknown>;\n\tannotations?: ToolAnnotations;\n\texecution?: ToolExecution;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListToolsResult {\n\ttools: Tool[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\n/** A resource a server lists in `resources/list`. */\nexport interface Resource {\n\turi: string;\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tmimeType?: string;\n\tsize?: number;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\n/** A family of resources, addressed by an RFC 6570 URI template, from `resources/templates/list`. */\nexport interface ResourceTemplate {\n\turiTemplate: string;\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\tmimeType?: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListResourcesResult {\n\tresources: Resource[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ListResourceTemplatesResult {\n\tresourceTemplates: ResourceTemplate[];\n\tnextCursor?: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ReadResourceResult {\n\tcontents: (TextResourceContents | BlobResourceContents)[];\n\t_meta?: Record<string, unknown>;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { AuthProvider, McpFetch } from "../auth-provider.ts";
2
- import { type JsonRpcMessage } from "../protocol/jsonrpc.ts";
2
+ import { type JsonRpcErrorObject, type JsonRpcMessage } from "../protocol/jsonrpc.ts";
3
3
  import { type McpTransport, type McpTransportSendOptions, TransportEvents } from "./transport.ts";
4
4
  export interface SseEvent {
5
5
  event?: string;
@@ -46,7 +46,10 @@ export declare class McpAuthRequiredError extends McpHttpError {
46
46
  export declare class McpSessionExpiredError extends McpHttpError {
47
47
  constructor(body?: string);
48
48
  }
49
+ /** The JSON-RPC error in an HTTP error body, which servers on the stateless revision send with 4xx statuses. */
50
+ export declare function jsonRpcErrorIn(body: string): JsonRpcErrorObject | undefined;
49
51
  export declare class StreamableHttpTransport extends TransportEvents implements McpTransport {
52
+ readonly sendsHeaders = true;
50
53
  readonly url: URL;
51
54
  readonly options: Readonly<StreamableHttpTransportOptions>;
52
55
  private fetch;
@@ -55,6 +58,11 @@ export declare class StreamableHttpTransport extends TransportEvents implements
55
58
  private closed;
56
59
  private sessionIdValue;
57
60
  private protocolVersion;
61
+ /**
62
+ * MCP 2026-07-28: no session, `Mcp-Method` and `Mcp-Name` headers, response streams that cannot be
63
+ * resumed, and closing a request's response stream cancels it.
64
+ */
65
+ private stateless;
58
66
  private getStreamStarted;
59
67
  /** Access token of the latest request, which `close()` reuses instead of asking the auth provider. */
60
68
  private lastToken;
@@ -62,11 +70,12 @@ export declare class StreamableHttpTransport extends TransportEvents implements
62
70
  get sessionId(): string | undefined;
63
71
  start(): Promise<void>;
64
72
  setProtocolVersion(version: string): void;
65
- send(message: JsonRpcMessage, { signal }?: McpTransportSendOptions): Promise<void>;
73
+ send(message: JsonRpcMessage, { signal, headers }?: McpTransportSendOptions): Promise<void>;
66
74
  close(): Promise<void>;
67
75
  /**
68
76
  * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider
69
- * once, and the request is retried with whatever credentials it left behind.
77
+ * once, and the request is retried with whatever credentials it left behind. `init.signal` aborts
78
+ * the fetch itself.
70
79
  *
71
80
  * `signal` only stops dispatch: getting a token or the authorization recovery can take a while, and a
72
81
  * request its sender gave up on in the meantime must not reach the server. It does not abort the shared
@@ -81,7 +90,8 @@ export declare class StreamableHttpTransport extends TransportEvents implements
81
90
  /**
82
91
  * Read the SSE stream answering one request. When the stream ends or breaks before the response
83
92
  * arrives and the server assigned event IDs, resume it with GET and `Last-Event-ID`, as the
84
- * server may close response streams at will. Otherwise only this request fails.
93
+ * server may close response streams at will. Otherwise, and always on the stateless revision,
94
+ * only this request fails.
85
95
  */
86
96
  private consumeResponseStream;
87
97
  private startGetStream;
@@ -1 +1 @@
1
- {"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../src/transports/streamable-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAKN,KAAK,cAAc,EAMnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,eAAe,EACf,MAAM,gBAAgB,CAAC;AAQxB,MAAM,WAAW,QAAQ;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,iBAAiB;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC/B,0GAA0G;IAC1G,IAAI,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,6DAA6D;IAC7D,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,GAA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O,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAE,uBAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDpG;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3B;IAED;;;;;;;;OAQG;YACW,eAAe;YAyBf,OAAO;IAMrB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,cAAc;YAKR,aAAa;YASb,UAAU;IA8BxB;;;;;OAKG;YACW,qBAAqB;IA6CnC,OAAO,CAAC,cAAc;IAMtB,sFAAsF;YACxE,YAAY;IA2B1B,gGAAgG;YAClF,aAAa;IAqB3B;;;OAGG;IACH,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,UAAU;IAIlB,8DAA8D;IAC9D,OAAO,CAAC,KAAK;CAiBb"}
@@ -1,4 +1,6 @@
1
- import { isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, normalizeOwnRequestId, parseJsonRpcMessage, toError, } from "../protocol/jsonrpc.js";
1
+ import { standardRequestHeaders } from "../protocol/http-headers.js";
2
+ import { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, isObject, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, normalizeOwnRequestId, parseJsonRpcMessage, toError, } from "../protocol/jsonrpc.js";
3
+ import { STATELESS_PROTOCOL_VERSION } from "../protocol/types.js";
2
4
  import { DEFAULT_MAX_MESSAGE_BYTES, TransportEvents, } from "./transport.js";
3
5
  const MAX_ERROR_BODY_BYTES = 8 * 1024;
4
6
  const ERROR_MESSAGE_BODY_CHARS = 500;
@@ -8,7 +10,10 @@ const DEFAULT_RECONNECT_MAX_RETRIES = 5;
8
10
  export async function consumeSseStream(stream, options) {
9
11
  const reader = stream.getReader();
10
12
  const decoder = new TextDecoder();
11
- let buffered = "";
13
+ // The incomplete last line. Only new text is scanned and the line is read once when it ends, so a large
14
+ // line arriving in many chunks costs time linear in its size.
15
+ let pendingLine = "";
16
+ let pendingLineBytes = 0;
12
17
  let eventName;
13
18
  let eventId;
14
19
  let dataLines = [];
@@ -58,16 +63,18 @@ export async function consumeSseStream(stream, options) {
58
63
  };
59
64
  // SSE lines end with CRLF, LF, or a lone CR.
60
65
  let skipLeadingLf = false;
61
- const consumeLines = () => {
66
+ const consumeLines = (text) => {
62
67
  let start = 0;
63
- for (let i = 0; i < buffered.length; i++) {
64
- const char = buffered[i];
68
+ for (let i = 0; i < text.length; i++) {
69
+ const char = text[i];
65
70
  if (char !== "\r" && char !== "\n")
66
71
  continue;
67
- processLine(buffered.slice(start, i));
72
+ processLine(pendingLine + text.slice(start, i));
73
+ pendingLine = "";
74
+ pendingLineBytes = 0;
68
75
  if (char === "\r") {
69
- if (i + 1 < buffered.length) {
70
- if (buffered[i + 1] === "\n")
76
+ if (i + 1 < text.length) {
77
+ if (text[i + 1] === "\n")
71
78
  i++;
72
79
  }
73
80
  else {
@@ -76,7 +83,9 @@ export async function consumeSseStream(stream, options) {
76
83
  }
77
84
  start = i + 1;
78
85
  }
79
- buffered = buffered.slice(start);
86
+ const rest = text.slice(start);
87
+ pendingLine += rest;
88
+ pendingLineBytes += Buffer.byteLength(rest);
80
89
  };
81
90
  try {
82
91
  while (true) {
@@ -90,18 +99,16 @@ export async function consumeSseStream(stream, options) {
90
99
  text = text.slice(1);
91
100
  skipLeadingLf = false;
92
101
  }
93
- buffered += text;
94
- consumeLines();
95
- if (Buffer.byteLength(buffered) > maxEventBytes)
102
+ consumeLines(text);
103
+ if (pendingLineBytes > maxEventBytes)
96
104
  throw new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);
97
105
  }
98
106
  let tail = decoder.decode();
99
107
  if (skipLeadingLf && tail.startsWith("\n"))
100
108
  tail = tail.slice(1);
101
- buffered += tail;
102
- consumeLines();
103
- if (buffered)
104
- processLine(buffered);
109
+ consumeLines(tail);
110
+ if (pendingLine)
111
+ processLine(pendingLine);
105
112
  dispatch();
106
113
  }
107
114
  catch (error) {
@@ -189,7 +196,24 @@ function describeHttpFailure(status, body) {
189
196
  const snippet = text.length > ERROR_MESSAGE_BODY_CHARS ? `${text.slice(0, ERROR_MESSAGE_BODY_CHARS - 3)}...` : text;
190
197
  return `MCP HTTP request failed with status ${status}${snippet ? `: ${snippet}` : ""}`;
191
198
  }
199
+ /** The JSON-RPC error in an HTTP error body, which servers on the stateless revision send with 4xx statuses. */
200
+ export function jsonRpcErrorIn(body) {
201
+ let parsed;
202
+ try {
203
+ parsed = JSON.parse(body);
204
+ }
205
+ catch {
206
+ return undefined;
207
+ }
208
+ if (!isObject(parsed) || parsed.jsonrpc !== "2.0" || !isObject(parsed.error))
209
+ return undefined;
210
+ const { code, message, data } = parsed.error;
211
+ if (typeof code !== "number" || typeof message !== "string")
212
+ return undefined;
213
+ return { code, message, ...(data === undefined ? {} : { data }) };
214
+ }
192
215
  export class StreamableHttpTransport extends TransportEvents {
216
+ sendsHeaders = true;
193
217
  url;
194
218
  options;
195
219
  fetch;
@@ -198,6 +222,11 @@ export class StreamableHttpTransport extends TransportEvents {
198
222
  closed = false;
199
223
  sessionIdValue;
200
224
  protocolVersion;
225
+ /**
226
+ * MCP 2026-07-28: no session, `Mcp-Method` and `Mcp-Name` headers, response streams that cannot be
227
+ * resumed, and closing a request's response stream cancels it.
228
+ */
229
+ stateless = false;
201
230
  getStreamStarted = false;
202
231
  /** Access token of the latest request, which `close()` reuses instead of asking the auth provider. */
203
232
  lastToken;
@@ -222,14 +251,36 @@ export class StreamableHttpTransport extends TransportEvents {
222
251
  }
223
252
  setProtocolVersion(version) {
224
253
  this.protocolVersion = version;
254
+ this.stateless = version === STATELESS_PROTOCOL_VERSION;
255
+ // A server that answered `initialize` with the stateless revision may have started a session.
256
+ if (this.stateless)
257
+ this.sessionIdValue = undefined;
225
258
  }
226
- async send(message, { signal } = {}) {
259
+ async send(message, { signal, headers } = {}) {
227
260
  if (!this.started || this.closed)
228
261
  throw new McpConnectionClosedError();
262
+ const statelessRequest = this.stateless && isJsonRpcRequest(message);
263
+ // Aborting the request's response stream already cancelled it.
264
+ if (this.stateless && isJsonRpcNotification(message) && message.method === "notifications/cancelled")
265
+ return;
229
266
  const response = await this.authorizedFetch("POST", {
230
- headers: { accept: "application/json, text/event-stream", "content-type": "application/json" },
267
+ headers: {
268
+ accept: "application/json, text/event-stream",
269
+ "content-type": "application/json",
270
+ ...(statelessRequest ? { ...headers, ...standardRequestHeaders(message.method, message.params) } : {}),
271
+ },
231
272
  body: JSON.stringify(message),
273
+ // Closing the connection cancels a stateless request, also before its response arrives.
274
+ ...(statelessRequest && signal ? { signal } : {}),
232
275
  }, signal);
276
+ if (statelessRequest && response.status >= 400 && response.status < 500 && response.status !== 401) {
277
+ const body = (await readBodyText(response, MAX_ERROR_BODY_BYTES).catch(() => ({ text: "" }))).text;
278
+ const error = jsonRpcErrorIn(body);
279
+ if (!error)
280
+ throw new McpHttpError(response.status, describeHttpFailure(response.status, body), body);
281
+ this.emitMessage({ jsonrpc: "2.0", id: message.id, error });
282
+ return;
283
+ }
233
284
  await this.checkResponse(response);
234
285
  this.captureSession(response);
235
286
  if (!isJsonRpcRequest(message)) {
@@ -255,7 +306,7 @@ export class StreamableHttpTransport extends TransportEvents {
255
306
  return;
256
307
  }
257
308
  if (type === "text/event-stream" && response.body) {
258
- void this.consumeResponseStream(response.body, message.id);
309
+ void this.consumeResponseStream(response.body, message.id, signal);
259
310
  return;
260
311
  }
261
312
  await discard(response);
@@ -283,7 +334,8 @@ export class StreamableHttpTransport extends TransportEvents {
283
334
  }
284
335
  /**
285
336
  * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider
286
- * once, and the request is retried with whatever credentials it left behind.
337
+ * once, and the request is retried with whatever credentials it left behind. `init.signal` aborts
338
+ * the fetch itself.
287
339
  *
288
340
  * `signal` only stops dispatch: getting a token or the authorization recovery can take a while, and a
289
341
  * request its sender gave up on in the meantime must not reach the server. It does not abort the shared
@@ -291,6 +343,7 @@ export class StreamableHttpTransport extends TransportEvents {
291
343
  */
292
344
  async authorizedFetch(method, init, signal) {
293
345
  const onUnauthorized = this.options.authProvider?.onUnauthorized?.bind(this.options.authProvider);
346
+ const fetchSignal = init.signal ? AbortSignal.any([this.controller.signal, init.signal]) : this.controller.signal;
294
347
  for (let attempt = 0;; attempt++) {
295
348
  const { headers, token } = await this.headers(init.headers);
296
349
  if (signal?.aborted)
@@ -299,7 +352,7 @@ export class StreamableHttpTransport extends TransportEvents {
299
352
  method,
300
353
  headers,
301
354
  body: init.body,
302
- signal: this.controller.signal,
355
+ signal: fetchSignal,
303
356
  });
304
357
  if (attempt > 0 || !onUnauthorized || !needsAuthorization(response))
305
358
  return response;
@@ -330,7 +383,7 @@ export class StreamableHttpTransport extends TransportEvents {
330
383
  }
331
384
  captureSession(response) {
332
385
  const sessionId = response.headers.get("mcp-session-id");
333
- if (sessionId)
386
+ if (sessionId && !this.stateless)
334
387
  this.sessionIdValue = sessionId;
335
388
  }
336
389
  async checkResponse(response) {
@@ -374,9 +427,10 @@ export class StreamableHttpTransport extends TransportEvents {
374
427
  /**
375
428
  * Read the SSE stream answering one request. When the stream ends or breaks before the response
376
429
  * arrives and the server assigned event IDs, resume it with GET and `Last-Event-ID`, as the
377
- * server may close response streams at will. Otherwise only this request fails.
430
+ * server may close response streams at will. Otherwise, and always on the stateless revision,
431
+ * only this request fails.
378
432
  */
379
- async consumeResponseStream(body, requestId) {
433
+ async consumeResponseStream(body, requestId, signal) {
380
434
  const cursor = { lastEventId: undefined, retryMs: undefined, received: false };
381
435
  let answered = false;
382
436
  const onMessage = (message) => {
@@ -395,11 +449,12 @@ export class StreamableHttpTransport extends TransportEvents {
395
449
  failure = error;
396
450
  }
397
451
  }
398
- if (answered || this.closed)
452
+ // An aborted `signal`: the request settled without this stream (timed out, cancelled).
453
+ if (answered || this.closed || signal?.aborted)
399
454
  return;
400
455
  if (failure !== undefined && !this.isRetryable(failure))
401
456
  break;
402
- if (cursor.lastEventId === undefined || attempt >= this.maxRetries())
457
+ if (this.stateless || cursor.lastEventId === undefined || attempt >= this.maxRetries())
403
458
  break;
404
459
  if (cursor.received)
405
460
  attempt = 0;