@bastani/atomic 0.9.35-alpha.2 → 0.9.35-alpha.3

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 (172) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/package.json +1 -1
  5. package/dist/builtin/web-access/package.json +1 -1
  6. package/dist/builtin/workflows/CHANGELOG.md +13 -0
  7. package/dist/builtin/workflows/builtin/{chunk-s7y3hw0n.js → chunk-3xffzzbg.js} +1 -1
  8. package/dist/builtin/workflows/builtin/{chunk-0d0pd4fz.js → chunk-7fvrnzhb.js} +1 -1
  9. package/dist/builtin/workflows/builtin/{chunk-119gt64q.js → chunk-8c3ae7tt.js} +8 -1
  10. package/dist/builtin/workflows/builtin/{chunk-y68758re.js → chunk-rhkg3d8e.js} +1 -1
  11. package/dist/builtin/workflows/builtin/goal.js +2 -2
  12. package/dist/builtin/workflows/builtin/index.js +3 -3
  13. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  14. package/dist/builtin/workflows/package.json +1 -1
  15. package/dist/builtin/workflows/src/extension/index.bundle.mjs +510 -35
  16. package/dist/builtin/workflows/src/index.js +87 -29
  17. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  18. package/dist/core/agent-session-accessors.js +7 -1
  19. package/dist/core/agent-session-accessors.js.map +1 -1
  20. package/dist/core/agent-session-custom-message-commit.js +15 -15
  21. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  22. package/dist/core/agent-session-events.d.ts.map +1 -1
  23. package/dist/core/agent-session-events.js +4 -0
  24. package/dist/core/agent-session-events.js.map +1 -1
  25. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  26. package/dist/core/agent-session-extension-bindings.js +61 -1
  27. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  28. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  29. package/dist/core/agent-session-message-queue.js +3 -1
  30. package/dist/core/agent-session-message-queue.js.map +1 -1
  31. package/dist/core/agent-session-methods.d.ts +5 -3
  32. package/dist/core/agent-session-methods.d.ts.map +1 -1
  33. package/dist/core/agent-session-methods.js.map +1 -1
  34. package/dist/core/agent-session-persistent-custom-messages.js +1 -1
  35. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
  36. package/dist/core/agent-session-prompt.d.ts +3 -1
  37. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  38. package/dist/core/agent-session-prompt.js +79 -9
  39. package/dist/core/agent-session-prompt.js.map +1 -1
  40. package/dist/core/agent-session-summary.d.ts.map +1 -1
  41. package/dist/core/agent-session-summary.js +17 -2
  42. package/dist/core/agent-session-summary.js.map +1 -1
  43. package/dist/core/agent-session-tree.js +1 -1
  44. package/dist/core/agent-session-tree.js.map +1 -1
  45. package/dist/core/agent-session.d.ts +1 -0
  46. package/dist/core/agent-session.d.ts.map +1 -1
  47. package/dist/core/agent-session.js +1 -0
  48. package/dist/core/agent-session.js.map +1 -1
  49. package/dist/core/auth-storage-backends.d.ts +1 -0
  50. package/dist/core/auth-storage-backends.d.ts.map +1 -1
  51. package/dist/core/auth-storage-backends.js +37 -23
  52. package/dist/core/auth-storage-backends.js.map +1 -1
  53. package/dist/core/compaction/session-summarization.d.ts +1 -0
  54. package/dist/core/compaction/session-summarization.d.ts.map +1 -1
  55. package/dist/core/compaction/session-summarization.js +7 -1
  56. package/dist/core/compaction/session-summarization.js.map +1 -1
  57. package/dist/core/extensions/agent-events.d.ts +15 -7
  58. package/dist/core/extensions/agent-events.d.ts.map +1 -1
  59. package/dist/core/extensions/agent-events.js.map +1 -1
  60. package/dist/core/extensions/context-types.d.ts +6 -0
  61. package/dist/core/extensions/context-types.d.ts.map +1 -1
  62. package/dist/core/extensions/context-types.js.map +1 -1
  63. package/dist/core/extensions/index.d.ts +1 -1
  64. package/dist/core/extensions/index.d.ts.map +1 -1
  65. package/dist/core/extensions/index.js.map +1 -1
  66. package/dist/core/extensions/runner-context.d.ts +4 -0
  67. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  68. package/dist/core/extensions/runner-context.js +8 -0
  69. package/dist/core/extensions/runner-context.js.map +1 -1
  70. package/dist/core/extensions/runner-events.d.ts +1 -1
  71. package/dist/core/extensions/runner-events.d.ts.map +1 -1
  72. package/dist/core/extensions/runner-events.js +4 -3
  73. package/dist/core/extensions/runner-events.js.map +1 -1
  74. package/dist/core/extensions/runner.d.ts +3 -1
  75. package/dist/core/extensions/runner.d.ts.map +1 -1
  76. package/dist/core/extensions/runner.js +8 -2
  77. package/dist/core/extensions/runner.js.map +1 -1
  78. package/dist/core/extensions/runtime-types.d.ts +4 -0
  79. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  80. package/dist/core/extensions/runtime-types.js.map +1 -1
  81. package/dist/core/extensions/workflow-run-control.d.ts +12 -2
  82. package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
  83. package/dist/core/extensions/workflow-run-control.js.map +1 -1
  84. package/dist/core/package-manager-resource-patterns.d.ts.map +1 -1
  85. package/dist/core/package-manager-resource-patterns.js +4 -2
  86. package/dist/core/package-manager-resource-patterns.js.map +1 -1
  87. package/dist/core/session-manager-archive.d.ts +2 -0
  88. package/dist/core/session-manager-archive.d.ts.map +1 -1
  89. package/dist/core/session-manager-archive.js +41 -19
  90. package/dist/core/session-manager-archive.js.map +1 -1
  91. package/dist/core/session-manager-core.d.ts +1 -0
  92. package/dist/core/session-manager-core.d.ts.map +1 -1
  93. package/dist/core/session-manager-core.js +8 -4
  94. package/dist/core/session-manager-core.js.map +1 -1
  95. package/dist/core/session-manager-list.d.ts.map +1 -1
  96. package/dist/core/session-manager-list.js +4 -10
  97. package/dist/core/session-manager-list.js.map +1 -1
  98. package/dist/core/session-manager-types.d.ts +2 -1
  99. package/dist/core/session-manager-types.d.ts.map +1 -1
  100. package/dist/core/session-manager-types.js.map +1 -1
  101. package/dist/core/session-manager.d.ts +1 -1
  102. package/dist/core/session-manager.d.ts.map +1 -1
  103. package/dist/core/session-manager.js.map +1 -1
  104. package/dist/core/workflow-summary-lifecycle.d.ts +4 -0
  105. package/dist/core/workflow-summary-lifecycle.d.ts.map +1 -0
  106. package/dist/core/workflow-summary-lifecycle.js +40 -0
  107. package/dist/core/workflow-summary-lifecycle.js.map +1 -0
  108. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  109. package/dist/extensions/codemode/execute.js +20 -6
  110. package/dist/extensions/codemode/execute.js.map +1 -1
  111. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  112. package/dist/extensions/mcp/cli.js +4 -7
  113. package/dist/extensions/mcp/cli.js.map +1 -1
  114. package/dist/extensions/mcp/client/client.d.ts.map +1 -1
  115. package/dist/extensions/mcp/client/client.js +5 -4
  116. package/dist/extensions/mcp/client/client.js.map +1 -1
  117. package/dist/extensions/mcp/client/index.d.ts +2 -2
  118. package/dist/extensions/mcp/client/index.d.ts.map +1 -1
  119. package/dist/extensions/mcp/client/index.js.map +1 -1
  120. package/dist/extensions/mcp/client/protocol/content.d.ts +4 -1
  121. package/dist/extensions/mcp/client/protocol/content.d.ts.map +1 -1
  122. package/dist/extensions/mcp/client/protocol/content.js.map +1 -1
  123. package/dist/extensions/mcp/client/transports/streamable-http.d.ts +2 -2
  124. package/dist/extensions/mcp/client/transports/streamable-http.d.ts.map +1 -1
  125. package/dist/extensions/mcp/client/transports/streamable-http.js +7 -5
  126. package/dist/extensions/mcp/client/transports/streamable-http.js.map +1 -1
  127. package/dist/extensions/mcp/client/transports/transport.d.ts +4 -1
  128. package/dist/extensions/mcp/client/transports/transport.d.ts.map +1 -1
  129. package/dist/extensions/mcp/client/transports/transport.js.map +1 -1
  130. package/dist/extensions/mcp/index.d.ts.map +1 -1
  131. package/dist/extensions/mcp/index.js +2 -4
  132. package/dist/extensions/mcp/index.js.map +1 -1
  133. package/dist/extensions/mcp/runtime.d.ts +1 -8
  134. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  135. package/dist/extensions/mcp/runtime.js +2 -41
  136. package/dist/extensions/mcp/runtime.js.map +1 -1
  137. package/dist/extensions/mcp/tools.js +1 -1
  138. package/dist/extensions/mcp/tools.js.map +1 -1
  139. package/dist/index-extensions.d.ts +1 -1
  140. package/dist/index-extensions.d.ts.map +1 -1
  141. package/dist/index-extensions.js.map +1 -1
  142. package/dist/index.d.ts +1 -1
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js.map +1 -1
  145. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  146. package/dist/modes/interactive/components/session-selector-list.js +2 -1
  147. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  148. package/dist/modes/print-mode.d.ts.map +1 -1
  149. package/dist/modes/print-mode.js +5 -0
  150. package/dist/modes/print-mode.js.map +1 -1
  151. package/dist/modes/rpc/rpc-client-api.d.ts +7 -2
  152. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  153. package/dist/modes/rpc/rpc-client-api.js +13 -0
  154. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  155. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  156. package/dist/modes/rpc/rpc-command-handler.js +19 -0
  157. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  158. package/dist/modes/rpc/rpc-types.d.ts +50 -1
  159. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  160. package/dist/modes/rpc/rpc-types.js.map +1 -1
  161. package/docs/extensions/authoring.md +2 -0
  162. package/docs/extensions/events.md +9 -3
  163. package/docs/guides/non-interactive.md +2 -0
  164. package/docs/mcp-servers.md +2 -0
  165. package/docs/packages/reference.md +2 -0
  166. package/docs/rpc/protocol.md +15 -0
  167. package/docs/rpc.md +1 -0
  168. package/docs/sdk.md +9 -1
  169. package/docs/sessions.md +2 -2
  170. package/docs/workflows/operations.md +11 -3
  171. package/npm-shrinkwrap.json +32 -32
  172. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","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Aa,CAAC,CAAC;YAC/B,CAAC;QACF,CAAC;IACF,CAAC;IAEO,SAAS,CAAC,KAAc;QAC/B,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc;YAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClE,CAAC;IAEO,yBAAyB;QAChC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,CAAC;IAC3D,CAAC;CACD","sourcesContent":["import type { CallToolResult } from \"./protocol/content.js\";\nimport {\n\tisJsonRpcId,\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tisObject,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\ttoError,\n} from \"./protocol/jsonrpc.js\";\nimport {\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n} from \"./protocol/types.js\";\nimport type { McpTransport } from \"./transports/transport.js\";\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst MAX_LIST_PAGES = 1_000;\n\ntype ClientState = \"idle\" | \"connecting\" | \"connected\" | \"closed\";\ntype NotificationListener = (params: unknown) => void;\ntype ErrorListener = (error: Error) => void;\ntype CloseListener = () => void;\ntype RequestHandler = (params: unknown, context: { signal: AbortSignal }) => unknown | Promise<unknown>;\n\nexport interface McpClientOptions extends Implementation {\n\tcapabilities?: ClientCapabilities;\n\tprotocolVersion?: SupportedProtocolVersion;\n\trequestTimeoutMs?: number;\n\troots?: readonly Root[] | (() => readonly Root[] | Promise<readonly Root[]>);\n}\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tonProgress?: (progress: ProgressNotification) => void;\n}\n\ninterface PendingRequest {\n\tresolve: (value: unknown) => void;\n\treject: (reason: unknown) => void;\n\ttimeoutMs: number;\n\ttimer: ReturnType<typeof setTimeout> | undefined;\n\tsignal: AbortSignal | undefined;\n\tonAbort: () => void;\n\tcancellable: boolean;\n\tonProgress: ((progress: ProgressNotification) => void) | undefined;\n\tprogressToken: JsonRpcId | undefined;\n}\n\nfunction validateInitializeResult(value: unknown): InitializeResult {\n\tif (\n\t\t!isObject(value) ||\n\t\ttypeof value.protocolVersion !== \"string\" ||\n\t\t!isObject(value.capabilities) ||\n\t\t!isObject(value.serverInfo) ||\n\t\ttypeof value.serverInfo.name !== \"string\" ||\n\t\ttypeof value.serverInfo.version !== \"string\" ||\n\t\t(value.instructions !== undefined && typeof value.instructions !== \"string\")\n\t) {\n\t\tthrow new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Invalid MCP initialize result\");\n\t}\n\treturn value as unknown as InitializeResult;\n}\n\nfunction invalid(message: string): McpError {\n\treturn new McpError(JSON_RPC_ERROR_CODES.invalidRequest, message);\n}\n\n/** One page of a paginated list: the items under `key`, each checked by `isItem`. */\nfunction validateListPage(\n\tmethod: string,\n\tkey: string,\n\tvalue: unknown,\n\tisItem: (item: Record<string, unknown>) => boolean,\n): { items: Record<string, unknown>[]; nextCursor?: string } {\n\tconst items = isObject(value) ? value[key] : undefined;\n\tif (!isObject(value) || !Array.isArray(items)) throw invalid(`Invalid MCP ${method} result`);\n\tfor (const item of items) {\n\t\tif (!isObject(item) || !isItem(item)) throw invalid(`Invalid entry in MCP ${method} result`);\n\t}\n\t// Some servers end pagination with `null` or `\"\"` instead of omitting the cursor.\n\tconst nextCursor = value.nextCursor === null || value.nextCursor === \"\" ? undefined : value.nextCursor;\n\tif (nextCursor !== undefined && typeof nextCursor !== \"string\") throw invalid(`Invalid MCP ${method} cursor`);\n\treturn { items, ...(nextCursor === undefined ? {} : { nextCursor }) };\n}\n\nconst isTool = (tool: Record<string, unknown>) => typeof tool.name === \"string\" && isObject(tool.inputSchema);\n// `name` is required by the spec, but some servers omit it; the URI stands in.\nconst isResource = (resource: Record<string, unknown>) =>\n\ttypeof resource.uri === \"string\" && (resource.name === undefined || typeof resource.name === \"string\");\nconst isResourceTemplate = (template: Record<string, unknown>) =>\n\ttypeof template.uriTemplate === \"string\" && (template.name === undefined || typeof template.name === \"string\");\n\nfunction toResource(item: Record<string, unknown>): Resource {\n\treturn { ...item, name: item.name ?? item.uri } as Resource;\n}\n\nfunction toResourceTemplate(item: Record<string, unknown>): ResourceTemplate {\n\treturn { ...item, name: item.name ?? item.uriTemplate } as ResourceTemplate;\n}\n\nfunction pageCursor(page: { nextCursor?: string }): { nextCursor?: string } {\n\treturn page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor };\n}\n\nfunction validateReadResourceResult(value: unknown): ReadResourceResult {\n\tif (!isObject(value) || !Array.isArray(value.contents)) throw invalid(\"Invalid MCP resources/read result\");\n\tfor (const contents of value.contents) {\n\t\tif (\n\t\t\t!isObject(contents) ||\n\t\t\ttypeof contents.uri !== \"string\" ||\n\t\t\t(typeof contents.text !== \"string\" && typeof contents.blob !== \"string\")\n\t\t) {\n\t\t\tthrow invalid(\"Invalid contents in MCP resources/read result\");\n\t\t}\n\t}\n\treturn value as unknown as ReadResourceResult;\n}\n\n/** `content` is required by the spec, but servers that only return `structuredContent` omit it (the SDK defaults it too). */\nfunction validateCallToolResult(value: unknown): CallToolResult {\n\tif (!isObject(value) || (value.content !== undefined && !Array.isArray(value.content))) {\n\t\tthrow new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Invalid MCP tools/call result\");\n\t}\n\tif (value.structuredContent !== undefined && !isObject(value.structuredContent)) {\n\t\tthrow new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Invalid MCP tools/call structured content\");\n\t}\n\treturn (value.content === undefined ? { ...value, content: [] } : value) as unknown as CallToolResult;\n}\n\nexport class McpClient {\n\treadonly options: Readonly<McpClientOptions>;\n\tprivate state: ClientState = \"idle\";\n\tprivate transport: McpTransport | undefined;\n\tprivate nextRequestId = 1;\n\tprivate serverInfoValue: Implementation | undefined;\n\tprivate serverCapabilitiesValue: ServerCapabilities | undefined;\n\tprivate instructionsValue: string | undefined;\n\tprivate protocolVersionValue: string | undefined;\n\tprivate pending = new Map<JsonRpcId, PendingRequest>();\n\tprivate progressRequests = new Map<JsonRpcId, JsonRpcId>();\n\tprivate incoming = new Map<JsonRpcId, AbortController>();\n\tprivate requestHandlers = new Map<string, RequestHandler>();\n\tprivate notificationListeners = new Map<string, Set<NotificationListener>>();\n\tprivate errorListeners = new Set<ErrorListener>();\n\tprivate closeListeners = new Set<CloseListener>();\n\tprivate disposers: (() => void)[] = [];\n\n\tconstructor(options: McpClientOptions) {\n\t\tthis.options = Object.freeze({ ...options });\n\t\tthis.requestHandlers.set(\"ping\", () => ({}));\n\t\tconst roots = options.roots;\n\t\tif (roots) {\n\t\t\tthis.requestHandlers.set(\"roots/list\", async () => ({\n\t\t\t\troots: [...(typeof roots === \"function\" ? await roots() : roots)],\n\t\t\t}));\n\t\t}\n\t}\n\n\tget connectionState(): ClientState {\n\t\treturn this.state;\n\t}\n\n\tget serverInfo(): Implementation | undefined {\n\t\treturn this.serverInfoValue;\n\t}\n\n\tget serverCapabilities(): ServerCapabilities | undefined {\n\t\treturn this.serverCapabilitiesValue;\n\t}\n\n\tget instructions(): string | undefined {\n\t\treturn this.instructionsValue;\n\t}\n\n\tget protocolVersion(): string | undefined {\n\t\treturn this.protocolVersionValue;\n\t}\n\n\tasync connect(transport: McpTransport): Promise<InitializeResult> {\n\t\tif (this.state !== \"idle\") throw new Error(`Cannot connect MCP client in ${this.state} state`);\n\t\tthis.state = \"connecting\";\n\t\tthis.transport = transport;\n\t\tthis.disposers = [\n\t\t\ttransport.onMessage((message) => this.handleMessage(message)),\n\t\t\t// Transport errors are reported only. Pending requests fail when the transport closes.\n\t\t\ttransport.onError((error) => this.emitError(error)),\n\t\t\ttransport.onClose(() => this.handleTransportClose()),\n\t\t];\n\n\t\ttry {\n\t\t\tawait transport.start();\n\t\t\tconst capabilities: ClientCapabilities = { ...this.options.capabilities };\n\t\t\tif (this.options.roots && capabilities.roots === undefined) capabilities.roots = {};\n\t\t\tconst result = validateInitializeResult(\n\t\t\t\tawait this.requestInternal(\n\t\t\t\t\t\"initialize\",\n\t\t\t\t\t{\n\t\t\t\t\t\tprotocolVersion: this.options.protocolVersion ?? LATEST_PROTOCOL_VERSION,\n\t\t\t\t\t\tcapabilities,\n\t\t\t\t\t\tclientInfo: {\n\t\t\t\t\t\t\tname: this.options.name,\n\t\t\t\t\t\t\tversion: this.options.version,\n\t\t\t\t\t\t\t...(this.options.title === undefined ? {} : { title: this.options.title }),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (!(SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(result.protocolVersion)) {\n\t\t\t\tthrow new Error(`MCP server selected unsupported protocol version ${result.protocolVersion}`);\n\t\t\t}\n\t\t\tthis.protocolVersionValue = result.protocolVersion;\n\t\t\tthis.serverInfoValue = result.serverInfo;\n\t\t\tthis.serverCapabilitiesValue = result.capabilities;\n\t\t\tthis.instructionsValue = result.instructions;\n\t\t\ttransport.setProtocolVersion?.(result.protocolVersion);\n\t\t\tawait this.notifyInternal(\"notifications/initialized\", undefined, true);\n\t\t\tthis.state = \"connected\";\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tawait this.close().catch(() => {});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\trequest<Result = unknown>(\n\t\tmethod: string,\n\t\tparams?: Record<string, unknown>,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<Result> {\n\t\treturn this.requestInternal(method, params, options, false) as Promise<Result>;\n\t}\n\n\tnotify(method: string, params?: Record<string, unknown>): Promise<void> {\n\t\treturn this.notifyInternal(method, params, false);\n\t}\n\n\tsetRequestHandler(method: string, handler: RequestHandler): () => void {\n\t\tthis.requestHandlers.set(method, handler);\n\t\treturn () => {\n\t\t\tif (this.requestHandlers.get(method) === handler) this.requestHandlers.delete(method);\n\t\t};\n\t}\n\n\tonNotification(method: string, listener: NotificationListener): () => void {\n\t\tconst listeners = this.notificationListeners.get(method) ?? new Set<NotificationListener>();\n\t\tthis.notificationListeners.set(method, listeners);\n\t\tlisteners.add(listener);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.notificationListeners.delete(method);\n\t\t};\n\t}\n\n\tonError(listener: ErrorListener): () => void {\n\t\tthis.errorListeners.add(listener);\n\t\treturn () => this.errorListeners.delete(listener);\n\t}\n\n\t/** Called once when the connection closes, whether the transport dropped or `close()` was called. */\n\tonClose(listener: CloseListener): () => void {\n\t\tthis.closeListeners.add(listener);\n\t\treturn () => this.closeListeners.delete(listener);\n\t}\n\n\tasync ping(options: McpRequestOptions = {}): Promise<void> {\n\t\tawait this.request(\"ping\", undefined, options);\n\t}\n\n\tasync listTools(options: McpRequestOptions = {}): Promise<Tool[]> {\n\t\treturn (await this.listAll(\"tools/list\", \"tools\", isTool, options)) as unknown as Tool[];\n\t}\n\n\t/** Every resource, following `nextCursor` through all pages. */\n\tasync listResources(options: McpRequestOptions = {}): Promise<Resource[]> {\n\t\treturn (await this.listAll(\"resources/list\", \"resources\", isResource, options)).map(toResource);\n\t}\n\n\t/** One page of resources, starting at `cursor`. */\n\tasync listResourcesPage(cursor?: string, options: McpRequestOptions = {}): Promise<ListResourcesResult> {\n\t\tconst page = await this.listPage(\"resources/list\", \"resources\", isResource, cursor, options);\n\t\treturn { resources: page.items.map(toResource), ...pageCursor(page) };\n\t}\n\n\t/** Every resource template, following `nextCursor` through all pages. */\n\tasync listResourceTemplates(options: McpRequestOptions = {}): Promise<ResourceTemplate[]> {\n\t\tconst templates = await this.listAll(\n\t\t\t\"resources/templates/list\",\n\t\t\t\"resourceTemplates\",\n\t\t\tisResourceTemplate,\n\t\t\toptions,\n\t\t);\n\t\treturn templates.map(toResourceTemplate);\n\t}\n\n\t/** One page of resource templates, starting at `cursor`. */\n\tasync listResourceTemplatesPage(\n\t\tcursor?: string,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<ListResourceTemplatesResult> {\n\t\tconst page = await this.listPage(\n\t\t\t\"resources/templates/list\",\n\t\t\t\"resourceTemplates\",\n\t\t\tisResourceTemplate,\n\t\t\tcursor,\n\t\t\toptions,\n\t\t);\n\t\treturn { resourceTemplates: page.items.map(toResourceTemplate), ...pageCursor(page) };\n\t}\n\n\tasync readResource(uri: string, options: McpRequestOptions = {}): Promise<ReadResourceResult> {\n\t\treturn validateReadResourceResult(await this.request(\"resources/read\", { uri }, options));\n\t}\n\n\tprivate async listPage(\n\t\tmethod: string,\n\t\tkey: string,\n\t\tisItem: (item: Record<string, unknown>) => boolean,\n\t\tcursor: string | undefined,\n\t\toptions: McpRequestOptions,\n\t): Promise<{ items: Record<string, unknown>[]; nextCursor?: string }> {\n\t\treturn validateListPage(\n\t\t\tmethod,\n\t\t\tkey,\n\t\t\tawait this.request(method, cursor === undefined ? undefined : { cursor }, options),\n\t\t\tisItem,\n\t\t);\n\t}\n\n\t/** Every item of a paginated list method. */\n\tprivate async listAll(\n\t\tmethod: string,\n\t\tkey: string,\n\t\tisItem: (item: Record<string, unknown>) => boolean,\n\t\toptions: McpRequestOptions,\n\t): Promise<Record<string, unknown>[]> {\n\t\tconst items: Record<string, unknown>[] = [];\n\t\tconst cursors = new Set<string>();\n\t\tlet cursor: string | undefined;\n\t\tfor (let pageNumber = 0; pageNumber < MAX_LIST_PAGES; pageNumber++) {\n\t\t\tconst page = await this.listPage(method, key, isItem, cursor, options);\n\t\t\titems.push(...page.items);\n\t\t\tif (page.nextCursor === undefined) return items;\n\t\t\tif (cursors.has(page.nextCursor))\n\t\t\t\tthrow new Error(`MCP ${method} returned duplicate cursor: ${page.nextCursor}`);\n\t\t\tcursors.add(page.nextCursor);\n\t\t\tcursor = page.nextCursor;\n\t\t}\n\t\tthrow new Error(`MCP ${method} exceeded ${MAX_LIST_PAGES} pages`);\n\t}\n\n\tasync callTool(\n\t\tname: string,\n\t\targs?: Record<string, unknown>,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<CallToolResult> {\n\t\treturn validateCallToolResult(\n\t\t\tawait this.request(\"tools/call\", { name, ...(args === undefined ? {} : { arguments: args }) }, options),\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst transport = this.transport;\n\t\tthis.transport = undefined;\n\t\tthis.disposeTransportListeners();\n\t\tthis.markClosed(new McpConnectionClosedError());\n\t\tawait transport?.close();\n\t}\n\n\tprivate async requestInternal(\n\t\tmethod: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\toptions: McpRequestOptions,\n\t\tallowConnecting: boolean,\n\t): Promise<unknown> {\n\t\tconst transport = this.requireTransport(allowConnecting);\n\t\tif (options.signal?.aborted) throw new McpAbortError();\n\t\tconst id = this.nextRequestId++;\n\t\tconst progressToken = options.onProgress ? id : undefined;\n\t\tconst requestParams =\n\t\t\tprogressToken === undefined\n\t\t\t\t? params\n\t\t\t\t: { ...params, _meta: { ...(isObject(params?._meta) ? params._meta : {}), progressToken } };\n\t\tconst message: JsonRpcRequest = {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tmethod,\n\t\t\t...(requestParams === undefined ? {} : { params: requestParams }),\n\t\t};\n\t\treturn new Promise<unknown>((resolve, reject) => {\n\t\t\tconst entry: PendingRequest = {\n\t\t\t\tresolve,\n\t\t\t\treject,\n\t\t\t\ttimeoutMs: options.timeoutMs ?? this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,\n\t\t\t\ttimer: undefined,\n\t\t\t\tsignal: options.signal,\n\t\t\t\t// The spec forbids cancelling `initialize`.\n\t\t\t\tonAbort: () =>\n\t\t\t\t\tthis.cancelPending(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tnew McpAbortError(),\n\t\t\t\t\t\tmethod !== \"initialize\",\n\t\t\t\t\t\tString(options.signal?.reason ?? \"Aborted\"),\n\t\t\t\t\t),\n\t\t\t\tcancellable: method !== \"initialize\",\n\t\t\t\tonProgress: options.onProgress,\n\t\t\t\tprogressToken,\n\t\t\t};\n\t\t\tthis.pending.set(id, entry);\n\t\t\tif (progressToken !== undefined) this.progressRequests.set(progressToken, id);\n\t\t\toptions.signal?.addEventListener(\"abort\", entry.onAbort, { once: true });\n\t\t\tthis.armTimeout(id, entry);\n\t\t\ttransport.send(message).catch((error) => this.cancelPending(id, error, false));\n\t\t});\n\t}\n\n\tprivate async notifyInternal(\n\t\tmethod: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\tallowConnecting: boolean,\n\t): Promise<void> {\n\t\tawait this.requireTransport(allowConnecting).send({\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tmethod,\n\t\t\t...(params === undefined ? {} : { params }),\n\t\t});\n\t}\n\n\tprivate requireTransport(allowConnecting: boolean): McpTransport {\n\t\tif (this.transport && (this.state === \"connected\" || (allowConnecting && this.state === \"connecting\"))) {\n\t\t\treturn this.transport;\n\t\t}\n\t\tthrow new McpConnectionClosedError(`MCP client is ${this.state}`);\n\t}\n\n\tprivate handleMessage(message: JsonRpcMessage): void {\n\t\tif (isJsonRpcResponse(message)) {\n\t\t\tthis.handleResponse(message);\n\t\t\treturn;\n\t\t}\n\t\tif (isJsonRpcRequest(message)) {\n\t\t\tvoid this.handleRequest(message);\n\t\t\treturn;\n\t\t}\n\t\tif (isJsonRpcNotification(message)) {\n\t\t\tthis.handleNotification(message.method, message.params);\n\t\t\treturn;\n\t\t}\n\t\tthis.emitError(new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Received invalid JSON-RPC message\"));\n\t}\n\n\tprivate handleResponse(message: JsonRpcResponse): void {\n\t\tconst entry = this.pending.get(message.id);\n\t\tif (!entry) {\n\t\t\tthis.emitError(new Error(`Received response for unknown MCP request ${String(message.id)}`));\n\t\t\treturn;\n\t\t}\n\t\tthis.removePending(message.id, entry);\n\t\tif (\"error\" in message) entry.reject(new McpError(message.error.code, message.error.message, message.error.data));\n\t\telse entry.resolve(message.result);\n\t}\n\n\tprivate async handleRequest(message: JsonRpcRequest): Promise<void> {\n\t\tconst transport = this.transport;\n\t\tif (!transport) return;\n\t\tconst handler = this.requestHandlers.get(message.method);\n\t\tif (!handler) {\n\t\t\tawait transport\n\t\t\t\t.send({\n\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\tid: message.id,\n\t\t\t\t\terror: { code: JSON_RPC_ERROR_CODES.methodNotFound, message: `Method not found: ${message.method}` },\n\t\t\t\t})\n\t\t\t\t.catch((error) => this.emitError(error));\n\t\t\treturn;\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tthis.incoming.set(message.id, controller);\n\t\ttry {\n\t\t\tconst result = await handler(message.params, { signal: controller.signal });\n\t\t\tawait transport.send({ jsonrpc: \"2.0\", id: message.id, result: result ?? {} });\n\t\t} catch (error) {\n\t\t\tconst responseError =\n\t\t\t\terror instanceof McpError\n\t\t\t\t\t? { code: error.code, message: error.message, data: error.data }\n\t\t\t\t\t: { code: JSON_RPC_ERROR_CODES.internalError, message: toError(error).message };\n\t\t\tawait transport\n\t\t\t\t.send({ jsonrpc: \"2.0\", id: message.id, error: responseError })\n\t\t\t\t.catch((sendError) => this.emitError(sendError));\n\t\t} finally {\n\t\t\tthis.incoming.delete(message.id);\n\t\t}\n\t}\n\n\tprivate handleNotification(method: string, params: unknown): void {\n\t\tif (method === \"notifications/progress\") this.handleProgress(params);\n\t\telse if (method === \"notifications/cancelled\") this.handleCancelled(params);\n\t\tfor (const listener of this.notificationListeners.get(method) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener(params);\n\t\t\t} catch (error) {\n\t\t\t\tthis.emitError(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleProgress(params: unknown): void {\n\t\tif (!isObject(params) || !isJsonRpcId(params.progressToken) || typeof params.progress !== \"number\") return;\n\t\tconst requestId = this.progressRequests.get(params.progressToken);\n\t\tconst entry = requestId === undefined ? undefined : this.pending.get(requestId);\n\t\tif (requestId === undefined || !entry) return;\n\t\tthis.armTimeout(requestId, entry);\n\t\ttry {\n\t\t\tentry.onProgress?.(params as unknown as ProgressNotification);\n\t\t} catch (error) {\n\t\t\tthis.emitError(error);\n\t\t}\n\t}\n\n\tprivate handleCancelled(params: unknown): void {\n\t\tif (isObject(params) && isJsonRpcId(params.requestId)) this.incoming.get(params.requestId)?.abort(params.reason);\n\t}\n\n\tprivate armTimeout(id: JsonRpcId, entry: PendingRequest): void {\n\t\tif (entry.timer) clearTimeout(entry.timer);\n\t\tif (!Number.isFinite(entry.timeoutMs) || entry.timeoutMs <= 0) return;\n\t\tentry.timer = setTimeout(() => {\n\t\t\tthis.cancelPending(id, new McpTimeoutError(entry.timeoutMs), entry.cancellable, \"Request timed out\");\n\t\t}, entry.timeoutMs);\n\t}\n\n\tprivate cancelPending(id: JsonRpcId, error: unknown, notifyServer: boolean, reason?: string): void {\n\t\tconst entry = this.pending.get(id);\n\t\tif (!entry) return;\n\t\tthis.removePending(id, entry);\n\t\tentry.reject(error);\n\t\tif (notifyServer && this.transport) {\n\t\t\tvoid this.transport\n\t\t\t\t.send({\n\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\tmethod: \"notifications/cancelled\",\n\t\t\t\t\tparams: { requestId: id, ...(reason ? { reason } : {}) },\n\t\t\t\t})\n\t\t\t\t.catch((sendError) => this.emitError(sendError));\n\t\t}\n\t}\n\n\tprivate removePending(id: JsonRpcId, entry: PendingRequest): void {\n\t\tthis.pending.delete(id);\n\t\tif (entry.timer) clearTimeout(entry.timer);\n\t\tif (entry.progressToken !== undefined) this.progressRequests.delete(entry.progressToken);\n\t\tentry.signal?.removeEventListener(\"abort\", entry.onAbort);\n\t}\n\n\tprivate rejectPending(error: unknown): void {\n\t\tfor (const [id, entry] of this.pending) {\n\t\t\tthis.removePending(id, entry);\n\t\t\tentry.reject(error);\n\t\t}\n\t}\n\n\tprivate handleTransportClose(): void {\n\t\tthis.markClosed(new McpConnectionClosedError());\n\t}\n\n\t/** Idempotent: rejects in-flight requests, aborts server requests we are serving, and flips the state. */\n\tprivate markClosed(error: Error): void {\n\t\tconst wasClosed = this.state === \"closed\";\n\t\tthis.state = \"closed\";\n\t\tthis.rejectPending(error);\n\t\tfor (const controller of this.incoming.values()) controller.abort(error);\n\t\tthis.incoming.clear();\n\t\tif (wasClosed) return;\n\t\tfor (const listener of [...this.closeListeners]) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch (listenerError) {\n\t\t\t\tthis.emitError(listenerError);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitError(error: unknown): void {\n\t\tconst normalized = toError(error);\n\t\tfor (const listener of this.errorListeners) listener(normalized);\n\t}\n\n\tprivate disposeTransportListeners(): void {\n\t\tfor (const dispose of this.disposers.splice(0)) dispose();\n\t}\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/extensions/mcp/client/client.ts"],"names":[],"mappings":"AACA,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,oBAAoB,EAKpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,OAAO,GACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIN,uBAAuB,EASvB,2BAA2B,GAG3B,MAAM,qBAAqB,CAAC;AAG7B,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM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nimport {\n\tisJsonRpcId,\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tisObject,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\ttoError,\n} from \"./protocol/jsonrpc.js\";\nimport {\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n} from \"./protocol/types.js\";\nimport type { McpTransport } from \"./transports/transport.js\";\n\nconst DEFAULT_REQUEST_TIMEOUT_MS = 30_000;\nconst MAX_LIST_PAGES = 1_000;\n\ntype ClientState = \"idle\" | \"connecting\" | \"connected\" | \"closed\";\ntype NotificationListener = (params: unknown) => void;\ntype ErrorListener = (error: Error) => void;\ntype CloseListener = () => void;\ntype RequestHandler = (params: unknown, context: { signal: AbortSignal }) => unknown | Promise<unknown>;\n\nexport interface McpClientOptions extends Implementation {\n\tcapabilities?: ClientCapabilities;\n\tprotocolVersion?: SupportedProtocolVersion;\n\trequestTimeoutMs?: number;\n\troots?: readonly Root[] | (() => readonly Root[] | Promise<readonly Root[]>);\n}\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tonProgress?: (progress: ProgressNotification) => void;\n}\n\ninterface PendingRequest {\n\tresolve: (value: unknown) => void;\n\treject: (reason: unknown) => void;\n\ttimeoutMs: number;\n\ttimer: ReturnType<typeof setTimeout> | undefined;\n\tsignal: AbortSignal | undefined;\n\tonAbort: () => void;\n\tsendController: AbortController;\n\tcancellable: boolean;\n\tonProgress: ((progress: ProgressNotification) => void) | undefined;\n\tprogressToken: JsonRpcId | undefined;\n}\n\nfunction validateInitializeResult(value: unknown): InitializeResult {\n\tif (\n\t\t!isObject(value) ||\n\t\ttypeof value.protocolVersion !== \"string\" ||\n\t\t!isObject(value.capabilities) ||\n\t\t!isObject(value.serverInfo) ||\n\t\ttypeof value.serverInfo.name !== \"string\" ||\n\t\ttypeof value.serverInfo.version !== \"string\" ||\n\t\t(value.instructions !== undefined && typeof value.instructions !== \"string\")\n\t) {\n\t\tthrow new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Invalid MCP initialize result\");\n\t}\n\treturn value as unknown as InitializeResult;\n}\n\nfunction invalid(message: string): McpError {\n\treturn new McpError(JSON_RPC_ERROR_CODES.invalidRequest, message);\n}\n\n/** One page of a paginated list: the items under `key`, each checked by `isItem`. */\nfunction validateListPage(\n\tmethod: string,\n\tkey: string,\n\tvalue: unknown,\n\tisItem: (item: Record<string, unknown>) => boolean,\n): { items: Record<string, unknown>[]; nextCursor?: string } {\n\tconst items = isObject(value) ? value[key] : undefined;\n\tif (!isObject(value) || !Array.isArray(items)) throw invalid(`Invalid MCP ${method} result`);\n\tfor (const item of items) {\n\t\tif (!isObject(item) || !isItem(item)) throw invalid(`Invalid entry in MCP ${method} result`);\n\t}\n\t// Some servers end pagination with `null` or `\"\"` instead of omitting the cursor.\n\tconst nextCursor = value.nextCursor === null || value.nextCursor === \"\" ? undefined : value.nextCursor;\n\tif (nextCursor !== undefined && typeof nextCursor !== \"string\") throw invalid(`Invalid MCP ${method} cursor`);\n\treturn { items, ...(nextCursor === undefined ? {} : { nextCursor }) };\n}\n\nconst isTool = (tool: Record<string, unknown>) => typeof tool.name === \"string\" && isObject(tool.inputSchema);\n// `name` is required by the spec, but some servers omit it; the URI stands in.\nconst isResource = (resource: Record<string, unknown>) =>\n\ttypeof resource.uri === \"string\" && (resource.name === undefined || typeof resource.name === \"string\");\nconst isResourceTemplate = (template: Record<string, unknown>) =>\n\ttypeof template.uriTemplate === \"string\" && (template.name === undefined || typeof template.name === \"string\");\n\nfunction toResource(item: Record<string, unknown>): Resource {\n\treturn { ...item, name: item.name ?? item.uri } as Resource;\n}\n\nfunction toResourceTemplate(item: Record<string, unknown>): ResourceTemplate {\n\treturn { ...item, name: item.name ?? item.uriTemplate } as ResourceTemplate;\n}\n\nfunction pageCursor(page: { nextCursor?: string }): { nextCursor?: string } {\n\treturn page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor };\n}\n\nfunction validateReadResourceResult(value: unknown): ReadResourceResult {\n\tif (!isObject(value) || !Array.isArray(value.contents)) throw invalid(\"Invalid MCP resources/read result\");\n\tfor (const contents of value.contents) {\n\t\tif (\n\t\t\t!isObject(contents) ||\n\t\t\ttypeof contents.uri !== \"string\" ||\n\t\t\t(typeof contents.text !== \"string\" && typeof contents.blob !== \"string\")\n\t\t) {\n\t\t\tthrow invalid(\"Invalid contents in MCP resources/read result\");\n\t\t}\n\t}\n\treturn value as unknown as ReadResourceResult;\n}\n\n/** `content` is required by the spec, but servers that only return `structuredContent` omit it (the SDK defaults it too). */\nfunction validateCallToolResult(value: unknown): CallToolResult {\n\tif (!isObject(value) || (value.content !== undefined && !Array.isArray(value.content))) {\n\t\tthrow new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Invalid MCP tools/call result\");\n\t}\n\treturn (value.content === undefined ? { ...value, content: [] } : value) as unknown as CallToolResult;\n}\n\nexport class McpClient {\n\treadonly options: Readonly<McpClientOptions>;\n\tprivate state: ClientState = \"idle\";\n\tprivate transport: McpTransport | undefined;\n\tprivate nextRequestId = 1;\n\tprivate serverInfoValue: Implementation | undefined;\n\tprivate serverCapabilitiesValue: ServerCapabilities | undefined;\n\tprivate instructionsValue: string | undefined;\n\tprivate protocolVersionValue: string | undefined;\n\tprivate pending = new Map<JsonRpcId, PendingRequest>();\n\tprivate progressRequests = new Map<JsonRpcId, JsonRpcId>();\n\tprivate incoming = new Map<JsonRpcId, AbortController>();\n\tprivate requestHandlers = new Map<string, RequestHandler>();\n\tprivate notificationListeners = new Map<string, Set<NotificationListener>>();\n\tprivate errorListeners = new Set<ErrorListener>();\n\tprivate closeListeners = new Set<CloseListener>();\n\tprivate disposers: (() => void)[] = [];\n\n\tconstructor(options: McpClientOptions) {\n\t\tthis.options = Object.freeze({ ...options });\n\t\tthis.requestHandlers.set(\"ping\", () => ({}));\n\t\tconst roots = options.roots;\n\t\tif (roots) {\n\t\t\tthis.requestHandlers.set(\"roots/list\", async () => ({\n\t\t\t\troots: [...(typeof roots === \"function\" ? await roots() : roots)],\n\t\t\t}));\n\t\t}\n\t}\n\n\tget connectionState(): ClientState {\n\t\treturn this.state;\n\t}\n\n\tget serverInfo(): Implementation | undefined {\n\t\treturn this.serverInfoValue;\n\t}\n\n\tget serverCapabilities(): ServerCapabilities | undefined {\n\t\treturn this.serverCapabilitiesValue;\n\t}\n\n\tget instructions(): string | undefined {\n\t\treturn this.instructionsValue;\n\t}\n\n\tget protocolVersion(): string | undefined {\n\t\treturn this.protocolVersionValue;\n\t}\n\n\tasync connect(transport: McpTransport): Promise<InitializeResult> {\n\t\tif (this.state !== \"idle\") throw new Error(`Cannot connect MCP client in ${this.state} state`);\n\t\tthis.state = \"connecting\";\n\t\tthis.transport = transport;\n\t\tthis.disposers = [\n\t\t\ttransport.onMessage((message) => this.handleMessage(message)),\n\t\t\t// Transport errors are reported only. Pending requests fail when the transport closes.\n\t\t\ttransport.onError((error) => this.emitError(error)),\n\t\t\ttransport.onClose(() => this.handleTransportClose()),\n\t\t];\n\n\t\ttry {\n\t\t\tawait transport.start();\n\t\t\tconst capabilities: ClientCapabilities = { ...this.options.capabilities };\n\t\t\tif (this.options.roots && capabilities.roots === undefined) capabilities.roots = {};\n\t\t\tconst result = validateInitializeResult(\n\t\t\t\tawait this.requestInternal(\n\t\t\t\t\t\"initialize\",\n\t\t\t\t\t{\n\t\t\t\t\t\tprotocolVersion: this.options.protocolVersion ?? LATEST_PROTOCOL_VERSION,\n\t\t\t\t\t\tcapabilities,\n\t\t\t\t\t\tclientInfo: {\n\t\t\t\t\t\t\tname: this.options.name,\n\t\t\t\t\t\t\tversion: this.options.version,\n\t\t\t\t\t\t\t...(this.options.title === undefined ? {} : { title: this.options.title }),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{},\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (!(SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(result.protocolVersion)) {\n\t\t\t\tthrow new Error(`MCP server selected unsupported protocol version ${result.protocolVersion}`);\n\t\t\t}\n\t\t\tthis.protocolVersionValue = result.protocolVersion;\n\t\t\tthis.serverInfoValue = result.serverInfo;\n\t\t\tthis.serverCapabilitiesValue = result.capabilities;\n\t\t\tthis.instructionsValue = result.instructions;\n\t\t\ttransport.setProtocolVersion?.(result.protocolVersion);\n\t\t\tawait this.notifyInternal(\"notifications/initialized\", undefined, true);\n\t\t\tthis.state = \"connected\";\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tawait this.close().catch(() => {});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\trequest<Result = unknown>(\n\t\tmethod: string,\n\t\tparams?: Record<string, unknown>,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<Result> {\n\t\treturn this.requestInternal(method, params, options, false) as Promise<Result>;\n\t}\n\n\tnotify(method: string, params?: Record<string, unknown>): Promise<void> {\n\t\treturn this.notifyInternal(method, params, false);\n\t}\n\n\tsetRequestHandler(method: string, handler: RequestHandler): () => void {\n\t\tthis.requestHandlers.set(method, handler);\n\t\treturn () => {\n\t\t\tif (this.requestHandlers.get(method) === handler) this.requestHandlers.delete(method);\n\t\t};\n\t}\n\n\tonNotification(method: string, listener: NotificationListener): () => void {\n\t\tconst listeners = this.notificationListeners.get(method) ?? new Set<NotificationListener>();\n\t\tthis.notificationListeners.set(method, listeners);\n\t\tlisteners.add(listener);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.notificationListeners.delete(method);\n\t\t};\n\t}\n\n\tonError(listener: ErrorListener): () => void {\n\t\tthis.errorListeners.add(listener);\n\t\treturn () => this.errorListeners.delete(listener);\n\t}\n\n\t/** Called once when the connection closes, whether the transport dropped or `close()` was called. */\n\tonClose(listener: CloseListener): () => void {\n\t\tthis.closeListeners.add(listener);\n\t\treturn () => this.closeListeners.delete(listener);\n\t}\n\n\tasync ping(options: McpRequestOptions = {}): Promise<void> {\n\t\tawait this.request(\"ping\", undefined, options);\n\t}\n\n\tasync listTools(options: McpRequestOptions = {}): Promise<Tool[]> {\n\t\treturn (await this.listAll(\"tools/list\", \"tools\", isTool, options)) as unknown as Tool[];\n\t}\n\n\t/** Every resource, following `nextCursor` through all pages. */\n\tasync listResources(options: McpRequestOptions = {}): Promise<Resource[]> {\n\t\treturn (await this.listAll(\"resources/list\", \"resources\", isResource, options)).map(toResource);\n\t}\n\n\t/** One page of resources, starting at `cursor`. */\n\tasync listResourcesPage(cursor?: string, options: McpRequestOptions = {}): Promise<ListResourcesResult> {\n\t\tconst page = await this.listPage(\"resources/list\", \"resources\", isResource, cursor, options);\n\t\treturn { resources: page.items.map(toResource), ...pageCursor(page) };\n\t}\n\n\t/** Every resource template, following `nextCursor` through all pages. */\n\tasync listResourceTemplates(options: McpRequestOptions = {}): Promise<ResourceTemplate[]> {\n\t\tconst templates = await this.listAll(\n\t\t\t\"resources/templates/list\",\n\t\t\t\"resourceTemplates\",\n\t\t\tisResourceTemplate,\n\t\t\toptions,\n\t\t);\n\t\treturn templates.map(toResourceTemplate);\n\t}\n\n\t/** One page of resource templates, starting at `cursor`. */\n\tasync listResourceTemplatesPage(\n\t\tcursor?: string,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<ListResourceTemplatesResult> {\n\t\tconst page = await this.listPage(\n\t\t\t\"resources/templates/list\",\n\t\t\t\"resourceTemplates\",\n\t\t\tisResourceTemplate,\n\t\t\tcursor,\n\t\t\toptions,\n\t\t);\n\t\treturn { resourceTemplates: page.items.map(toResourceTemplate), ...pageCursor(page) };\n\t}\n\n\tasync readResource(uri: string, options: McpRequestOptions = {}): Promise<ReadResourceResult> {\n\t\treturn validateReadResourceResult(await this.request(\"resources/read\", { uri }, options));\n\t}\n\n\tprivate async listPage(\n\t\tmethod: string,\n\t\tkey: string,\n\t\tisItem: (item: Record<string, unknown>) => boolean,\n\t\tcursor: string | undefined,\n\t\toptions: McpRequestOptions,\n\t): Promise<{ items: Record<string, unknown>[]; nextCursor?: string }> {\n\t\treturn validateListPage(\n\t\t\tmethod,\n\t\t\tkey,\n\t\t\tawait this.request(method, cursor === undefined ? undefined : { cursor }, options),\n\t\t\tisItem,\n\t\t);\n\t}\n\n\t/** Every item of a paginated list method. */\n\tprivate async listAll(\n\t\tmethod: string,\n\t\tkey: string,\n\t\tisItem: (item: Record<string, unknown>) => boolean,\n\t\toptions: McpRequestOptions,\n\t): Promise<Record<string, unknown>[]> {\n\t\tconst items: Record<string, unknown>[] = [];\n\t\tconst cursors = new Set<string>();\n\t\tlet cursor: string | undefined;\n\t\tfor (let pageNumber = 0; pageNumber < MAX_LIST_PAGES; pageNumber++) {\n\t\t\tconst page = await this.listPage(method, key, isItem, cursor, options);\n\t\t\titems.push(...page.items);\n\t\t\tif (page.nextCursor === undefined) return items;\n\t\t\tif (cursors.has(page.nextCursor))\n\t\t\t\tthrow new Error(`MCP ${method} returned duplicate cursor: ${page.nextCursor}`);\n\t\t\tcursors.add(page.nextCursor);\n\t\t\tcursor = page.nextCursor;\n\t\t}\n\t\tthrow new Error(`MCP ${method} exceeded ${MAX_LIST_PAGES} pages`);\n\t}\n\n\tasync callTool(\n\t\tname: string,\n\t\targs?: Record<string, unknown>,\n\t\toptions: McpRequestOptions = {},\n\t): Promise<CallToolResult> {\n\t\treturn validateCallToolResult(\n\t\t\tawait this.request(\"tools/call\", { name, ...(args === undefined ? {} : { arguments: args }) }, options),\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst transport = this.transport;\n\t\tthis.transport = undefined;\n\t\tthis.disposeTransportListeners();\n\t\tthis.markClosed(new McpConnectionClosedError());\n\t\tawait transport?.close();\n\t}\n\n\tprivate async requestInternal(\n\t\tmethod: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\toptions: McpRequestOptions,\n\t\tallowConnecting: boolean,\n\t): Promise<unknown> {\n\t\tconst transport = this.requireTransport(allowConnecting);\n\t\tif (options.signal?.aborted) throw new McpAbortError();\n\t\tconst id = this.nextRequestId++;\n\t\tconst progressToken = options.onProgress ? id : undefined;\n\t\tconst requestParams =\n\t\t\tprogressToken === undefined\n\t\t\t\t? params\n\t\t\t\t: { ...params, _meta: { ...(isObject(params?._meta) ? params._meta : {}), progressToken } };\n\t\tconst message: JsonRpcRequest = {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tmethod,\n\t\t\t...(requestParams === undefined ? {} : { params: requestParams }),\n\t\t};\n\t\treturn new Promise<unknown>((resolve, reject) => {\n\t\t\tconst entry: PendingRequest = {\n\t\t\t\tresolve,\n\t\t\t\treject,\n\t\t\t\ttimeoutMs: options.timeoutMs ?? this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,\n\t\t\t\ttimer: undefined,\n\t\t\t\tsignal: options.signal,\n\t\t\t\t// The spec forbids cancelling `initialize`.\n\t\t\t\tonAbort: () =>\n\t\t\t\t\tthis.cancelPending(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tnew McpAbortError(),\n\t\t\t\t\t\tmethod !== \"initialize\",\n\t\t\t\t\t\tString(options.signal?.reason ?? \"Aborted\"),\n\t\t\t\t\t),\n\t\t\t\tsendController: new AbortController(),\n\t\t\t\tcancellable: method !== \"initialize\",\n\t\t\t\tonProgress: options.onProgress,\n\t\t\t\tprogressToken,\n\t\t\t};\n\t\t\tthis.pending.set(id, entry);\n\t\t\tif (progressToken !== undefined) this.progressRequests.set(progressToken, id);\n\t\t\toptions.signal?.addEventListener(\"abort\", entry.onAbort, { once: true });\n\t\t\tthis.armTimeout(id, entry);\n\t\t\ttransport\n\t\t\t\t.send(message, { signal: entry.sendController.signal })\n\t\t\t\t.catch((error) => this.cancelPending(id, error, false));\n\t\t});\n\t}\n\n\tprivate async notifyInternal(\n\t\tmethod: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\tallowConnecting: boolean,\n\t): Promise<void> {\n\t\tawait this.requireTransport(allowConnecting).send({\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tmethod,\n\t\t\t...(params === undefined ? {} : { params }),\n\t\t});\n\t}\n\n\tprivate requireTransport(allowConnecting: boolean): McpTransport {\n\t\tif (this.transport && (this.state === \"connected\" || (allowConnecting && this.state === \"connecting\"))) {\n\t\t\treturn this.transport;\n\t\t}\n\t\tthrow new McpConnectionClosedError(`MCP client is ${this.state}`);\n\t}\n\n\tprivate handleMessage(message: JsonRpcMessage): void {\n\t\tif (isJsonRpcResponse(message)) {\n\t\t\tthis.handleResponse(message);\n\t\t\treturn;\n\t\t}\n\t\tif (isJsonRpcRequest(message)) {\n\t\t\tvoid this.handleRequest(message);\n\t\t\treturn;\n\t\t}\n\t\tif (isJsonRpcNotification(message)) {\n\t\t\tthis.handleNotification(message.method, message.params);\n\t\t\treturn;\n\t\t}\n\t\tthis.emitError(new McpError(JSON_RPC_ERROR_CODES.invalidRequest, \"Received invalid JSON-RPC message\"));\n\t}\n\n\tprivate handleResponse(message: JsonRpcResponse): void {\n\t\tconst entry = this.pending.get(message.id);\n\t\tif (!entry) {\n\t\t\tthis.emitError(new Error(`Received response for unknown MCP request ${String(message.id)}`));\n\t\t\treturn;\n\t\t}\n\t\tthis.removePending(message.id, entry);\n\t\tif (\"error\" in message) entry.reject(new McpError(message.error.code, message.error.message, message.error.data));\n\t\telse entry.resolve(message.result);\n\t}\n\n\tprivate async handleRequest(message: JsonRpcRequest): Promise<void> {\n\t\tconst transport = this.transport;\n\t\tif (!transport) return;\n\t\tconst handler = this.requestHandlers.get(message.method);\n\t\tif (!handler) {\n\t\t\tawait transport\n\t\t\t\t.send({\n\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\tid: message.id,\n\t\t\t\t\terror: { code: JSON_RPC_ERROR_CODES.methodNotFound, message: `Method not found: ${message.method}` },\n\t\t\t\t})\n\t\t\t\t.catch((error) => this.emitError(error));\n\t\t\treturn;\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tthis.incoming.set(message.id, controller);\n\t\ttry {\n\t\t\tconst result = await handler(message.params, { signal: controller.signal });\n\t\t\tawait transport.send({ jsonrpc: \"2.0\", id: message.id, result: result ?? {} });\n\t\t} catch (error) {\n\t\t\tconst responseError =\n\t\t\t\terror instanceof McpError\n\t\t\t\t\t? { code: error.code, message: error.message, data: error.data }\n\t\t\t\t\t: { code: JSON_RPC_ERROR_CODES.internalError, message: toError(error).message };\n\t\t\tawait transport\n\t\t\t\t.send({ jsonrpc: \"2.0\", id: message.id, error: responseError })\n\t\t\t\t.catch((sendError) => this.emitError(sendError));\n\t\t} finally {\n\t\t\tthis.incoming.delete(message.id);\n\t\t}\n\t}\n\n\tprivate handleNotification(method: string, params: unknown): void {\n\t\tif (method === \"notifications/progress\") this.handleProgress(params);\n\t\telse if (method === \"notifications/cancelled\") this.handleCancelled(params);\n\t\tfor (const listener of this.notificationListeners.get(method) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener(params);\n\t\t\t} catch (error) {\n\t\t\t\tthis.emitError(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleProgress(params: unknown): void {\n\t\tif (!isObject(params) || !isJsonRpcId(params.progressToken) || typeof params.progress !== \"number\") return;\n\t\tconst requestId = this.progressRequests.get(params.progressToken);\n\t\tconst entry = requestId === undefined ? undefined : this.pending.get(requestId);\n\t\tif (requestId === undefined || !entry) return;\n\t\tthis.armTimeout(requestId, entry);\n\t\ttry {\n\t\t\tentry.onProgress?.(params as unknown as ProgressNotification);\n\t\t} catch (error) {\n\t\t\tthis.emitError(error);\n\t\t}\n\t}\n\n\tprivate handleCancelled(params: unknown): void {\n\t\tif (isObject(params) && isJsonRpcId(params.requestId)) this.incoming.get(params.requestId)?.abort(params.reason);\n\t}\n\n\tprivate armTimeout(id: JsonRpcId, entry: PendingRequest): void {\n\t\tif (entry.timer) clearTimeout(entry.timer);\n\t\tif (!Number.isFinite(entry.timeoutMs) || entry.timeoutMs <= 0) return;\n\t\tentry.timer = setTimeout(() => {\n\t\t\tthis.cancelPending(id, new McpTimeoutError(entry.timeoutMs), entry.cancellable, \"Request timed out\");\n\t\t}, entry.timeoutMs);\n\t}\n\n\tprivate cancelPending(id: JsonRpcId, error: unknown, notifyServer: boolean, reason?: string): void {\n\t\tconst entry = this.pending.get(id);\n\t\tif (!entry) return;\n\t\tthis.removePending(id, entry);\n\t\tentry.reject(error);\n\t\tif (notifyServer && this.transport) {\n\t\t\tvoid this.transport\n\t\t\t\t.send({\n\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\tmethod: \"notifications/cancelled\",\n\t\t\t\t\tparams: { requestId: id, ...(reason ? { reason } : {}) },\n\t\t\t\t})\n\t\t\t\t.catch((sendError) => this.emitError(sendError));\n\t\t}\n\t}\n\n\tprivate removePending(id: JsonRpcId, entry: PendingRequest): void {\n\t\tthis.pending.delete(id);\n\t\tif (entry.timer) clearTimeout(entry.timer);\n\t\tif (entry.progressToken !== undefined) this.progressRequests.delete(entry.progressToken);\n\t\tentry.signal?.removeEventListener(\"abort\", entry.onAbort);\n\t\tentry.sendController.abort();\n\t}\n\n\tprivate rejectPending(error: unknown): void {\n\t\tfor (const [id, entry] of this.pending) {\n\t\t\tthis.removePending(id, entry);\n\t\t\tentry.reject(error);\n\t\t}\n\t}\n\n\tprivate handleTransportClose(): void {\n\t\tthis.markClosed(new McpConnectionClosedError());\n\t}\n\n\t/** Idempotent: rejects in-flight requests, aborts server requests we are serving, and flips the state. */\n\tprivate markClosed(error: Error): void {\n\t\tconst wasClosed = this.state === \"closed\";\n\t\tthis.state = \"closed\";\n\t\tthis.rejectPending(error);\n\t\tfor (const controller of this.incoming.values()) controller.abort(error);\n\t\tthis.incoming.clear();\n\t\tif (wasClosed) return;\n\t\tfor (const listener of [...this.closeListeners]) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch (listenerError) {\n\t\t\t\tthis.emitError(listenerError);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitError(error: unknown): void {\n\t\tconst normalized = toError(error);\n\t\tfor (const listener of this.errorListeners) listener(normalized);\n\t}\n\n\tprivate disposeTransportListeners(): void {\n\t\tfor (const dispose of this.disposers.splice(0)) dispose();\n\t}\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  export type { AuthProvider, McpFetch, UnauthorizedContext } from "./auth-provider.js";
2
2
  export { McpClient, type McpClientOptions, type McpRequestOptions } from "./client.js";
3
- export { type AudioContent, type BlobResourceContents, type CallToolResult, type ContentAnnotations, type ContentBlock, type EmbeddedResourceContent, type ImageContent, type LlmContent, type ResourceLinkContent, type TextContent, type TextResourceContents, toLlmContent, } from "./protocol/content.js";
3
+ export { type AudioContent, type BlobResourceContents, type CallToolResult, type ContentAnnotations, type ContentBlock, type EmbeddedResourceContent, type ImageContent, type JsonValue, type LlmContent, type ResourceLinkContent, type TextContent, type TextResourceContents, toLlmContent, } from "./protocol/content.js";
4
4
  export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, type JsonRpcErrorObject, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.js";
5
5
  export { type CancelledNotification, type ClientCapabilities, type Implementation, type InitializeParams, type InitializeResult, LATEST_PROTOCOL_VERSION, type ListResourcesResult, type ListResourceTemplatesResult, type ListToolsResult, type ProgressNotification, type ReadResourceResult, type Resource, type ResourceTemplate, type Root, type ServerCapabilities, SUPPORTED_PROTOCOL_VERSIONS, type SupportedProtocolVersion, type Tool, type ToolAnnotations, type ToolExecution, } from "./protocol/types.js";
6
6
  export { StdioTransport, type StdioTransportOptions } from "./transports/stdio.js";
7
7
  export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, type StreamableHttpTransportOptions, } from "./transports/streamable-http.js";
8
- export type { McpTransport, McpTransportCloseListener, McpTransportErrorListener, McpTransportMessageListener, } from "./transports/transport.js";
8
+ export type { McpTransport, McpTransportCloseListener, McpTransportErrorListener, McpTransportMessageListener, McpTransportSendOptions, } from "./transports/transport.js";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/mcp/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACT,KAAK,eAAe,EACpB,KAAK,aAAa,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,8BAA8B,GACnC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACX,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,GAC3B,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/mcp/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACT,KAAK,eAAe,EACpB,KAAK,aAAa,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,8BAA8B,GACnC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACX,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,uBAAuB,GACvB,MAAM,2BAA2B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/mcp/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EAYN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.js\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.js\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.js\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.js\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.js\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.js\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.js\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n} from \"./transports/transport.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/mcp/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EAaN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.js\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.js\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype JsonValue,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.js\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.js\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.js\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.js\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.js\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n\tMcpTransportSendOptions,\n} from \"./transports/transport.js\";\n"]}
@@ -53,9 +53,12 @@ export interface EmbeddedResourceContent {
53
53
  _meta?: Record<string, unknown>;
54
54
  }
55
55
  export type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLinkContent | EmbeddedResourceContent;
56
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
57
+ [key: string]: JsonValue;
58
+ };
56
59
  export interface CallToolResult {
57
60
  content: ContentBlock[];
58
- structuredContent?: Record<string, unknown>;
61
+ structuredContent?: JsonValue;
59
62
  isError?: boolean;
60
63
  _meta?: Record<string, unknown>;
61
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/protocol/content.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC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C;AAChB,CAAC","sourcesContent":["export interface ContentAnnotations {\n\taudience?: (\"user\" | \"assistant\")[];\n\tpriority?: number;\n\tlastModified?: string;\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string;\n\tmimeType: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface AudioContent {\n\ttype: \"audio\";\n\tdata: string;\n\tmimeType: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ResourceLinkContent {\n\ttype: \"resource_link\";\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\nexport interface TextResourceContents {\n\turi: string;\n\tmimeType?: string;\n\ttext: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface BlobResourceContents {\n\turi: string;\n\tmimeType?: string;\n\tblob: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface EmbeddedResourceContent {\n\ttype: \"resource\";\n\tresource: TextResourceContents | BlobResourceContents;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLinkContent | EmbeddedResourceContent;\n\nexport interface CallToolResult {\n\tcontent: ContentBlock[];\n\tstructuredContent?: Record<string, unknown>;\n\tisError?: boolean;\n\t_meta?: Record<string, unknown>;\n}\n\n/**\n * Tool result content in the shape LLM APIs accept: text and base64 images. Matches the\n * `TextContent` and `ImageContent` types of `@earendil-works/pi-ai`.\n */\nexport type LlmContent = { type: \"text\"; text: string } | { type: \"image\"; data: string; mimeType: string };\n\nfunction blockToLlmContent(block: ContentBlock): LlmContent {\n\tswitch (block.type) {\n\t\tcase \"text\":\n\t\t\treturn { type: \"text\", text: block.text };\n\t\tcase \"image\":\n\t\t\treturn { type: \"image\", data: block.data, mimeType: block.mimeType };\n\t\tcase \"audio\":\n\t\t\treturn { type: \"text\", text: `[audio ${block.mimeType} omitted]` };\n\t\tcase \"resource_link\":\n\t\t\treturn { type: \"text\", text: `${block.name}: ${block.uri}` };\n\t\tcase \"resource\": {\n\t\t\tconst resource = block.resource;\n\t\t\tif (\"text\" in resource) return { type: \"text\", text: resource.text };\n\t\t\tif (resource.mimeType?.startsWith(\"image/\")) {\n\t\t\t\treturn { type: \"image\", data: resource.blob, mimeType: resource.mimeType };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `[binary resource ${resource.uri} (${resource.mimeType ?? \"unknown type\"}) omitted]`,\n\t\t\t};\n\t\t}\n\t\tdefault:\n\t\t\treturn { type: \"text\", text: `[unsupported MCP content ${(block as { type: string }).type}]` };\n\t}\n}\n\n/**\n * Convert a tool result to text and image content for a model. Text and images pass through,\n * embedded text resources become text, embedded image resources become images, and other blocks\n * (audio, resource links, binary resources) become a short text placeholder. A result without\n * content blocks but with `structuredContent` becomes its JSON, since servers should, but do not\n * always, mirror structured results as text.\n */\nexport function toLlmContent(result: Pick<CallToolResult, \"content\" | \"structuredContent\">): LlmContent[] {\n\tconst content = (result.content ?? []).map(blockToLlmContent);\n\tif (content.length === 0 && result.structuredContent !== undefined) {\n\t\tcontent.push({ type: \"text\", text: JSON.stringify(result.structuredContent, null, 2) });\n\t}\n\treturn content;\n}\n"]}
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/protocol/content.ts"],"names":[],"mappings":"AA+EA,SAAS,iBAAiB,CAAC,KAAmB;IAC7C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,MAAM;YACV,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC3C,KAAK,OAAO;YACX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I,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["export interface ContentAnnotations {\n\taudience?: (\"user\" | \"assistant\")[];\n\tpriority?: number;\n\tlastModified?: string;\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string;\n\tmimeType: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface AudioContent {\n\ttype: \"audio\";\n\tdata: string;\n\tmimeType: string;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface ResourceLinkContent {\n\ttype: \"resource_link\";\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\nexport interface TextResourceContents {\n\turi: string;\n\tmimeType?: string;\n\ttext: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface BlobResourceContents {\n\turi: string;\n\tmimeType?: string;\n\tblob: string;\n\t_meta?: Record<string, unknown>;\n}\n\nexport interface EmbeddedResourceContent {\n\ttype: \"resource\";\n\tresource: TextResourceContents | BlobResourceContents;\n\tannotations?: ContentAnnotations;\n\t_meta?: Record<string, unknown>;\n}\n\nexport type ContentBlock = TextContent | ImageContent | AudioContent | ResourceLinkContent | EmbeddedResourceContent;\n\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\n\nexport interface CallToolResult {\n\tcontent: ContentBlock[];\n\tstructuredContent?: JsonValue;\n\tisError?: boolean;\n\t_meta?: Record<string, unknown>;\n}\n\n/**\n * Tool result content in the shape LLM APIs accept: text and base64 images. Matches the\n * `TextContent` and `ImageContent` types of `@earendil-works/pi-ai`.\n */\nexport type LlmContent = { type: \"text\"; text: string } | { type: \"image\"; data: string; mimeType: string };\n\nfunction blockToLlmContent(block: ContentBlock): LlmContent {\n\tswitch (block.type) {\n\t\tcase \"text\":\n\t\t\treturn { type: \"text\", text: block.text };\n\t\tcase \"image\":\n\t\t\treturn { type: \"image\", data: block.data, mimeType: block.mimeType };\n\t\tcase \"audio\":\n\t\t\treturn { type: \"text\", text: `[audio ${block.mimeType} omitted]` };\n\t\tcase \"resource_link\":\n\t\t\treturn { type: \"text\", text: `${block.name}: ${block.uri}` };\n\t\tcase \"resource\": {\n\t\t\tconst resource = block.resource;\n\t\t\tif (\"text\" in resource) return { type: \"text\", text: resource.text };\n\t\t\tif (resource.mimeType?.startsWith(\"image/\")) {\n\t\t\t\treturn { type: \"image\", data: resource.blob, mimeType: resource.mimeType };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `[binary resource ${resource.uri} (${resource.mimeType ?? \"unknown type\"}) omitted]`,\n\t\t\t};\n\t\t}\n\t\tdefault:\n\t\t\treturn { type: \"text\", text: `[unsupported MCP content ${(block as { type: string }).type}]` };\n\t}\n}\n\n/**\n * Convert a tool result to text and image content for a model. Text and images pass through,\n * embedded text resources become text, embedded image resources become images, and other blocks\n * (audio, resource links, binary resources) become a short text placeholder. A result without\n * content blocks but with `structuredContent` becomes its JSON, since servers should, but do not\n * always, mirror structured results as text.\n */\nexport function toLlmContent(result: Pick<CallToolResult, \"content\" | \"structuredContent\">): LlmContent[] {\n\tconst content = (result.content ?? []).map(blockToLlmContent);\n\tif (content.length === 0 && result.structuredContent !== undefined) {\n\t\tcontent.push({ type: \"text\", text: JSON.stringify(result.structuredContent, null, 2) });\n\t}\n\treturn content;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { AuthProvider, McpFetch } from "../auth-provider.js";
2
2
  import { type JsonRpcMessage } from "../protocol/jsonrpc.js";
3
- import { type McpTransport, TransportEvents } from "./transport.js";
3
+ import { type McpTransport, type McpTransportSendOptions, TransportEvents } from "./transport.js";
4
4
  export interface SseEvent {
5
5
  event?: string;
6
6
  data: string;
@@ -62,7 +62,7 @@ export declare class StreamableHttpTransport extends TransportEvents implements
62
62
  get sessionId(): string | undefined;
63
63
  start(): Promise<void>;
64
64
  setProtocolVersion(version: string): void;
65
- send(message: JsonRpcMessage): Promise<void>;
65
+ send(message: JsonRpcMessage, { signal }?: McpTransportSendOptions): Promise<void>;
66
66
  close(): Promise<void>;
67
67
  /**
68
68
  * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider
@@ -1 +1 @@
1
- {"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/transports/streamable-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAKN,KAAK,cAAc,EAInB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA6B,KAAK,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAQ/F,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,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,CAAC,OAAO,EAAE,QAAQ,CAAC,8BAA8B,CAAC,CAAC;IAC3D,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,gBAAgB,CAAS;IACjC,sGAAsG;IACtG,OAAO,CAAC,SAAS,CAAqB;IAEtC,YAAY,OAAO,EAAE,8BAA8B,EAQlD;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAI3B;IAED,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAExC;IAEK,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BjD;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3B;IAED;;;OAGG;YACW,eAAe;YAsBf,OAAO;IAMrB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,cAAc;YAKR,aAAa;YAQb,UAAU;IA8BxB;;;;OAIG;YACW,qBAAqB;IAwCnC,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
+ {"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/transports/streamable-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAKN,KAAK,cAAc,EAKnB,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OAAO,CAAC,cAAc;YAKR,aAAa;YAQb,UAAU;IA8BxB;;;;OAIG;YACW,qBAAqB;IAwCnC,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,5 +1,5 @@
1
- import { isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpConnectionClosedError, parseJsonRpcMessage, toError, } from "../protocol/jsonrpc.js";
2
- import { DEFAULT_MAX_MESSAGE_BYTES, TransportEvents } from "./transport.js";
1
+ import { isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, parseJsonRpcMessage, toError, } from "../protocol/jsonrpc.js";
2
+ import { DEFAULT_MAX_MESSAGE_BYTES, TransportEvents, } from "./transport.js";
3
3
  const MAX_ERROR_BODY_BYTES = 8 * 1024;
4
4
  const ERROR_MESSAGE_BODY_CHARS = 500;
5
5
  const DEFAULT_RECONNECT_INITIAL_DELAY_MS = 1_000;
@@ -162,13 +162,13 @@ export class StreamableHttpTransport extends TransportEvents {
162
162
  setProtocolVersion(version) {
163
163
  this.protocolVersion = version;
164
164
  }
165
- async send(message) {
165
+ async send(message, { signal } = {}) {
166
166
  if (!this.started || this.closed)
167
167
  throw new McpConnectionClosedError();
168
168
  const response = await this.authorizedFetch("POST", {
169
169
  headers: { accept: "application/json, text/event-stream", "content-type": "application/json" },
170
170
  body: JSON.stringify(message),
171
- });
171
+ }, signal);
172
172
  await this.checkResponse(response);
173
173
  this.captureSession(response);
174
174
  if (!isJsonRpcRequest(message)) {
@@ -220,10 +220,12 @@ export class StreamableHttpTransport extends TransportEvents {
220
220
  * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider
221
221
  * once, and the request is retried with whatever credentials it left behind.
222
222
  */
223
- async authorizedFetch(method, init) {
223
+ async authorizedFetch(method, init, signal) {
224
224
  const onUnauthorized = this.options.authProvider?.onUnauthorized?.bind(this.options.authProvider);
225
225
  for (let attempt = 0;; attempt++) {
226
226
  const { headers, token } = await this.headers(init.headers);
227
+ if (signal?.aborted)
228
+ throw new McpAbortError();
227
229
  const response = await this.fetch(this.url, {
228
230
  method,
229
231
  headers,
@@ -1 +1 @@
1
- {"version":3,"file":"streamable-http.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/transports/streamable-http.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EAGpB,wBAAwB,EACxB,mBAAmB,EACnB,OAAO,GACP,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAqB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/F,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,CAAC;AACtC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,kCAAkC,GAAG,KAAK,CAAC;AACjD,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAC9C,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAiBxC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAkC,EAAE,OAA0B;IACpG,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,SAA6B,CAAC;IAClC,IAAI,OAA2B,CAAC;IAChC,IAAI,SAAS,GAAa,EAAE,CAAC;IAC7B,0FAA0F;IAC1F,kFAAkF;IAClF,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,yBAAyB,CAAC;IAEzE,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ider, McpFetch } from \"../auth-provider.js\";\nimport {\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\tMcpConnectionClosedError,\n\tparseJsonRpcMessage,\n\ttoError,\n} from \"../protocol/jsonrpc.js\";\nimport { DEFAULT_MAX_MESSAGE_BYTES, type McpTransport, TransportEvents } from \"./transport.js\";\n\nconst MAX_ERROR_BODY_BYTES = 8 * 1024;\nconst ERROR_MESSAGE_BODY_CHARS = 500;\nconst DEFAULT_RECONNECT_INITIAL_DELAY_MS = 1_000;\nconst DEFAULT_RECONNECT_MAX_DELAY_MS = 30_000;\nconst DEFAULT_RECONNECT_MAX_RETRIES = 5;\n\nexport interface SseEvent {\n\tevent?: string;\n\tdata: string;\n\tid?: string;\n}\n\nexport interface ConsumeSseOptions {\n\tmaxEventBytes?: number;\n\tonEvent(event: SseEvent): void;\n\t/** Called for every `id` field, including events without data (for example resumption priming events). */\n\tonId?(id: string): void;\n\t/** Called for every valid `retry` field, in milliseconds. */\n\tonRetry?(delayMs: number): void;\n}\n\nexport async function consumeSseStream(stream: ReadableStream<Uint8Array>, options: ConsumeSseOptions): Promise<void> {\n\tconst reader = stream.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffered = \"\";\n\tlet eventName: string | undefined;\n\tlet eventId: string | undefined;\n\tlet dataLines: string[] = [];\n\t// Bytes of the pending event's data, including the \"\\n\" joins, so events streamed as many\n\t// short `data:` lines without a terminating blank line cannot grow without bound.\n\tlet dataBytes = 0;\n\tconst maxEventBytes = options.maxEventBytes ?? DEFAULT_MAX_MESSAGE_BYTES;\n\n\tconst dispatch = () => {\n\t\tif (dataLines.length === 0) {\n\t\t\teventName = undefined;\n\t\t\teventId = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst data = dataLines.join(\"\\n\");\n\t\toptions.onEvent({ ...(eventName ? { event: eventName } : {}), data, ...(eventId ? { id: eventId } : {}) });\n\t\teventName = undefined;\n\t\teventId = undefined;\n\t\tdataLines = [];\n\t\tdataBytes = 0;\n\t};\n\n\tconst processLine = (rawLine: string) => {\n\t\tconst line = rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine;\n\t\tif (line === \"\") {\n\t\t\tdispatch();\n\t\t\treturn;\n\t\t}\n\t\tif (line.startsWith(\":\")) return;\n\t\tconst colon = line.indexOf(\":\");\n\t\tconst field = colon < 0 ? line : line.slice(0, colon);\n\t\tlet value = colon < 0 ? \"\" : line.slice(colon + 1);\n\t\tif (value.startsWith(\" \")) value = value.slice(1);\n\t\tif (field === \"data\") {\n\t\t\tdataBytes += Buffer.byteLength(value) + (dataLines.length > 0 ? 1 : 0);\n\t\t\tif (dataBytes > maxEventBytes) throw new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);\n\t\t\tdataLines.push(value);\n\t\t} else if (field === \"event\") eventName = value;\n\t\telse if (field === \"id\" && !value.includes(\"\\0\")) {\n\t\t\teventId = value;\n\t\t\toptions.onId?.(value);\n\t\t} else if (field === \"retry\" && /^\\d+$/.test(value)) options.onRetry?.(Number(value));\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffered += decoder.decode(value, { stream: true });\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline >= 0) {\n\t\t\t\tprocessLine(buffered.slice(0, newline));\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t}\n\t\t\tif (Buffer.byteLength(buffered) > maxEventBytes)\n\t\t\t\tthrow new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);\n\t\t}\n\t\tbuffered += decoder.decode();\n\t\tif (buffered) processLine(buffered);\n\t\tdispatch();\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\nexport interface StreamableHttpReconnectOptions {\n\t/** Delay before the first reconnection attempt, unless the server sent a `retry` field. Default: 1000. */\n\tinitialDelayMs?: number;\n\t/** Upper bound for the exponential backoff. Default: 30000. */\n\tmaxDelayMs?: number;\n\t/** Consecutive failed attempts before giving up on a stream. Default: 5. */\n\tmaxRetries?: number;\n}\n\nexport interface StreamableHttpTransportOptions {\n\turl: string | URL;\n\theaders?: Record<string, string>;\n\tfetch?: McpFetch;\n\t/** Open the server-to-client GET stream after initialization. Default: true. */\n\topenGetStream?: boolean;\n\tmaxMessageBytes?: number;\n\tauthProvider?: AuthProvider;\n\t/** Reconnection of dropped SSE streams (the GET stream, and response streams that carry event IDs). */\n\treconnect?: StreamableHttpReconnectOptions;\n}\n\nexport class McpHttpError extends Error {\n\treadonly status: number;\n\treadonly body: string;\n\n\tconstructor(status: number, message: string, body = \"\") {\n\t\tsuper(message);\n\t\tthis.name = \"McpHttpError\";\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class McpAuthRequiredError extends McpHttpError {\n\treadonly wwwAuthenticate: string | null;\n\n\tconstructor(response: Response, body = \"\") {\n\t\tsuper(401, \"MCP server requires authentication\", body);\n\t\tthis.name = \"McpAuthRequiredError\";\n\t\tthis.wwwAuthenticate = response.headers.get(\"www-authenticate\");\n\t}\n}\n\nexport class McpSessionExpiredError extends McpHttpError {\n\tconstructor(body = \"\") {\n\t\tsuper(404, \"MCP session expired\", body);\n\t\tthis.name = \"McpSessionExpiredError\";\n\t}\n}\n\nfunction contentType(response: Response): string | undefined {\n\treturn response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase();\n}\n\n/** 401, or 403 with an `insufficient_scope` bearer challenge (step-up authorization). */\nfunction needsAuthorization(response: Response): boolean {\n\tif (response.status === 401) return true;\n\tif (response.status !== 403) return false;\n\treturn /(?:^|[\\s,])error=\"?insufficient_scope\"?/i.test(response.headers.get(\"www-authenticate\") ?? \"\");\n}\n\n/** Statuses worth retrying when a stream fails to (re)open. */\nfunction isTransientStatus(status: number): boolean {\n\treturn status === 408 || status === 429 || status >= 500;\n}\n\nfunction discard(response: Response): Promise<void> {\n\treturn response.body?.cancel().catch(() => {}) ?? Promise.resolve();\n}\n\nfunction describeHttpFailure(status: number, body: string): string {\n\tconst text = body.trim();\n\tconst snippet = text.length > ERROR_MESSAGE_BODY_CHARS ? `${text.slice(0, ERROR_MESSAGE_BODY_CHARS - 3)}...` : text;\n\treturn `MCP HTTP request failed with status ${status}${snippet ? `: ${snippet}` : \"\"}`;\n}\n\ninterface StreamCursor {\n\tlastEventId: string | undefined;\n\tretryMs: number | undefined;\n\t/** Whether the stream delivered any event since it was (re)opened. */\n\treceived: boolean;\n}\n\nexport class StreamableHttpTransport extends TransportEvents implements McpTransport {\n\treadonly url: URL;\n\treadonly options: Readonly<StreamableHttpTransportOptions>;\n\tprivate fetch: McpFetch;\n\tprivate controller = new AbortController();\n\tprivate started = false;\n\tprivate closed = false;\n\tprivate sessionIdValue: string | undefined;\n\tprivate protocolVersion: string | undefined;\n\tprivate getStreamStarted = false;\n\t/** Access token of the latest request, which `close()` reuses instead of asking the auth provider. */\n\tprivate lastToken: string | undefined;\n\n\tconstructor(options: StreamableHttpTransportOptions) {\n\t\tsuper();\n\t\tthis.options = Object.freeze({ ...options, headers: options.headers ? { ...options.headers } : undefined });\n\t\tthis.url = new URL(options.url);\n\t\tconst fetch = options.fetch ?? globalThis.fetch;\n\t\t// Call fetch without a receiver. `this.fetch(...)` and `context.fetch(...)` would pass the transport or\n\t\t// the auth context as `this`, which Cloudflare Workers reject for the platform fetch (\"Illegal invocation\").\n\t\tthis.fetch = (input, init) => fetch(input, init);\n\t}\n\n\tget sessionId(): string | undefined {\n\t\treturn this.sessionIdValue;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.started) throw new Error(\"MCP Streamable HTTP transport already started\");\n\t\tif (this.closed) throw new McpConnectionClosedError();\n\t\tthis.started = true;\n\t}\n\n\tsetProtocolVersion(version: string): void {\n\t\tthis.protocolVersion = version;\n\t}\n\n\tasync send(message: JsonRpcMessage): Promise<void> {\n\t\tif (!this.started || this.closed) throw new McpConnectionClosedError();\n\t\tconst response = await this.authorizedFetch(\"POST\", {\n\t\t\theaders: { accept: \"application/json, text/event-stream\", \"content-type\": \"application/json\" },\n\t\t\tbody: JSON.stringify(message),\n\t\t});\n\t\tawait this.checkResponse(response);\n\t\tthis.captureSession(response);\n\n\t\tif (!isJsonRpcRequest(message)) {\n\t\t\t// Notifications and responses are acknowledged with 202 and carry no reply; ignore any body.\n\t\t\tawait discard(response);\n\t\t\t// The server-to-client stream may only open once the session is initialized.\n\t\t\tif (\"method\" in message && message.method === \"notifications/initialized\") this.startGetStream();\n\t\t\treturn;\n\t\t}\n\t\tif (response.status === 202 || response.status === 204) {\n\t\t\tthrow new McpHttpError(response.status, `MCP server accepted request ${message.method} without a response`);\n\t\t}\n\t\tconst type = contentType(response);\n\t\tif (type === \"application/json\") {\n\t\t\tconst body: unknown = await response.json();\n\t\t\tfor (const item of Array.isArray(body) ? body : [body]) this.emitMessage(parseJsonRpcMessage(item));\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"text/event-stream\" && response.body) {\n\t\t\tvoid this.consumeResponseStream(response.body, message.id);\n\t\t\treturn;\n\t\t}\n\t\tawait discard(response);\n\t\tthrow new McpHttpError(response.status, `Unsupported MCP response content type: ${type ?? \"missing\"}`);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tthis.controller.abort();\n\t\tif (this.started && this.sessionIdValue) {\n\t\t\t// Best effort: the session expires on the server anyway. The auth provider may refresh tokens\n\t\t\t// over the network, so it is not asked here and closing never waits for a refresh.\n\t\t\ttry {\n\t\t\t\tconst response = await this.fetch(this.url, {\n\t\t\t\t\tmethod: \"DELETE\",\n\t\t\t\t\theaders: this.buildHeaders({}, this.lastToken),\n\t\t\t\t\tsignal: AbortSignal.timeout(1_000),\n\t\t\t\t});\n\t\t\t\tawait discard(response);\n\t\t\t} catch {}\n\t\t}\n\t\tthis.emitClose();\n\t}\n\n\t/**\n\t * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider\n\t * once, and the request is retried with whatever credentials it left behind.\n\t */\n\tprivate async authorizedFetch(\n\t\tmethod: \"GET\" | \"POST\",\n\t\tinit: { headers: Record<string, string>; body?: string },\n\t): Promise<Response> {\n\t\tconst onUnauthorized = this.options.authProvider?.onUnauthorized?.bind(this.options.authProvider);\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tconst { headers, token } = await this.headers(init.headers);\n\t\t\tconst response = await this.fetch(this.url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: init.body,\n\t\t\t\tsignal: this.controller.signal,\n\t\t\t});\n\t\t\tif (attempt > 0 || !onUnauthorized || !needsAuthorization(response)) return response;\n\t\t\ttry {\n\t\t\t\tawait onUnauthorized({ response, serverUrl: this.url, fetch: this.fetch, token });\n\t\t\t} finally {\n\t\t\t\tawait discard(response);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async headers(extra: Record<string, string> = {}): Promise<{ headers: Headers; token?: string }> {\n\t\tconst token = await this.options.authProvider?.token();\n\t\tthis.lastToken = token;\n\t\treturn { headers: this.buildHeaders(extra, token), ...(token ? { token } : {}) };\n\t}\n\n\tprivate buildHeaders(extra: Record<string, string>, token: string | undefined): Headers {\n\t\tconst headers = new Headers(this.options.headers);\n\t\tfor (const [name, value] of Object.entries(extra)) headers.set(name, value);\n\t\tif (this.sessionIdValue) headers.set(\"Mcp-Session-Id\", this.sessionIdValue);\n\t\tif (this.protocolVersion) headers.set(\"MCP-Protocol-Version\", this.protocolVersion);\n\t\tif (token) headers.set(\"Authorization\", `Bearer ${token}`);\n\t\treturn headers;\n\t}\n\n\tprivate captureSession(response: Response): void {\n\t\tconst sessionId = response.headers.get(\"mcp-session-id\");\n\t\tif (sessionId) this.sessionIdValue = sessionId;\n\t}\n\n\tprivate async checkResponse(response: Response): Promise<void> {\n\t\tif (response.ok) return;\n\t\tconst body = (await response.text().catch(() => \"\")).slice(0, MAX_ERROR_BODY_BYTES);\n\t\tif (response.status === 401) throw new McpAuthRequiredError(response, body);\n\t\tif (response.status === 404 && this.sessionIdValue) throw new McpSessionExpiredError(body);\n\t\tthrow new McpHttpError(response.status, describeHttpFailure(response.status, body), body);\n\t}\n\n\tprivate async consumeSse(\n\t\tstream: ReadableStream<Uint8Array>,\n\t\tcursor: StreamCursor,\n\t\tonMessage?: (message: JsonRpcMessage) => void,\n\t): Promise<void> {\n\t\tawait consumeSseStream(stream, {\n\t\t\tmaxEventBytes: this.options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES,\n\t\t\tonId: (id) => {\n\t\t\t\tcursor.lastEventId = id;\n\t\t\t},\n\t\t\tonRetry: (delayMs) => {\n\t\t\t\tcursor.retryMs = delayMs;\n\t\t\t},\n\t\t\tonEvent: (event) => {\n\t\t\t\tcursor.received = true;\n\t\t\t\t// Events without data prime resumption; other event types are not JSON-RPC.\n\t\t\t\tif (!event.data.trim() || (event.event !== undefined && event.event !== \"message\")) return;\n\t\t\t\tlet message: JsonRpcMessage;\n\t\t\t\ttry {\n\t\t\t\t\tmessage = parseJsonRpcMessage(JSON.parse(event.data));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.emitError(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonMessage?.(message);\n\t\t\t\tthis.emitMessage(message);\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Read the SSE stream answering one request. When the stream ends or breaks before the response\n\t * arrives and the server assigned event IDs, resume it with GET and `Last-Event-ID`, as the\n\t * server may close response streams at will. Otherwise only this request fails.\n\t */\n\tprivate async consumeResponseStream(body: ReadableStream<Uint8Array>, requestId: JsonRpcId): Promise<void> {\n\t\tconst cursor: StreamCursor = { lastEventId: undefined, retryMs: undefined, received: false };\n\t\tlet answered = false;\n\t\tconst onMessage = (message: JsonRpcMessage) => {\n\t\t\tif (isJsonRpcResponse(message) && message.id === requestId) answered = true;\n\t\t};\n\t\tlet stream: ReadableStream<Uint8Array> | undefined = body;\n\t\tlet failure: unknown;\n\t\tfor (let attempt = 0; ; ) {\n\t\t\tif (stream) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.consumeSse(stream, cursor, onMessage);\n\t\t\t\t\tfailure = undefined;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailure = error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (answered || this.closed) return;\n\t\t\tif (failure !== undefined && !this.isRetryable(failure)) break;\n\t\t\tif (cursor.lastEventId === undefined || attempt >= this.maxRetries()) break;\n\t\t\tif (cursor.received) attempt = 0;\n\t\t\tcursor.received = false;\n\t\t\tif (!(await this.sleep(this.reconnectDelay(attempt++, cursor.retryMs)))) return;\n\t\t\ttry {\n\t\t\t\tstream = await this.openSseStream(cursor.lastEventId);\n\t\t\t} catch (error) {\n\t\t\t\tfailure = error;\n\t\t\t\tif (!this.isRetryable(error)) break;\n\t\t\t\tstream = undefined;\n\t\t\t}\n\t\t}\n\t\tif (this.closed) return;\n\t\tconst reason = failure === undefined ? \"stream ended without a response\" : toError(failure).message;\n\t\tthis.emitMessage({\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid: requestId,\n\t\t\terror: { code: JSON_RPC_ERROR_CODES.internalError, message: `MCP response stream failed: ${reason}` },\n\t\t});\n\t}\n\n\tprivate startGetStream(): void {\n\t\tif (this.options.openGetStream === false || this.getStreamStarted || this.closed) return;\n\t\tthis.getStreamStarted = true;\n\t\tvoid this.runGetStream();\n\t}\n\n\t/** Keep the server-to-client stream open, reconnecting with backoff when it drops. */\n\tprivate async runGetStream(): Promise<void> {\n\t\tconst cursor: StreamCursor = { lastEventId: undefined, retryMs: undefined, received: false };\n\t\tfor (let attempt = 0; !this.closed; ) {\n\t\t\ttry {\n\t\t\t\tconst stream = await this.openSseStream(cursor.lastEventId);\n\t\t\t\t// The server does not offer a GET stream.\n\t\t\t\tif (!stream) return;\n\t\t\t\tconst openedAt = Date.now();\n\t\t\t\tawait this.consumeSse(stream, cursor);\n\t\t\t\t// A stream that stayed up for a while counts as healthy, even if it was idle.\n\t\t\t\tif (cursor.received || Date.now() - openedAt > this.maxDelay()) attempt = 0;\n\t\t\t} catch (error) {\n\t\t\t\tif (this.closed) return;\n\t\t\t\tif (!this.isRetryable(error)) {\n\t\t\t\t\tthis.emitError(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcursor.received = false;\n\t\t\tif (attempt >= this.maxRetries()) {\n\t\t\t\tthis.emitError(new Error(\"MCP server-to-client stream dropped and could not be reopened\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!(await this.sleep(this.reconnectDelay(attempt++, cursor.retryMs)))) return;\n\t\t}\n\t}\n\n\t/** Open a GET SSE stream. Resolves to undefined when the server answers 405 (no GET stream). */\n\tprivate async openSseStream(lastEventId: string | undefined): Promise<ReadableStream<Uint8Array> | undefined> {\n\t\tconst response = await this.authorizedFetch(\"GET\", {\n\t\t\theaders: {\n\t\t\t\taccept: \"text/event-stream\",\n\t\t\t\t...(lastEventId === undefined ? {} : { \"last-event-id\": lastEventId }),\n\t\t\t},\n\t\t});\n\t\tif (response.status === 405) {\n\t\t\tawait discard(response);\n\t\t\treturn undefined;\n\t\t}\n\t\tawait this.checkResponse(response);\n\t\tthis.captureSession(response);\n\t\tconst type = contentType(response);\n\t\tif (type !== \"text/event-stream\" || !response.body) {\n\t\t\tawait discard(response);\n\t\t\tthrow new McpHttpError(response.status, `Unsupported MCP GET response content type: ${type ?? \"missing\"}`);\n\t\t}\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Network failures and transient statuses are retried; auth, session, and protocol errors are not.\n\t * `fetch` reports network failures, including a connection dropped mid-body, as `TypeError`.\n\t */\n\tprivate isRetryable(error: unknown): boolean {\n\t\tif (error instanceof McpHttpError) return isTransientStatus(error.status);\n\t\tif (error instanceof TypeError) return true;\n\t\tconst code = (error as { code?: unknown } | undefined)?.code;\n\t\treturn typeof code === \"string\" && (code.startsWith(\"E\") || code.startsWith(\"UND_ERR\"));\n\t}\n\n\tprivate reconnectDelay(attempt: number, serverDelayMs: number | undefined): number {\n\t\tif (serverDelayMs !== undefined) return serverDelayMs;\n\t\tconst initial = this.options.reconnect?.initialDelayMs ?? DEFAULT_RECONNECT_INITIAL_DELAY_MS;\n\t\treturn Math.min(initial * 2 ** attempt, this.maxDelay());\n\t}\n\n\tprivate maxDelay(): number {\n\t\treturn this.options.reconnect?.maxDelayMs ?? DEFAULT_RECONNECT_MAX_DELAY_MS;\n\t}\n\n\tprivate maxRetries(): number {\n\t\treturn this.options.reconnect?.maxRetries ?? DEFAULT_RECONNECT_MAX_RETRIES;\n\t}\n\n\t/** Resolves false when the transport closed while waiting. */\n\tprivate sleep(ms: number): Promise<boolean> {\n\t\tconst signal = this.controller.signal;\n\t\tif (signal.aborted) return Promise.resolve(false);\n\t\treturn new Promise((resolve) => {\n\t\t\tconst onAbort = () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(false);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(true);\n\t\t\t}, ms);\n\t\t\t// A reconnect wait alone does not keep the process alive.\n\t\t\ttimer.unref?.();\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"streamable-http.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/transports/streamable-http.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EAGpB,aAAa,EACb,wBAAwB,EACxB,mBAAmB,EACnB,OAAO,GACP,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,yBAAyB,EAGzB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,CAAC;AACtC,MAAM,wBAAwB,GAAG,GA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AAC,MAAM,CAAC;QACtC,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,MAAM,OAAO,GAAG,GAAG,EAAE;gBACpB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YACF,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC7B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,OAAO,CAAC,IAAI,CAAC,CAAC;YACf,CAAC,EAAE,EAAE,CAAC,CAAC;YACP,0DAA0D;YAC1D,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAChB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { AuthProvider, McpFetch } from \"../auth-provider.js\";\nimport {\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tparseJsonRpcMessage,\n\ttoError,\n} from \"../protocol/jsonrpc.js\";\nimport {\n\tDEFAULT_MAX_MESSAGE_BYTES,\n\ttype McpTransport,\n\ttype McpTransportSendOptions,\n\tTransportEvents,\n} from \"./transport.js\";\n\nconst MAX_ERROR_BODY_BYTES = 8 * 1024;\nconst ERROR_MESSAGE_BODY_CHARS = 500;\nconst DEFAULT_RECONNECT_INITIAL_DELAY_MS = 1_000;\nconst DEFAULT_RECONNECT_MAX_DELAY_MS = 30_000;\nconst DEFAULT_RECONNECT_MAX_RETRIES = 5;\n\nexport interface SseEvent {\n\tevent?: string;\n\tdata: string;\n\tid?: string;\n}\n\nexport interface ConsumeSseOptions {\n\tmaxEventBytes?: number;\n\tonEvent(event: SseEvent): void;\n\t/** Called for every `id` field, including events without data (for example resumption priming events). */\n\tonId?(id: string): void;\n\t/** Called for every valid `retry` field, in milliseconds. */\n\tonRetry?(delayMs: number): void;\n}\n\nexport async function consumeSseStream(stream: ReadableStream<Uint8Array>, options: ConsumeSseOptions): Promise<void> {\n\tconst reader = stream.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffered = \"\";\n\tlet eventName: string | undefined;\n\tlet eventId: string | undefined;\n\tlet dataLines: string[] = [];\n\t// Bytes of the pending event's data, including the \"\\n\" joins, so events streamed as many\n\t// short `data:` lines without a terminating blank line cannot grow without bound.\n\tlet dataBytes = 0;\n\tconst maxEventBytes = options.maxEventBytes ?? DEFAULT_MAX_MESSAGE_BYTES;\n\n\tconst dispatch = () => {\n\t\tif (dataLines.length === 0) {\n\t\t\teventName = undefined;\n\t\t\teventId = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst data = dataLines.join(\"\\n\");\n\t\toptions.onEvent({ ...(eventName ? { event: eventName } : {}), data, ...(eventId ? { id: eventId } : {}) });\n\t\teventName = undefined;\n\t\teventId = undefined;\n\t\tdataLines = [];\n\t\tdataBytes = 0;\n\t};\n\n\tconst processLine = (rawLine: string) => {\n\t\tconst line = rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine;\n\t\tif (line === \"\") {\n\t\t\tdispatch();\n\t\t\treturn;\n\t\t}\n\t\tif (line.startsWith(\":\")) return;\n\t\tconst colon = line.indexOf(\":\");\n\t\tconst field = colon < 0 ? line : line.slice(0, colon);\n\t\tlet value = colon < 0 ? \"\" : line.slice(colon + 1);\n\t\tif (value.startsWith(\" \")) value = value.slice(1);\n\t\tif (field === \"data\") {\n\t\t\tdataBytes += Buffer.byteLength(value) + (dataLines.length > 0 ? 1 : 0);\n\t\t\tif (dataBytes > maxEventBytes) throw new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);\n\t\t\tdataLines.push(value);\n\t\t} else if (field === \"event\") eventName = value;\n\t\telse if (field === \"id\" && !value.includes(\"\\0\")) {\n\t\t\teventId = value;\n\t\t\toptions.onId?.(value);\n\t\t} else if (field === \"retry\" && /^\\d+$/.test(value)) options.onRetry?.(Number(value));\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffered += decoder.decode(value, { stream: true });\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline >= 0) {\n\t\t\t\tprocessLine(buffered.slice(0, newline));\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t}\n\t\t\tif (Buffer.byteLength(buffered) > maxEventBytes)\n\t\t\t\tthrow new Error(`MCP SSE event exceeds ${maxEventBytes} bytes`);\n\t\t}\n\t\tbuffered += decoder.decode();\n\t\tif (buffered) processLine(buffered);\n\t\tdispatch();\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\nexport interface StreamableHttpReconnectOptions {\n\t/** Delay before the first reconnection attempt, unless the server sent a `retry` field. Default: 1000. */\n\tinitialDelayMs?: number;\n\t/** Upper bound for the exponential backoff. Default: 30000. */\n\tmaxDelayMs?: number;\n\t/** Consecutive failed attempts before giving up on a stream. Default: 5. */\n\tmaxRetries?: number;\n}\n\nexport interface StreamableHttpTransportOptions {\n\turl: string | URL;\n\theaders?: Record<string, string>;\n\tfetch?: McpFetch;\n\t/** Open the server-to-client GET stream after initialization. Default: true. */\n\topenGetStream?: boolean;\n\tmaxMessageBytes?: number;\n\tauthProvider?: AuthProvider;\n\t/** Reconnection of dropped SSE streams (the GET stream, and response streams that carry event IDs). */\n\treconnect?: StreamableHttpReconnectOptions;\n}\n\nexport class McpHttpError extends Error {\n\treadonly status: number;\n\treadonly body: string;\n\n\tconstructor(status: number, message: string, body = \"\") {\n\t\tsuper(message);\n\t\tthis.name = \"McpHttpError\";\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class McpAuthRequiredError extends McpHttpError {\n\treadonly wwwAuthenticate: string | null;\n\n\tconstructor(response: Response, body = \"\") {\n\t\tsuper(401, \"MCP server requires authentication\", body);\n\t\tthis.name = \"McpAuthRequiredError\";\n\t\tthis.wwwAuthenticate = response.headers.get(\"www-authenticate\");\n\t}\n}\n\nexport class McpSessionExpiredError extends McpHttpError {\n\tconstructor(body = \"\") {\n\t\tsuper(404, \"MCP session expired\", body);\n\t\tthis.name = \"McpSessionExpiredError\";\n\t}\n}\n\nfunction contentType(response: Response): string | undefined {\n\treturn response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase();\n}\n\n/** 401, or 403 with an `insufficient_scope` bearer challenge (step-up authorization). */\nfunction needsAuthorization(response: Response): boolean {\n\tif (response.status === 401) return true;\n\tif (response.status !== 403) return false;\n\treturn /(?:^|[\\s,])error=\"?insufficient_scope\"?/i.test(response.headers.get(\"www-authenticate\") ?? \"\");\n}\n\n/** Statuses worth retrying when a stream fails to (re)open. */\nfunction isTransientStatus(status: number): boolean {\n\treturn status === 408 || status === 429 || status >= 500;\n}\n\nfunction discard(response: Response): Promise<void> {\n\treturn response.body?.cancel().catch(() => {}) ?? Promise.resolve();\n}\n\nfunction describeHttpFailure(status: number, body: string): string {\n\tconst text = body.trim();\n\tconst snippet = text.length > ERROR_MESSAGE_BODY_CHARS ? `${text.slice(0, ERROR_MESSAGE_BODY_CHARS - 3)}...` : text;\n\treturn `MCP HTTP request failed with status ${status}${snippet ? `: ${snippet}` : \"\"}`;\n}\n\ninterface StreamCursor {\n\tlastEventId: string | undefined;\n\tretryMs: number | undefined;\n\t/** Whether the stream delivered any event since it was (re)opened. */\n\treceived: boolean;\n}\n\nexport class StreamableHttpTransport extends TransportEvents implements McpTransport {\n\treadonly url: URL;\n\treadonly options: Readonly<StreamableHttpTransportOptions>;\n\tprivate fetch: McpFetch;\n\tprivate controller = new AbortController();\n\tprivate started = false;\n\tprivate closed = false;\n\tprivate sessionIdValue: string | undefined;\n\tprivate protocolVersion: string | undefined;\n\tprivate getStreamStarted = false;\n\t/** Access token of the latest request, which `close()` reuses instead of asking the auth provider. */\n\tprivate lastToken: string | undefined;\n\n\tconstructor(options: StreamableHttpTransportOptions) {\n\t\tsuper();\n\t\tthis.options = Object.freeze({ ...options, headers: options.headers ? { ...options.headers } : undefined });\n\t\tthis.url = new URL(options.url);\n\t\tconst fetch = options.fetch ?? globalThis.fetch;\n\t\t// Call fetch without a receiver. `this.fetch(...)` and `context.fetch(...)` would pass the transport or\n\t\t// the auth context as `this`, which Cloudflare Workers reject for the platform fetch (\"Illegal invocation\").\n\t\tthis.fetch = (input, init) => fetch(input, init);\n\t}\n\n\tget sessionId(): string | undefined {\n\t\treturn this.sessionIdValue;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.started) throw new Error(\"MCP Streamable HTTP transport already started\");\n\t\tif (this.closed) throw new McpConnectionClosedError();\n\t\tthis.started = true;\n\t}\n\n\tsetProtocolVersion(version: string): void {\n\t\tthis.protocolVersion = version;\n\t}\n\n\tasync send(message: JsonRpcMessage, { signal }: McpTransportSendOptions = {}): Promise<void> {\n\t\tif (!this.started || this.closed) throw new McpConnectionClosedError();\n\t\tconst response = await this.authorizedFetch(\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\theaders: { accept: \"application/json, text/event-stream\", \"content-type\": \"application/json\" },\n\t\t\t\tbody: JSON.stringify(message),\n\t\t\t},\n\t\t\tsignal,\n\t\t);\n\t\tawait this.checkResponse(response);\n\t\tthis.captureSession(response);\n\n\t\tif (!isJsonRpcRequest(message)) {\n\t\t\t// Notifications and responses are acknowledged with 202 and carry no reply; ignore any body.\n\t\t\tawait discard(response);\n\t\t\t// The server-to-client stream may only open once the session is initialized.\n\t\t\tif (\"method\" in message && message.method === \"notifications/initialized\") this.startGetStream();\n\t\t\treturn;\n\t\t}\n\t\tif (response.status === 202 || response.status === 204) {\n\t\t\tthrow new McpHttpError(response.status, `MCP server accepted request ${message.method} without a response`);\n\t\t}\n\t\tconst type = contentType(response);\n\t\tif (type === \"application/json\") {\n\t\t\tconst body: unknown = await response.json();\n\t\t\tfor (const item of Array.isArray(body) ? body : [body]) this.emitMessage(parseJsonRpcMessage(item));\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"text/event-stream\" && response.body) {\n\t\t\tvoid this.consumeResponseStream(response.body, message.id);\n\t\t\treturn;\n\t\t}\n\t\tawait discard(response);\n\t\tthrow new McpHttpError(response.status, `Unsupported MCP response content type: ${type ?? \"missing\"}`);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tthis.controller.abort();\n\t\tif (this.started && this.sessionIdValue) {\n\t\t\t// Best effort: the session expires on the server anyway. The auth provider may refresh tokens\n\t\t\t// over the network, so it is not asked here and closing never waits for a refresh.\n\t\t\ttry {\n\t\t\t\tconst response = await this.fetch(this.url, {\n\t\t\t\t\tmethod: \"DELETE\",\n\t\t\t\t\theaders: this.buildHeaders({}, this.lastToken),\n\t\t\t\t\tsignal: AbortSignal.timeout(1_000),\n\t\t\t\t});\n\t\t\t\tawait discard(response);\n\t\t\t} catch {}\n\t\t}\n\t\tthis.emitClose();\n\t}\n\n\t/**\n\t * Fetch with auth headers. A 401 (or a 403 asking for more scope) is handed to the auth provider\n\t * once, and the request is retried with whatever credentials it left behind.\n\t */\n\tprivate async authorizedFetch(\n\t\tmethod: \"GET\" | \"POST\",\n\t\tinit: { headers: Record<string, string>; body?: string },\n\t\tsignal?: AbortSignal,\n\t): Promise<Response> {\n\t\tconst onUnauthorized = this.options.authProvider?.onUnauthorized?.bind(this.options.authProvider);\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tconst { headers, token } = await this.headers(init.headers);\n\t\t\tif (signal?.aborted) throw new McpAbortError();\n\t\t\tconst response = await this.fetch(this.url, {\n\t\t\t\tmethod,\n\t\t\t\theaders,\n\t\t\t\tbody: init.body,\n\t\t\t\tsignal: this.controller.signal,\n\t\t\t});\n\t\t\tif (attempt > 0 || !onUnauthorized || !needsAuthorization(response)) return response;\n\t\t\ttry {\n\t\t\t\tawait onUnauthorized({ response, serverUrl: this.url, fetch: this.fetch, token });\n\t\t\t} finally {\n\t\t\t\tawait discard(response);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async headers(extra: Record<string, string> = {}): Promise<{ headers: Headers; token?: string }> {\n\t\tconst token = await this.options.authProvider?.token();\n\t\tthis.lastToken = token;\n\t\treturn { headers: this.buildHeaders(extra, token), ...(token ? { token } : {}) };\n\t}\n\n\tprivate buildHeaders(extra: Record<string, string>, token: string | undefined): Headers {\n\t\tconst headers = new Headers(this.options.headers);\n\t\tfor (const [name, value] of Object.entries(extra)) headers.set(name, value);\n\t\tif (this.sessionIdValue) headers.set(\"Mcp-Session-Id\", this.sessionIdValue);\n\t\tif (this.protocolVersion) headers.set(\"MCP-Protocol-Version\", this.protocolVersion);\n\t\tif (token) headers.set(\"Authorization\", `Bearer ${token}`);\n\t\treturn headers;\n\t}\n\n\tprivate captureSession(response: Response): void {\n\t\tconst sessionId = response.headers.get(\"mcp-session-id\");\n\t\tif (sessionId) this.sessionIdValue = sessionId;\n\t}\n\n\tprivate async checkResponse(response: Response): Promise<void> {\n\t\tif (response.ok) return;\n\t\tconst body = (await response.text().catch(() => \"\")).slice(0, MAX_ERROR_BODY_BYTES);\n\t\tif (response.status === 401) throw new McpAuthRequiredError(response, body);\n\t\tif (response.status === 404 && this.sessionIdValue) throw new McpSessionExpiredError(body);\n\t\tthrow new McpHttpError(response.status, describeHttpFailure(response.status, body), body);\n\t}\n\n\tprivate async consumeSse(\n\t\tstream: ReadableStream<Uint8Array>,\n\t\tcursor: StreamCursor,\n\t\tonMessage?: (message: JsonRpcMessage) => void,\n\t): Promise<void> {\n\t\tawait consumeSseStream(stream, {\n\t\t\tmaxEventBytes: this.options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES,\n\t\t\tonId: (id) => {\n\t\t\t\tcursor.lastEventId = id;\n\t\t\t},\n\t\t\tonRetry: (delayMs) => {\n\t\t\t\tcursor.retryMs = delayMs;\n\t\t\t},\n\t\t\tonEvent: (event) => {\n\t\t\t\tcursor.received = true;\n\t\t\t\t// Events without data prime resumption; other event types are not JSON-RPC.\n\t\t\t\tif (!event.data.trim() || (event.event !== undefined && event.event !== \"message\")) return;\n\t\t\t\tlet message: JsonRpcMessage;\n\t\t\t\ttry {\n\t\t\t\t\tmessage = parseJsonRpcMessage(JSON.parse(event.data));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.emitError(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonMessage?.(message);\n\t\t\t\tthis.emitMessage(message);\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Read the SSE stream answering one request. When the stream ends or breaks before the response\n\t * arrives and the server assigned event IDs, resume it with GET and `Last-Event-ID`, as the\n\t * server may close response streams at will. Otherwise only this request fails.\n\t */\n\tprivate async consumeResponseStream(body: ReadableStream<Uint8Array>, requestId: JsonRpcId): Promise<void> {\n\t\tconst cursor: StreamCursor = { lastEventId: undefined, retryMs: undefined, received: false };\n\t\tlet answered = false;\n\t\tconst onMessage = (message: JsonRpcMessage) => {\n\t\t\tif (isJsonRpcResponse(message) && message.id === requestId) answered = true;\n\t\t};\n\t\tlet stream: ReadableStream<Uint8Array> | undefined = body;\n\t\tlet failure: unknown;\n\t\tfor (let attempt = 0; ; ) {\n\t\t\tif (stream) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.consumeSse(stream, cursor, onMessage);\n\t\t\t\t\tfailure = undefined;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tfailure = error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (answered || this.closed) return;\n\t\t\tif (failure !== undefined && !this.isRetryable(failure)) break;\n\t\t\tif (cursor.lastEventId === undefined || attempt >= this.maxRetries()) break;\n\t\t\tif (cursor.received) attempt = 0;\n\t\t\tcursor.received = false;\n\t\t\tif (!(await this.sleep(this.reconnectDelay(attempt++, cursor.retryMs)))) return;\n\t\t\ttry {\n\t\t\t\tstream = await this.openSseStream(cursor.lastEventId);\n\t\t\t} catch (error) {\n\t\t\t\tfailure = error;\n\t\t\t\tif (!this.isRetryable(error)) break;\n\t\t\t\tstream = undefined;\n\t\t\t}\n\t\t}\n\t\tif (this.closed) return;\n\t\tconst reason = failure === undefined ? \"stream ended without a response\" : toError(failure).message;\n\t\tthis.emitMessage({\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid: requestId,\n\t\t\terror: { code: JSON_RPC_ERROR_CODES.internalError, message: `MCP response stream failed: ${reason}` },\n\t\t});\n\t}\n\n\tprivate startGetStream(): void {\n\t\tif (this.options.openGetStream === false || this.getStreamStarted || this.closed) return;\n\t\tthis.getStreamStarted = true;\n\t\tvoid this.runGetStream();\n\t}\n\n\t/** Keep the server-to-client stream open, reconnecting with backoff when it drops. */\n\tprivate async runGetStream(): Promise<void> {\n\t\tconst cursor: StreamCursor = { lastEventId: undefined, retryMs: undefined, received: false };\n\t\tfor (let attempt = 0; !this.closed; ) {\n\t\t\ttry {\n\t\t\t\tconst stream = await this.openSseStream(cursor.lastEventId);\n\t\t\t\t// The server does not offer a GET stream.\n\t\t\t\tif (!stream) return;\n\t\t\t\tconst openedAt = Date.now();\n\t\t\t\tawait this.consumeSse(stream, cursor);\n\t\t\t\t// A stream that stayed up for a while counts as healthy, even if it was idle.\n\t\t\t\tif (cursor.received || Date.now() - openedAt > this.maxDelay()) attempt = 0;\n\t\t\t} catch (error) {\n\t\t\t\tif (this.closed) return;\n\t\t\t\tif (!this.isRetryable(error)) {\n\t\t\t\t\tthis.emitError(error);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcursor.received = false;\n\t\t\tif (attempt >= this.maxRetries()) {\n\t\t\t\tthis.emitError(new Error(\"MCP server-to-client stream dropped and could not be reopened\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!(await this.sleep(this.reconnectDelay(attempt++, cursor.retryMs)))) return;\n\t\t}\n\t}\n\n\t/** Open a GET SSE stream. Resolves to undefined when the server answers 405 (no GET stream). */\n\tprivate async openSseStream(lastEventId: string | undefined): Promise<ReadableStream<Uint8Array> | undefined> {\n\t\tconst response = await this.authorizedFetch(\"GET\", {\n\t\t\theaders: {\n\t\t\t\taccept: \"text/event-stream\",\n\t\t\t\t...(lastEventId === undefined ? {} : { \"last-event-id\": lastEventId }),\n\t\t\t},\n\t\t});\n\t\tif (response.status === 405) {\n\t\t\tawait discard(response);\n\t\t\treturn undefined;\n\t\t}\n\t\tawait this.checkResponse(response);\n\t\tthis.captureSession(response);\n\t\tconst type = contentType(response);\n\t\tif (type !== \"text/event-stream\" || !response.body) {\n\t\t\tawait discard(response);\n\t\t\tthrow new McpHttpError(response.status, `Unsupported MCP GET response content type: ${type ?? \"missing\"}`);\n\t\t}\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Network failures and transient statuses are retried; auth, session, and protocol errors are not.\n\t * `fetch` reports network failures, including a connection dropped mid-body, as `TypeError`.\n\t */\n\tprivate isRetryable(error: unknown): boolean {\n\t\tif (error instanceof McpHttpError) return isTransientStatus(error.status);\n\t\tif (error instanceof TypeError) return true;\n\t\tconst code = (error as { code?: unknown } | undefined)?.code;\n\t\treturn typeof code === \"string\" && (code.startsWith(\"E\") || code.startsWith(\"UND_ERR\"));\n\t}\n\n\tprivate reconnectDelay(attempt: number, serverDelayMs: number | undefined): number {\n\t\tif (serverDelayMs !== undefined) return serverDelayMs;\n\t\tconst initial = this.options.reconnect?.initialDelayMs ?? DEFAULT_RECONNECT_INITIAL_DELAY_MS;\n\t\treturn Math.min(initial * 2 ** attempt, this.maxDelay());\n\t}\n\n\tprivate maxDelay(): number {\n\t\treturn this.options.reconnect?.maxDelayMs ?? DEFAULT_RECONNECT_MAX_DELAY_MS;\n\t}\n\n\tprivate maxRetries(): number {\n\t\treturn this.options.reconnect?.maxRetries ?? DEFAULT_RECONNECT_MAX_RETRIES;\n\t}\n\n\t/** Resolves false when the transport closed while waiting. */\n\tprivate sleep(ms: number): Promise<boolean> {\n\t\tconst signal = this.controller.signal;\n\t\tif (signal.aborted) return Promise.resolve(false);\n\t\treturn new Promise((resolve) => {\n\t\t\tconst onAbort = () => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(false);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(true);\n\t\t\t}, ms);\n\t\t\t// A reconnect wait alone does not keep the process alive.\n\t\t\ttimer.unref?.();\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t});\n\t}\n}\n"]}
@@ -3,9 +3,12 @@ export declare const DEFAULT_MAX_MESSAGE_BYTES: number;
3
3
  export type McpTransportMessageListener = (message: JsonRpcMessage) => void;
4
4
  export type McpTransportErrorListener = (error: Error) => void;
5
5
  export type McpTransportCloseListener = () => void;
6
+ export interface McpTransportSendOptions {
7
+ signal?: AbortSignal;
8
+ }
6
9
  export interface McpTransport {
7
10
  start(): Promise<void>;
8
- send(message: JsonRpcMessage): Promise<void>;
11
+ send(message: JsonRpcMessage, options?: McpTransportSendOptions): Promise<void>;
9
12
  close(): Promise<void>;
10
13
  onMessage(listener: McpTransportMessageListener): () => void;
11
14
  onError(listener: McpTransportErrorListener): () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/transports/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,wBAAwB,CAAC;AAEtE,eAAO,MAAM,yBAAyB,QAAmB,CAAC;AAE1D,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;AAC5E,MAAM,MAAM,yBAAyB,GAAG,CAAC,KAAK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