@bastani/atomic 0.9.25-alpha.3 → 0.9.25-alpha.4

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 (178) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/CHANGELOG.md +30 -0
  4. package/dist/builtin/mcp/OAUTH.md +59 -269
  5. package/dist/builtin/mcp/README.md +58 -345
  6. package/dist/builtin/mcp/index.bundle.mjs +4 -28073
  7. package/dist/builtin/mcp/native-client-licenses/LICENSES/modelcontextprotocol-typescript-sdk.txt +21 -0
  8. package/dist/builtin/mcp/native-client-licenses/NOTICE +30 -0
  9. package/dist/builtin/mcp/package.json +4 -25
  10. package/dist/builtin/subagents/package.json +1 -1
  11. package/dist/builtin/web-access/package.json +1 -1
  12. package/dist/builtin/workflows/package.json +1 -1
  13. package/dist/cli/args.d.ts.map +1 -1
  14. package/dist/cli/args.js +2 -1
  15. package/dist/cli/args.js.map +1 -1
  16. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  17. package/dist/core/agent-session-extension-bindings.js +87 -5
  18. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  19. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  20. package/dist/core/agent-session-tool-registry.js +6 -3
  21. package/dist/core/agent-session-tool-registry.js.map +1 -1
  22. package/dist/core/extensions/context-types.d.ts +3 -1
  23. package/dist/core/extensions/context-types.d.ts.map +1 -1
  24. package/dist/core/extensions/context-types.js.map +1 -1
  25. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  26. package/dist/core/extensions/loader-api.js +4 -0
  27. package/dist/core/extensions/loader-api.js.map +1 -1
  28. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  29. package/dist/core/extensions/loader-virtual-modules.js +3 -0
  30. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  31. package/dist/core/mcp-child-policy.d.ts +11 -0
  32. package/dist/core/mcp-child-policy.d.ts.map +1 -0
  33. package/dist/core/mcp-child-policy.js +31 -0
  34. package/dist/core/mcp-child-policy.js.map +1 -0
  35. package/dist/core/mcp-servers.d.ts +32 -26
  36. package/dist/core/mcp-servers.d.ts.map +1 -1
  37. package/dist/core/mcp-servers.js +148 -1
  38. package/dist/core/mcp-servers.js.map +1 -1
  39. package/dist/core/package-manager-manifest.js.map +1 -1
  40. package/dist/core/package-manager-mcp-servers.js +1 -1
  41. package/dist/core/package-manager-mcp-servers.js.map +1 -1
  42. package/dist/core/sdk.js +10 -1
  43. package/dist/core/sdk.js.map +1 -1
  44. package/dist/core/tools/truncate.d.ts +8 -0
  45. package/dist/core/tools/truncate.d.ts.map +1 -1
  46. package/dist/core/tools/truncate.js +24 -0
  47. package/dist/core/tools/truncate.js.map +1 -1
  48. package/dist/extensions/mcp/cli.d.ts +21 -0
  49. package/dist/extensions/mcp/cli.d.ts.map +1 -0
  50. package/dist/extensions/mcp/cli.js +500 -0
  51. package/dist/extensions/mcp/cli.js.map +1 -0
  52. package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
  53. package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
  54. package/dist/extensions/mcp/cli.lazy.js +3 -0
  55. package/dist/extensions/mcp/cli.lazy.js.map +1 -0
  56. package/dist/extensions/mcp/client/auth-provider.d.ts +15 -0
  57. package/dist/extensions/mcp/client/auth-provider.d.ts.map +1 -0
  58. package/dist/extensions/mcp/client/auth-provider.js +2 -0
  59. package/dist/extensions/mcp/client/auth-provider.js.map +1 -0
  60. package/dist/extensions/mcp/client/client.d.ts +89 -0
  61. package/dist/extensions/mcp/client/client.d.ts.map +1 -0
  62. package/dist/extensions/mcp/client/client.js +457 -0
  63. package/dist/extensions/mcp/client/client.js.map +1 -0
  64. package/dist/extensions/mcp/client/index.d.ts +9 -0
  65. package/dist/extensions/mcp/client/index.d.ts.map +1 -0
  66. package/dist/extensions/mcp/client/index.js +7 -0
  67. package/dist/extensions/mcp/client/index.js.map +1 -0
  68. package/dist/extensions/mcp/client/oauth/callback.d.ts +42 -0
  69. package/dist/extensions/mcp/client/oauth/callback.d.ts.map +1 -0
  70. package/dist/extensions/mcp/client/oauth/callback.js +106 -0
  71. package/dist/extensions/mcp/client/oauth/callback.js.map +1 -0
  72. package/dist/extensions/mcp/client/oauth/discovery.d.ts +27 -0
  73. package/dist/extensions/mcp/client/oauth/discovery.d.ts.map +1 -0
  74. package/dist/extensions/mcp/client/oauth/discovery.js +153 -0
  75. package/dist/extensions/mcp/client/oauth/discovery.js.map +1 -0
  76. package/dist/extensions/mcp/client/oauth/errors.d.ts +24 -0
  77. package/dist/extensions/mcp/client/oauth/errors.d.ts.map +1 -0
  78. package/dist/extensions/mcp/client/oauth/errors.js +46 -0
  79. package/dist/extensions/mcp/client/oauth/errors.js.map +1 -0
  80. package/dist/extensions/mcp/client/oauth/flow.d.ts +82 -0
  81. package/dist/extensions/mcp/client/oauth/flow.d.ts.map +1 -0
  82. package/dist/extensions/mcp/client/oauth/flow.js +292 -0
  83. package/dist/extensions/mcp/client/oauth/flow.js.map +1 -0
  84. package/dist/extensions/mcp/client/oauth/index.d.ts +7 -0
  85. package/dist/extensions/mcp/client/oauth/index.d.ts.map +1 -0
  86. package/dist/extensions/mcp/client/oauth/index.js +6 -0
  87. package/dist/extensions/mcp/client/oauth/index.js.map +1 -0
  88. package/dist/extensions/mcp/client/oauth/provider.d.ts +59 -0
  89. package/dist/extensions/mcp/client/oauth/provider.d.ts.map +1 -0
  90. package/dist/extensions/mcp/client/oauth/provider.js +116 -0
  91. package/dist/extensions/mcp/client/oauth/provider.js.map +1 -0
  92. package/dist/extensions/mcp/client/oauth/types.d.ts +77 -0
  93. package/dist/extensions/mcp/client/oauth/types.d.ts.map +1 -0
  94. package/dist/extensions/mcp/client/oauth/types.js +109 -0
  95. package/dist/extensions/mcp/client/oauth/types.js.map +1 -0
  96. package/dist/extensions/mcp/client/protocol/content.d.ts +82 -0
  97. package/dist/extensions/mcp/client/protocol/content.d.ts.map +1 -0
  98. package/dist/extensions/mcp/client/protocol/content.js +41 -0
  99. package/dist/extensions/mcp/client/protocol/content.js.map +1 -0
  100. package/dist/extensions/mcp/client/protocol/jsonrpc.d.ts +59 -0
  101. package/dist/extensions/mcp/client/protocol/jsonrpc.d.ts.map +1 -0
  102. package/dist/extensions/mcp/client/protocol/jsonrpc.js +67 -0
  103. package/dist/extensions/mcp/client/protocol/jsonrpc.js.map +1 -0
  104. package/dist/extensions/mcp/client/protocol/types.d.ts +123 -0
  105. package/dist/extensions/mcp/client/protocol/types.d.ts.map +1 -0
  106. package/dist/extensions/mcp/client/protocol/types.js +7 -0
  107. package/dist/extensions/mcp/client/protocol/types.js.map +1 -0
  108. package/dist/extensions/mcp/client/testing/index.d.ts +2 -0
  109. package/dist/extensions/mcp/client/testing/index.d.ts.map +1 -0
  110. package/dist/extensions/mcp/client/testing/index.js +2 -0
  111. package/dist/extensions/mcp/client/testing/index.js.map +1 -0
  112. package/dist/extensions/mcp/client/transports/in-memory.d.ts +19 -0
  113. package/dist/extensions/mcp/client/transports/in-memory.d.ts.map +1 -0
  114. package/dist/extensions/mcp/client/transports/in-memory.js +50 -0
  115. package/dist/extensions/mcp/client/transports/in-memory.js.map +1 -0
  116. package/dist/extensions/mcp/client/transports/stdio.d.ts +32 -0
  117. package/dist/extensions/mcp/client/transports/stdio.d.ts.map +1 -0
  118. package/dist/extensions/mcp/client/transports/stdio.js +201 -0
  119. package/dist/extensions/mcp/client/transports/stdio.js.map +1 -0
  120. package/dist/extensions/mcp/client/transports/streamable-http.d.ts +96 -0
  121. package/dist/extensions/mcp/client/transports/streamable-http.d.ts.map +1 -0
  122. package/dist/extensions/mcp/client/transports/streamable-http.js +456 -0
  123. package/dist/extensions/mcp/client/transports/streamable-http.js.map +1 -0
  124. package/dist/extensions/mcp/client/transports/transport.d.ts +28 -0
  125. package/dist/extensions/mcp/client/transports/transport.d.ts.map +1 -0
  126. package/dist/extensions/mcp/client/transports/transport.js +38 -0
  127. package/dist/extensions/mcp/client/transports/transport.js.map +1 -0
  128. package/dist/extensions/mcp/config.d.ts +72 -0
  129. package/dist/extensions/mcp/config.d.ts.map +1 -0
  130. package/dist/extensions/mcp/config.js +158 -0
  131. package/dist/extensions/mcp/config.js.map +1 -0
  132. package/dist/extensions/mcp/index.d.ts +76 -0
  133. package/dist/extensions/mcp/index.d.ts.map +1 -0
  134. package/dist/extensions/mcp/index.js +1119 -0
  135. package/dist/extensions/mcp/index.js.map +1 -0
  136. package/dist/extensions/mcp/log.d.ts +16 -0
  137. package/dist/extensions/mcp/log.d.ts.map +1 -0
  138. package/dist/extensions/mcp/log.js +66 -0
  139. package/dist/extensions/mcp/log.js.map +1 -0
  140. package/dist/extensions/mcp/oauth.d.ts +103 -0
  141. package/dist/extensions/mcp/oauth.d.ts.map +1 -0
  142. package/dist/extensions/mcp/oauth.js +382 -0
  143. package/dist/extensions/mcp/oauth.js.map +1 -0
  144. package/dist/extensions/mcp/resources.d.ts +43 -0
  145. package/dist/extensions/mcp/resources.d.ts.map +1 -0
  146. package/dist/extensions/mcp/resources.js +262 -0
  147. package/dist/extensions/mcp/resources.js.map +1 -0
  148. package/dist/extensions/mcp/runtime.d.ts +104 -0
  149. package/dist/extensions/mcp/runtime.d.ts.map +1 -0
  150. package/dist/extensions/mcp/runtime.js +546 -0
  151. package/dist/extensions/mcp/runtime.js.map +1 -0
  152. package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
  153. package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
  154. package/dist/extensions/mcp/runtime.lazy.js +3 -0
  155. package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
  156. package/dist/extensions/mcp/tools.d.ts +84 -0
  157. package/dist/extensions/mcp/tools.d.ts.map +1 -0
  158. package/dist/extensions/mcp/tools.js +251 -0
  159. package/dist/extensions/mcp/tools.js.map +1 -0
  160. package/dist/extensions/mcp/ui.d.ts +60 -0
  161. package/dist/extensions/mcp/ui.d.ts.map +1 -0
  162. package/dist/extensions/mcp/ui.js +175 -0
  163. package/dist/extensions/mcp/ui.js.map +1 -0
  164. package/dist/index.d.ts +5 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +5 -0
  167. package/dist/index.js.map +1 -1
  168. package/dist/main.d.ts.map +1 -1
  169. package/dist/main.js +7 -0
  170. package/dist/main.js.map +1 -1
  171. package/docs/extensions/api-reference.md +3 -3
  172. package/docs/extensions.md +8 -8
  173. package/docs/mcp-servers.md +153 -79
  174. package/docs/packages/authoring.md +2 -2
  175. package/npm-shrinkwrap.json +32 -32
  176. package/package.json +3 -3
  177. package/dist/builtin/mcp/app-bridge.bundle.js +0 -67
  178. package/dist/builtin/mcp/xdg-open +0 -1267
@@ -0,0 +1,9 @@
1
+ export type { AuthProvider, McpFetch, UnauthorizedContext } from "./auth-provider.js";
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";
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
+ 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
+ export { StdioTransport, type StdioTransportOptions } from "./transports/stdio.js";
7
+ export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, type StreamableHttpTransportOptions, } from "./transports/streamable-http.js";
8
+ export type { McpTransport, McpTransportCloseListener, McpTransportErrorListener, McpTransportMessageListener, } from "./transports/transport.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ export { McpClient } from "./client.js";
2
+ export { toLlmContent, } from "./protocol/content.js";
3
+ export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.js";
4
+ export { LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, } from "./protocol/types.js";
5
+ export { StdioTransport } from "./transports/stdio.js";
6
+ export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, } from "./transports/streamable-http.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,42 @@
1
+ export interface OAuthCallback {
2
+ code: string;
3
+ state: string;
4
+ iss?: string;
5
+ }
6
+ /** Outcome shown on the browser page after the redirect. */
7
+ export type OAuthCallbackPage = {
8
+ ok: true;
9
+ } | {
10
+ ok: false;
11
+ message: string;
12
+ details?: string;
13
+ };
14
+ export interface OAuthCallbackServerOptions {
15
+ /** Address to listen on. Default: `127.0.0.1`. */
16
+ host?: string;
17
+ /**
18
+ * Host name in `redirectUrl`, for example `localhost` for a client registered with it while
19
+ * listening on `127.0.0.1`. Default: `host`.
20
+ */
21
+ redirectHost?: string;
22
+ port?: number;
23
+ path?: string;
24
+ timeoutMs?: number;
25
+ /** Render the browser page as HTML. Default: a plain-text message. */
26
+ renderPage?: (page: OAuthCallbackPage) => string;
27
+ }
28
+ export declare class OAuthCallbackServer {
29
+ readonly redirectUrl: string;
30
+ private server;
31
+ private path;
32
+ private timeoutMs;
33
+ private renderPage;
34
+ private pending;
35
+ private constructor();
36
+ static listen(options?: OAuthCallbackServerOptions): Promise<OAuthCallbackServer>;
37
+ waitForCallback(state: string): Promise<OAuthCallback>;
38
+ close(): Promise<void>;
39
+ private reply;
40
+ private handle;
41
+ }
42
+ //# sourceMappingURL=callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":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
+ function plainText(page) {
3
+ if (page.ok)
4
+ return "Authorization complete. You may close this window.";
5
+ return page.details ? `${page.message}\n\n${page.details}` : page.message;
6
+ }
7
+ export class OAuthCallbackServer {
8
+ redirectUrl;
9
+ server;
10
+ path;
11
+ timeoutMs;
12
+ renderPage;
13
+ pending = new Map();
14
+ constructor(server, redirectUrl, path, timeoutMs, renderPage) {
15
+ this.server = server;
16
+ this.redirectUrl = redirectUrl;
17
+ this.path = path;
18
+ this.timeoutMs = timeoutMs;
19
+ this.renderPage = renderPage;
20
+ }
21
+ static async listen(options = {}) {
22
+ const host = options.host ?? "127.0.0.1";
23
+ const redirectHost = options.redirectHost ?? host;
24
+ const path = options.path ?? "/callback";
25
+ let instance;
26
+ const server = createServer((request, response) => instance?.handle(request.url ?? "/", response));
27
+ await new Promise((resolve, reject) => {
28
+ server.once("error", reject);
29
+ server.listen(options.port ?? 0, host, () => {
30
+ server.off("error", reject);
31
+ resolve();
32
+ });
33
+ });
34
+ const address = server.address();
35
+ if (!address || typeof address === "string")
36
+ throw new Error("OAuth callback server did not bind to TCP");
37
+ instance = new OAuthCallbackServer(server, `http://${redirectHost.includes(":") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`, path, options.timeoutMs ?? 5 * 60_000, options.renderPage);
38
+ return instance;
39
+ }
40
+ waitForCallback(state) {
41
+ if (this.pending.has(state))
42
+ throw new Error("OAuth state is already pending");
43
+ return new Promise((resolve, reject) => {
44
+ const timer = setTimeout(() => {
45
+ this.pending.delete(state);
46
+ reject(new Error("OAuth callback timed out"));
47
+ }, this.timeoutMs);
48
+ this.pending.set(state, { resolve, reject, timer });
49
+ });
50
+ }
51
+ async close() {
52
+ for (const pending of this.pending.values()) {
53
+ clearTimeout(pending.timer);
54
+ pending.reject(new Error("OAuth callback server closed"));
55
+ }
56
+ this.pending.clear();
57
+ await new Promise((resolve, reject) => {
58
+ this.server.close((error) => (error ? reject(error) : resolve()));
59
+ });
60
+ }
61
+ reply(response, status, page) {
62
+ if (this.renderPage) {
63
+ response.writeHead(status, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
64
+ response.end(this.renderPage(page));
65
+ }
66
+ else {
67
+ response.writeHead(status, { "content-type": "text/plain; charset=utf-8" }).end(plainText(page));
68
+ }
69
+ }
70
+ handle(rawUrl, response) {
71
+ const url = new URL(rawUrl, this.redirectUrl);
72
+ if (url.pathname !== this.path) {
73
+ this.reply(response, 404, { ok: false, message: "Not found" });
74
+ return;
75
+ }
76
+ const state = url.searchParams.get("state");
77
+ const pending = state ? this.pending.get(state) : undefined;
78
+ if (!state || !pending) {
79
+ this.reply(response, 400, { ok: false, message: "Invalid or expired OAuth state" });
80
+ return;
81
+ }
82
+ clearTimeout(pending.timer);
83
+ this.pending.delete(state);
84
+ const error = url.searchParams.get("error");
85
+ if (error) {
86
+ const description = url.searchParams.get("error_description") ?? error;
87
+ pending.reject(new Error(description));
88
+ this.reply(response, 200, {
89
+ ok: false,
90
+ message: "Authorization failed. You may close this window.",
91
+ details: description,
92
+ });
93
+ return;
94
+ }
95
+ const code = url.searchParams.get("code");
96
+ if (!code) {
97
+ pending.reject(new Error("OAuth callback did not include an authorization code"));
98
+ this.reply(response, 400, { ok: false, message: "Missing authorization code" });
99
+ return;
100
+ }
101
+ const iss = url.searchParams.get("iss");
102
+ pending.resolve({ code, state, ...(iss ? { iss } : {}) });
103
+ this.reply(response, 200, { ok: true });
104
+ }
105
+ }
106
+ //# sourceMappingURL=callback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoC,MAAM,WAAW,CAAC;AA0B3E,SAAS,SAAS,CAAC,IAAuB;IACzC,IAAI,IAAI,CAAC,EAAE;QAAE,OAAO,oDAAoD,CAAC;IACzE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,OAAO,IAAI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AQ,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAC;YAChF,OAAO;QACR,CAAC;QACD,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;CACD","sourcesContent":["import { createServer, type Server, type ServerResponse } from \"node:http\";\n\nexport interface OAuthCallback {\n\tcode: string;\n\tstate: string;\n\tiss?: string;\n}\n\n/** Outcome shown on the browser page after the redirect. */\nexport type OAuthCallbackPage = { ok: true } | { ok: false; message: string; details?: string };\n\nexport interface OAuthCallbackServerOptions {\n\t/** Address to listen on. Default: `127.0.0.1`. */\n\thost?: string;\n\t/**\n\t * Host name in `redirectUrl`, for example `localhost` for a client registered with it while\n\t * listening on `127.0.0.1`. Default: `host`.\n\t */\n\tredirectHost?: string;\n\tport?: number;\n\tpath?: string;\n\ttimeoutMs?: number;\n\t/** Render the browser page as HTML. Default: a plain-text message. */\n\trenderPage?: (page: OAuthCallbackPage) => string;\n}\n\nfunction plainText(page: OAuthCallbackPage): string {\n\tif (page.ok) return \"Authorization complete. You may close this window.\";\n\treturn page.details ? `${page.message}\\n\\n${page.details}` : page.message;\n}\n\nexport class OAuthCallbackServer {\n\treadonly redirectUrl: string;\n\tprivate server: Server;\n\tprivate path: string;\n\tprivate timeoutMs: number;\n\tprivate renderPage: ((page: OAuthCallbackPage) => string) | undefined;\n\tprivate pending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tresolve: (callback: OAuthCallback) => void;\n\t\t\treject: (error: Error) => void;\n\t\t\ttimer: ReturnType<typeof setTimeout>;\n\t\t}\n\t>();\n\n\tprivate constructor(\n\t\tserver: Server,\n\t\tredirectUrl: string,\n\t\tpath: string,\n\t\ttimeoutMs: number,\n\t\trenderPage: ((page: OAuthCallbackPage) => string) | undefined,\n\t) {\n\t\tthis.server = server;\n\t\tthis.redirectUrl = redirectUrl;\n\t\tthis.path = path;\n\t\tthis.timeoutMs = timeoutMs;\n\t\tthis.renderPage = renderPage;\n\t}\n\n\tstatic async listen(options: OAuthCallbackServerOptions = {}): Promise<OAuthCallbackServer> {\n\t\tconst host = options.host ?? \"127.0.0.1\";\n\t\tconst redirectHost = options.redirectHost ?? host;\n\t\tconst path = options.path ?? \"/callback\";\n\t\tlet instance: OAuthCallbackServer | undefined;\n\t\tconst server = createServer((request, response) => instance?.handle(request.url ?? \"/\", response));\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tserver.once(\"error\", reject);\n\t\t\tserver.listen(options.port ?? 0, host, () => {\n\t\t\t\tserver.off(\"error\", reject);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t\tconst address = server.address();\n\t\tif (!address || typeof address === \"string\") throw new Error(\"OAuth callback server did not bind to TCP\");\n\t\tinstance = new OAuthCallbackServer(\n\t\t\tserver,\n\t\t\t`http://${redirectHost.includes(\":\") ? `[${redirectHost}]` : redirectHost}:${address.port}${path}`,\n\t\t\tpath,\n\t\t\toptions.timeoutMs ?? 5 * 60_000,\n\t\t\toptions.renderPage,\n\t\t);\n\t\treturn instance;\n\t}\n\n\twaitForCallback(state: string): Promise<OAuthCallback> {\n\t\tif (this.pending.has(state)) throw new Error(\"OAuth state is already pending\");\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pending.delete(state);\n\t\t\t\treject(new Error(\"OAuth callback timed out\"));\n\t\t\t}, this.timeoutMs);\n\t\t\tthis.pending.set(state, { resolve, reject, timer });\n\t\t});\n\t}\n\n\tasync close(): Promise<void> {\n\t\tfor (const pending of this.pending.values()) {\n\t\t\tclearTimeout(pending.timer);\n\t\t\tpending.reject(new Error(\"OAuth callback server closed\"));\n\t\t}\n\t\tthis.pending.clear();\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? reject(error) : resolve()));\n\t\t});\n\t}\n\n\tprivate reply(response: ServerResponse, status: number, page: OAuthCallbackPage): void {\n\t\tif (this.renderPage) {\n\t\t\tresponse.writeHead(status, { \"content-type\": \"text/html; charset=utf-8\", \"cache-control\": \"no-store\" });\n\t\t\tresponse.end(this.renderPage(page));\n\t\t} else {\n\t\t\tresponse.writeHead(status, { \"content-type\": \"text/plain; charset=utf-8\" }).end(plainText(page));\n\t\t}\n\t}\n\n\tprivate handle(rawUrl: string, response: ServerResponse): void {\n\t\tconst url = new URL(rawUrl, this.redirectUrl);\n\t\tif (url.pathname !== this.path) {\n\t\t\tthis.reply(response, 404, { ok: false, message: \"Not found\" });\n\t\t\treturn;\n\t\t}\n\t\tconst state = url.searchParams.get(\"state\");\n\t\tconst pending = state ? this.pending.get(state) : undefined;\n\t\tif (!state || !pending) {\n\t\t\tthis.reply(response, 400, { ok: false, message: \"Invalid or expired OAuth state\" });\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(pending.timer);\n\t\tthis.pending.delete(state);\n\t\tconst error = url.searchParams.get(\"error\");\n\t\tif (error) {\n\t\t\tconst description = url.searchParams.get(\"error_description\") ?? error;\n\t\t\tpending.reject(new Error(description));\n\t\t\tthis.reply(response, 200, {\n\t\t\t\tok: false,\n\t\t\t\tmessage: \"Authorization failed. You may close this window.\",\n\t\t\t\tdetails: description,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst code = url.searchParams.get(\"code\");\n\t\tif (!code) {\n\t\t\tpending.reject(new Error(\"OAuth callback did not include an authorization code\"));\n\t\t\tthis.reply(response, 400, { ok: false, message: \"Missing authorization code\" });\n\t\t\treturn;\n\t\t}\n\t\tconst iss = url.searchParams.get(\"iss\");\n\t\tpending.resolve({ code, state, ...(iss ? { iss } : {}) });\n\t\tthis.reply(response, 200, { ok: true });\n\t}\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { McpFetch } from "../auth-provider.js";
2
+ import { type AuthorizationServerMetadata, type OAuthChallenge, type OAuthProtectedResourceMetadata, type OAuthServerInfo } from "./types.js";
3
+ export declare function parseWwwAuthenticate(header: string | null): OAuthChallenge;
4
+ export declare function discoverProtectedResourceMetadata(serverUrl: string | URL, options?: {
5
+ resourceMetadataUrl?: string | URL;
6
+ protocolVersion?: string;
7
+ fetch?: McpFetch;
8
+ }): Promise<OAuthProtectedResourceMetadata>;
9
+ export declare function buildAuthorizationServerDiscoveryUrls(authorizationServerUrl: string | URL): {
10
+ url: URL;
11
+ type: "oauth" | "oidc";
12
+ }[];
13
+ export declare function discoverAuthorizationServerMetadata(authorizationServerUrl: string | URL, options?: {
14
+ fetch?: McpFetch;
15
+ protocolVersion?: string;
16
+ skipIssuerValidation?: boolean;
17
+ }): Promise<AuthorizationServerMetadata | undefined>;
18
+ export declare function discoverOAuthServerInfo(serverUrl: string | URL, options?: {
19
+ resourceMetadataUrl?: URL;
20
+ /** Metadata document to use instead of discovery. It is trusted as configured, so its issuer is not checked. */
21
+ authorizationServerMetadataUrl?: URL;
22
+ fetch?: McpFetch;
23
+ skipIssuerValidation?: boolean;
24
+ }): Promise<OAuthServerInfo>;
25
+ export declare function resourceUrlFromServerUrl(value: string | URL): URL;
26
+ export declare function selectResource(serverUrl: string | URL, metadata?: OAuthProtectedResourceMetadata): string | undefined;
27
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/discovery.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EACN,KAAK,2BAA2B,EAChC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AAG,EAAE,QAAQ,CAAC,EAAE,8BAA8B,GAAG,MAAM,GAAG,SAAS,CAarH"}
@@ -0,0 +1,153 @@
1
+ /*
2
+ * Adapted from modelcontextprotocol/typescript-sdk v1.29.0 src/client/auth.ts.
3
+ * Copyright (c) 2024 Anthropic, PBC. Licensed under MIT; see LICENSES/.
4
+ * Modified to remove Zod/CORS shims and enforce authorization-server issuer validation.
5
+ */
6
+ import { LATEST_PROTOCOL_VERSION } from "../protocol/types.js";
7
+ import { OAuthIssuerMismatchError } from "./errors.js";
8
+ import { parseAuthorizationServerMetadata, parseProtectedResourceMetadata, } from "./types.js";
9
+ function discard(response) {
10
+ void response?.body?.cancel().catch(() => { });
11
+ }
12
+ /** 4xx and 502 mean "not here", so discovery tries the next candidate URL. */
13
+ function isDiscoveryMiss(status) {
14
+ return (status >= 400 && status < 500) || status === 502;
15
+ }
16
+ /** Path suffix for `/.well-known/<kind><path>`; empty for the root path. */
17
+ function pathSuffix(pathname) {
18
+ return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
19
+ }
20
+ function field(header, name) {
21
+ const match = header.match(new RegExp(String.raw `(?:^|[,\s])${name}=(?:"([^"]*)"|([^\s,]+))`, "i"));
22
+ // An empty value (`scope=""`) carries no information, so it counts as absent.
23
+ return match?.[1] || match?.[2] || undefined;
24
+ }
25
+ export function parseWwwAuthenticate(header) {
26
+ if (!header)
27
+ return {};
28
+ const scheme = header.trimStart().split(/\s+/, 1)[0]?.toLowerCase();
29
+ if (scheme !== "bearer" && scheme !== "dpop")
30
+ return {};
31
+ const resourceMetadata = field(header, "resource_metadata");
32
+ let resourceMetadataUrl;
33
+ if (resourceMetadata) {
34
+ try {
35
+ resourceMetadataUrl = new URL(resourceMetadata);
36
+ }
37
+ catch { }
38
+ }
39
+ return {
40
+ resourceMetadataUrl,
41
+ scope: field(header, "scope"),
42
+ error: field(header, "error"),
43
+ errorDescription: field(header, "error_description"),
44
+ };
45
+ }
46
+ async function fetchMetadata(url, fetch, protocolVersion) {
47
+ return fetch(url, {
48
+ headers: { Accept: "application/json", "MCP-Protocol-Version": protocolVersion },
49
+ });
50
+ }
51
+ export async function discoverProtectedResourceMetadata(serverUrl, options = {}) {
52
+ const server = new URL(serverUrl);
53
+ const fetch = options.fetch ?? globalThis.fetch;
54
+ const version = options.protocolVersion ?? LATEST_PROTOCOL_VERSION;
55
+ let response = await fetchMetadata(options.resourceMetadataUrl
56
+ ? new URL(options.resourceMetadataUrl)
57
+ : new URL(`/.well-known/oauth-protected-resource${pathSuffix(server.pathname)}`, server.origin), fetch, version);
58
+ if (!options.resourceMetadataUrl && server.pathname !== "/" && isDiscoveryMiss(response.status)) {
59
+ discard(response);
60
+ response = await fetchMetadata(new URL("/.well-known/oauth-protected-resource", server.origin), fetch, version);
61
+ }
62
+ if (!response.ok) {
63
+ discard(response);
64
+ throw new Error(`HTTP ${response.status} loading OAuth protected resource metadata`);
65
+ }
66
+ return parseProtectedResourceMetadata(await response.json());
67
+ }
68
+ export function buildAuthorizationServerDiscoveryUrls(authorizationServerUrl) {
69
+ const issuer = new URL(authorizationServerUrl);
70
+ const path = pathSuffix(issuer.pathname);
71
+ const urls = [
72
+ { url: new URL(`/.well-known/oauth-authorization-server${path}`, issuer.origin), type: "oauth" },
73
+ { url: new URL(`/.well-known/openid-configuration${path}`, issuer.origin), type: "oidc" },
74
+ ];
75
+ if (path)
76
+ urls.push({ url: new URL(`${path}/.well-known/openid-configuration`, issuer.origin), type: "oidc" });
77
+ return urls;
78
+ }
79
+ export async function discoverAuthorizationServerMetadata(authorizationServerUrl, options = {}) {
80
+ const fetch = options.fetch ?? globalThis.fetch;
81
+ for (const { url } of buildAuthorizationServerDiscoveryUrls(authorizationServerUrl)) {
82
+ const response = await fetchMetadata(url, fetch, options.protocolVersion ?? LATEST_PROTOCOL_VERSION);
83
+ if (!response.ok) {
84
+ discard(response);
85
+ if (isDiscoveryMiss(response.status))
86
+ continue;
87
+ throw new Error(`HTTP ${response.status} loading authorization server metadata from ${url}`);
88
+ }
89
+ const metadata = parseAuthorizationServerMetadata(await response.json());
90
+ if (!options.skipIssuerValidation) {
91
+ const expected = String(authorizationServerUrl);
92
+ // URL parsing adds a trailing slash to bare origins, so compare without one on either side.
93
+ const trim = (value) => (value.endsWith("/") ? value.slice(0, -1) : value);
94
+ if (trim(metadata.issuer) !== trim(expected))
95
+ throw new OAuthIssuerMismatchError(expected, metadata.issuer);
96
+ }
97
+ return metadata;
98
+ }
99
+ return undefined;
100
+ }
101
+ export async function discoverOAuthServerInfo(serverUrl, options = {}) {
102
+ let resourceMetadata;
103
+ try {
104
+ resourceMetadata = await discoverProtectedResourceMetadata(serverUrl, {
105
+ resourceMetadataUrl: options.resourceMetadataUrl,
106
+ fetch: options.fetch,
107
+ });
108
+ }
109
+ catch (error) {
110
+ if (error instanceof TypeError)
111
+ throw error;
112
+ }
113
+ if (options.authorizationServerMetadataUrl) {
114
+ const url = options.authorizationServerMetadataUrl;
115
+ const response = await fetchMetadata(url, options.fetch ?? globalThis.fetch, LATEST_PROTOCOL_VERSION);
116
+ if (!response.ok) {
117
+ discard(response);
118
+ throw new Error(`HTTP ${response.status} loading authorization server metadata from ${url}`);
119
+ }
120
+ const metadata = parseAuthorizationServerMetadata(await response.json());
121
+ return { authorizationServerUrl: metadata.issuer, authorizationServerMetadata: metadata, resourceMetadata };
122
+ }
123
+ const authorizationServerUrl = resourceMetadata?.authorization_servers?.[0] ?? String(new URL("/", serverUrl));
124
+ return {
125
+ authorizationServerUrl,
126
+ authorizationServerMetadata: await discoverAuthorizationServerMetadata(authorizationServerUrl, {
127
+ fetch: options.fetch,
128
+ skipIssuerValidation: options.skipIssuerValidation,
129
+ }),
130
+ resourceMetadata,
131
+ };
132
+ }
133
+ export function resourceUrlFromServerUrl(value) {
134
+ const url = new URL(value);
135
+ url.hash = "";
136
+ return url;
137
+ }
138
+ export function selectResource(serverUrl, metadata) {
139
+ if (!metadata)
140
+ return undefined;
141
+ const requested = resourceUrlFromServerUrl(serverUrl);
142
+ const configured = new URL(metadata.resource);
143
+ if (requested.origin !== configured.origin) {
144
+ throw new Error(`Protected resource ${metadata.resource} does not match MCP server ${requested}`);
145
+ }
146
+ const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : `${requested.pathname}/`;
147
+ const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : `${configured.pathname}/`;
148
+ if (!requestedPath.startsWith(configuredPath)) {
149
+ throw new Error(`Protected resource ${metadata.resource} does not match MCP server ${requested}`);
150
+ }
151
+ return metadata.resource;
152
+ }
153
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/discovery.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAKN,gCAAgC,EAChC,8BAA8B,GAC9B,MAAM,YAAY,CAAC;AAEpB,SAAS,OAAO,CAAC,QAA8B;IAC9C,KAAK,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,8EAA8E;AAC9E,SAAS,eAAe,CAAC,MAAc;IACtC,OAAO,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,MAAM,KAAK,GAAG,CAAC;AAC1D,CAAC;AAED,4EAA4E;AAC5E,SAAS,UAAU,CAAC,QAAgB;IACnC,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClE,CAAC;AAED,SAAS,KAAK,CAAC,MAAc,EAAE,IAAY;IAC1C,MAAM,KAAK,GAAG,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CAAC;IACnG,CAAC;IACD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,GAAG,CAAC;IACvG,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,QAAQ,GAAG,CAAC;IAC3G,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,QAAQ,8BAA8B,SAAS,EAAE,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAC1B,CAAC","sourcesContent":["/*\n * Adapted from modelcontextprotocol/typescript-sdk v1.29.0 src/client/auth.ts.\n * Copyright (c) 2024 Anthropic, PBC. Licensed under MIT; see LICENSES/.\n * Modified to remove Zod/CORS shims and enforce authorization-server issuer validation.\n */\n\nimport type { McpFetch } from \"../auth-provider.js\";\nimport { LATEST_PROTOCOL_VERSION } from \"../protocol/types.js\";\nimport { OAuthIssuerMismatchError } from \"./errors.js\";\nimport {\n\ttype AuthorizationServerMetadata,\n\ttype OAuthChallenge,\n\ttype OAuthProtectedResourceMetadata,\n\ttype OAuthServerInfo,\n\tparseAuthorizationServerMetadata,\n\tparseProtectedResourceMetadata,\n} from \"./types.js\";\n\nfunction discard(response: Response | undefined): void {\n\tvoid response?.body?.cancel().catch(() => {});\n}\n\n/** 4xx and 502 mean \"not here\", so discovery tries the next candidate URL. */\nfunction isDiscoveryMiss(status: number): boolean {\n\treturn (status >= 400 && status < 500) || status === 502;\n}\n\n/** Path suffix for `/.well-known/<kind><path>`; empty for the root path. */\nfunction pathSuffix(pathname: string): string {\n\treturn pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname;\n}\n\nfunction field(header: string, name: string): string | undefined {\n\tconst match = header.match(new RegExp(String.raw`(?:^|[,\\s])${name}=(?:\"([^\"]*)\"|([^\\s,]+))`, \"i\"));\n\t// An empty value (`scope=\"\"`) carries no information, so it counts as absent.\n\treturn match?.[1] || match?.[2] || undefined;\n}\n\nexport function parseWwwAuthenticate(header: string | null): OAuthChallenge {\n\tif (!header) return {};\n\tconst scheme = header.trimStart().split(/\\s+/, 1)[0]?.toLowerCase();\n\tif (scheme !== \"bearer\" && scheme !== \"dpop\") return {};\n\tconst resourceMetadata = field(header, \"resource_metadata\");\n\tlet resourceMetadataUrl: URL | undefined;\n\tif (resourceMetadata) {\n\t\ttry {\n\t\t\tresourceMetadataUrl = new URL(resourceMetadata);\n\t\t} catch {}\n\t}\n\treturn {\n\t\tresourceMetadataUrl,\n\t\tscope: field(header, \"scope\"),\n\t\terror: field(header, \"error\"),\n\t\terrorDescription: field(header, \"error_description\"),\n\t};\n}\n\nasync function fetchMetadata(url: URL, fetch: McpFetch, protocolVersion: string): Promise<Response> {\n\treturn fetch(url, {\n\t\theaders: { Accept: \"application/json\", \"MCP-Protocol-Version\": protocolVersion },\n\t});\n}\n\nexport async function discoverProtectedResourceMetadata(\n\tserverUrl: string | URL,\n\toptions: { resourceMetadataUrl?: string | URL; protocolVersion?: string; fetch?: McpFetch } = {},\n): Promise<OAuthProtectedResourceMetadata> {\n\tconst server = new URL(serverUrl);\n\tconst fetch = options.fetch ?? globalThis.fetch;\n\tconst version = options.protocolVersion ?? LATEST_PROTOCOL_VERSION;\n\tlet response = await fetchMetadata(\n\t\toptions.resourceMetadataUrl\n\t\t\t? new URL(options.resourceMetadataUrl)\n\t\t\t: new URL(`/.well-known/oauth-protected-resource${pathSuffix(server.pathname)}`, server.origin),\n\t\tfetch,\n\t\tversion,\n\t);\n\tif (!options.resourceMetadataUrl && server.pathname !== \"/\" && isDiscoveryMiss(response.status)) {\n\t\tdiscard(response);\n\t\tresponse = await fetchMetadata(new URL(\"/.well-known/oauth-protected-resource\", server.origin), fetch, version);\n\t}\n\tif (!response.ok) {\n\t\tdiscard(response);\n\t\tthrow new Error(`HTTP ${response.status} loading OAuth protected resource metadata`);\n\t}\n\treturn parseProtectedResourceMetadata(await response.json());\n}\n\nexport function buildAuthorizationServerDiscoveryUrls(\n\tauthorizationServerUrl: string | URL,\n): { url: URL; type: \"oauth\" | \"oidc\" }[] {\n\tconst issuer = new URL(authorizationServerUrl);\n\tconst path = pathSuffix(issuer.pathname);\n\tconst urls: { url: URL; type: \"oauth\" | \"oidc\" }[] = [\n\t\t{ url: new URL(`/.well-known/oauth-authorization-server${path}`, issuer.origin), type: \"oauth\" },\n\t\t{ url: new URL(`/.well-known/openid-configuration${path}`, issuer.origin), type: \"oidc\" },\n\t];\n\tif (path) urls.push({ url: new URL(`${path}/.well-known/openid-configuration`, issuer.origin), type: \"oidc\" });\n\treturn urls;\n}\n\nexport async function discoverAuthorizationServerMetadata(\n\tauthorizationServerUrl: string | URL,\n\toptions: { fetch?: McpFetch; protocolVersion?: string; skipIssuerValidation?: boolean } = {},\n): Promise<AuthorizationServerMetadata | undefined> {\n\tconst fetch = options.fetch ?? globalThis.fetch;\n\tfor (const { url } of buildAuthorizationServerDiscoveryUrls(authorizationServerUrl)) {\n\t\tconst response = await fetchMetadata(url, fetch, options.protocolVersion ?? LATEST_PROTOCOL_VERSION);\n\t\tif (!response.ok) {\n\t\t\tdiscard(response);\n\t\t\tif (isDiscoveryMiss(response.status)) continue;\n\t\t\tthrow new Error(`HTTP ${response.status} loading authorization server metadata from ${url}`);\n\t\t}\n\t\tconst metadata = parseAuthorizationServerMetadata(await response.json());\n\t\tif (!options.skipIssuerValidation) {\n\t\t\tconst expected = String(authorizationServerUrl);\n\t\t\t// URL parsing adds a trailing slash to bare origins, so compare without one on either side.\n\t\t\tconst trim = (value: string) => (value.endsWith(\"/\") ? value.slice(0, -1) : value);\n\t\t\tif (trim(metadata.issuer) !== trim(expected)) throw new OAuthIssuerMismatchError(expected, metadata.issuer);\n\t\t}\n\t\treturn metadata;\n\t}\n\treturn undefined;\n}\n\nexport async function discoverOAuthServerInfo(\n\tserverUrl: string | URL,\n\toptions: {\n\t\tresourceMetadataUrl?: URL;\n\t\t/** Metadata document to use instead of discovery. It is trusted as configured, so its issuer is not checked. */\n\t\tauthorizationServerMetadataUrl?: URL;\n\t\tfetch?: McpFetch;\n\t\tskipIssuerValidation?: boolean;\n\t} = {},\n): Promise<OAuthServerInfo> {\n\tlet resourceMetadata: OAuthProtectedResourceMetadata | undefined;\n\ttry {\n\t\tresourceMetadata = await discoverProtectedResourceMetadata(serverUrl, {\n\t\t\tresourceMetadataUrl: options.resourceMetadataUrl,\n\t\t\tfetch: options.fetch,\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof TypeError) throw error;\n\t}\n\tif (options.authorizationServerMetadataUrl) {\n\t\tconst url = options.authorizationServerMetadataUrl;\n\t\tconst response = await fetchMetadata(url, options.fetch ?? globalThis.fetch, LATEST_PROTOCOL_VERSION);\n\t\tif (!response.ok) {\n\t\t\tdiscard(response);\n\t\t\tthrow new Error(`HTTP ${response.status} loading authorization server metadata from ${url}`);\n\t\t}\n\t\tconst metadata = parseAuthorizationServerMetadata(await response.json());\n\t\treturn { authorizationServerUrl: metadata.issuer, authorizationServerMetadata: metadata, resourceMetadata };\n\t}\n\tconst authorizationServerUrl = resourceMetadata?.authorization_servers?.[0] ?? String(new URL(\"/\", serverUrl));\n\treturn {\n\t\tauthorizationServerUrl,\n\t\tauthorizationServerMetadata: await discoverAuthorizationServerMetadata(authorizationServerUrl, {\n\t\t\tfetch: options.fetch,\n\t\t\tskipIssuerValidation: options.skipIssuerValidation,\n\t\t}),\n\t\tresourceMetadata,\n\t};\n}\n\nexport function resourceUrlFromServerUrl(value: string | URL): URL {\n\tconst url = new URL(value);\n\turl.hash = \"\";\n\treturn url;\n}\n\nexport function selectResource(serverUrl: string | URL, metadata?: OAuthProtectedResourceMetadata): string | undefined {\n\tif (!metadata) return undefined;\n\tconst requested = resourceUrlFromServerUrl(serverUrl);\n\tconst configured = new URL(metadata.resource);\n\tif (requested.origin !== configured.origin) {\n\t\tthrow new Error(`Protected resource ${metadata.resource} does not match MCP server ${requested}`);\n\t}\n\tconst requestedPath = requested.pathname.endsWith(\"/\") ? requested.pathname : `${requested.pathname}/`;\n\tconst configuredPath = configured.pathname.endsWith(\"/\") ? configured.pathname : `${configured.pathname}/`;\n\tif (!requestedPath.startsWith(configuredPath)) {\n\t\tthrow new Error(`Protected resource ${metadata.resource} does not match MCP server ${requested}`);\n\t}\n\treturn metadata.resource;\n}\n"]}
@@ -0,0 +1,24 @@
1
+ export declare class OAuthError extends Error {
2
+ readonly code: string;
3
+ readonly errorUri: string | undefined;
4
+ constructor(code: string, message: string, errorUri?: string);
5
+ }
6
+ export declare class OAuthIssuerMismatchError extends Error {
7
+ readonly expected: string;
8
+ /** `undefined` when an authorization response lacks the `iss` parameter its server promised (RFC 9207). */
9
+ readonly received: string | undefined;
10
+ constructor(expected: string, received: string | undefined);
11
+ }
12
+ export declare class OAuthInsecureEndpointError extends Error {
13
+ readonly endpoint: string;
14
+ constructor(endpoint: string);
15
+ }
16
+ export declare class OAuthRegistrationError extends Error {
17
+ readonly status: number;
18
+ readonly body: string;
19
+ constructor(status: number, body: string);
20
+ }
21
+ export declare class McpOAuthAuthorizationRequiredError extends Error {
22
+ constructor();
23
+ }
24
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAEtC,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAK3D;CACD;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2GAA2G;IAC3G,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAEtC,YAAY,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAOzD;CACD;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,YAAY,QAAQ,EAAE,MAAM,EAI3B;CACD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAKvC;CACD;AAED,qBAAa,kCAAmC,SAAQ,KAAK;IAC5D,cAGC;CACD"}
@@ -0,0 +1,46 @@
1
+ export class OAuthError extends Error {
2
+ code;
3
+ errorUri;
4
+ constructor(code, message, errorUri) {
5
+ super(message || code);
6
+ this.name = "OAuthError";
7
+ this.code = code;
8
+ this.errorUri = errorUri;
9
+ }
10
+ }
11
+ export class OAuthIssuerMismatchError extends Error {
12
+ expected;
13
+ /** `undefined` when an authorization response lacks the `iss` parameter its server promised (RFC 9207). */
14
+ received;
15
+ constructor(expected, received) {
16
+ super(`OAuth issuer mismatch: expected ${JSON.stringify(expected)}, received ${received === undefined ? "none" : JSON.stringify(received)}`);
17
+ this.name = "OAuthIssuerMismatchError";
18
+ this.expected = expected;
19
+ this.received = received;
20
+ }
21
+ }
22
+ export class OAuthInsecureEndpointError extends Error {
23
+ endpoint;
24
+ constructor(endpoint) {
25
+ super(`Refusing to send OAuth credentials to non-HTTPS endpoint ${endpoint}`);
26
+ this.name = "OAuthInsecureEndpointError";
27
+ this.endpoint = endpoint;
28
+ }
29
+ }
30
+ export class OAuthRegistrationError extends Error {
31
+ status;
32
+ body;
33
+ constructor(status, body) {
34
+ super(`OAuth dynamic client registration failed with status ${status}: ${body}`);
35
+ this.name = "OAuthRegistrationError";
36
+ this.status = status;
37
+ this.body = body;
38
+ }
39
+ }
40
+ export class McpOAuthAuthorizationRequiredError extends Error {
41
+ constructor() {
42
+ super("MCP OAuth authorization requires user interaction");
43
+ this.name = "McpOAuthAuthorizationRequiredError";
44
+ }
45
+ }
46
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,QAAQ,CAAqB;IAEtC,YAAY,IAAY,EAAE,OAAe,EAAE,QAAiB;QAC3D,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACzC,QAAQ,CAAS;IAC1B,2GAA2G;IAClG,QAAQ,CAAqB;IAEtC,YAAY,QAAgB,EAAE,QAA4B;QACzD,KAAK,CACJ,mCAAmC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,cAAc,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CACrI,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC3C,QAAQ,CAAS;IAE1B,YAAY,QAAgB;QAC3B,KAAK,CAAC,4DAA4D,QAAQ,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACvC,MAAM,CAAS;IACf,IAAI,CAAS;IAEtB,YAAY,MAAc,EAAE,IAAY;QACvC,KAAK,CAAC,wDAAwD,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,OAAO,kCAAmC,SAAQ,KAAK;IAC5D;QACC,KAAK,CAAC,mDAAmD,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IAClD,CAAC;CACD","sourcesContent":["export class OAuthError extends Error {\n\treadonly code: string;\n\treadonly errorUri: string | undefined;\n\n\tconstructor(code: string, message: string, errorUri?: string) {\n\t\tsuper(message || code);\n\t\tthis.name = \"OAuthError\";\n\t\tthis.code = code;\n\t\tthis.errorUri = errorUri;\n\t}\n}\n\nexport class OAuthIssuerMismatchError extends Error {\n\treadonly expected: string;\n\t/** `undefined` when an authorization response lacks the `iss` parameter its server promised (RFC 9207). */\n\treadonly received: string | undefined;\n\n\tconstructor(expected: string, received: string | undefined) {\n\t\tsuper(\n\t\t\t`OAuth issuer mismatch: expected ${JSON.stringify(expected)}, received ${received === undefined ? \"none\" : JSON.stringify(received)}`,\n\t\t);\n\t\tthis.name = \"OAuthIssuerMismatchError\";\n\t\tthis.expected = expected;\n\t\tthis.received = received;\n\t}\n}\n\nexport class OAuthInsecureEndpointError extends Error {\n\treadonly endpoint: string;\n\n\tconstructor(endpoint: string) {\n\t\tsuper(`Refusing to send OAuth credentials to non-HTTPS endpoint ${endpoint}`);\n\t\tthis.name = \"OAuthInsecureEndpointError\";\n\t\tthis.endpoint = endpoint;\n\t}\n}\n\nexport class OAuthRegistrationError extends Error {\n\treadonly status: number;\n\treadonly body: string;\n\n\tconstructor(status: number, body: string) {\n\t\tsuper(`OAuth dynamic client registration failed with status ${status}: ${body}`);\n\t\tthis.name = \"OAuthRegistrationError\";\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class McpOAuthAuthorizationRequiredError extends Error {\n\tconstructor() {\n\t\tsuper(\"MCP OAuth authorization requires user interaction\");\n\t\tthis.name = \"McpOAuthAuthorizationRequiredError\";\n\t}\n}\n"]}
@@ -0,0 +1,82 @@
1
+ import type { AuthProvider, McpFetch } from "../auth-provider.js";
2
+ import { type AuthorizationServerMetadata, type OAuthClientInformationFull, type OAuthClientInformationMixed, type OAuthClientMetadata, type OAuthDiscoveryState, type OAuthTokens } from "./types.js";
3
+ export type AddClientAuthentication = (headers: Headers, params: URLSearchParams, url: string | URL, metadata?: AuthorizationServerMetadata) => void | Promise<void>;
4
+ export interface OAuthClientProvider {
5
+ readonly redirectUrl: string | URL;
6
+ readonly clientMetadata: OAuthClientMetadata;
7
+ readonly clientMetadataUrl?: string;
8
+ state?(): string | Promise<string>;
9
+ clientInformation(): OAuthClientInformationMixed | undefined | Promise<OAuthClientInformationMixed | undefined>;
10
+ saveClientInformation?(information: OAuthClientInformationMixed): void | Promise<void>;
11
+ tokens(): OAuthTokens | undefined | Promise<OAuthTokens | undefined>;
12
+ saveTokens(tokens: OAuthTokens): void | Promise<void>;
13
+ redirectToAuthorization(url: URL): void | Promise<void>;
14
+ saveCodeVerifier(verifier: string): void | Promise<void>;
15
+ codeVerifier(): string | Promise<string>;
16
+ addClientAuthentication?: AddClientAuthentication;
17
+ invalidateCredentials?(kind: "all" | "client" | "tokens" | "verifier" | "discovery"): void | Promise<void>;
18
+ saveDiscoveryState?(state: OAuthDiscoveryState): void | Promise<void>;
19
+ discoveryState?(): OAuthDiscoveryState | undefined | Promise<OAuthDiscoveryState | undefined>;
20
+ }
21
+ export interface OAuthFlowOptions {
22
+ serverUrl: string | URL;
23
+ authorizationCode?: string;
24
+ /** `iss` parameter of the authorization response that delivered `authorizationCode` (RFC 9207). */
25
+ iss?: string;
26
+ scope?: string;
27
+ resourceMetadataUrl?: URL;
28
+ /**
29
+ * Authorization server metadata document to use instead of discovery, for servers that advertise a
30
+ * wrong authorization server or none. It is trusted as configured. Must use https, except on loopback.
31
+ */
32
+ authorizationServerMetadataUrl?: URL;
33
+ fetch?: McpFetch;
34
+ skipIssuerValidation?: boolean;
35
+ /**
36
+ * Go straight to the authorization redirect instead of refreshing stored tokens, for example when the
37
+ * server asks for scopes the current grant lacks (a refresh keeps the old scope).
38
+ */
39
+ skipRefresh?: boolean;
40
+ }
41
+ export type OAuthFlowResult = "AUTHORIZED" | "REDIRECT";
42
+ export interface TokenRequestOptions {
43
+ metadata?: AuthorizationServerMetadata;
44
+ clientInformation: OAuthClientInformationMixed;
45
+ resource?: string;
46
+ addClientAuthentication?: AddClientAuthentication;
47
+ fetch?: McpFetch;
48
+ }
49
+ export declare function startAuthorization(authorizationServerUrl: string | URL, options: {
50
+ metadata?: AuthorizationServerMetadata;
51
+ clientInformation: OAuthClientInformationMixed;
52
+ redirectUrl: string | URL;
53
+ scope?: string;
54
+ state?: string;
55
+ resource?: string;
56
+ }): Promise<{
57
+ authorizationUrl: URL;
58
+ codeVerifier: string;
59
+ }>;
60
+ export declare function registerClient(authorizationServerUrl: string | URL, options: {
61
+ metadata?: AuthorizationServerMetadata;
62
+ clientMetadata: OAuthClientMetadata;
63
+ scope?: string;
64
+ fetch?: McpFetch;
65
+ }): Promise<OAuthClientInformationFull>;
66
+ export declare function exchangeAuthorizationCode(authorizationServerUrl: string | URL, options: TokenRequestOptions & {
67
+ code: string;
68
+ codeVerifier: string;
69
+ redirectUrl: string | URL;
70
+ }): Promise<OAuthTokens>;
71
+ export declare function refreshAuthorization(authorizationServerUrl: string | URL, options: TokenRequestOptions & {
72
+ refreshToken: string;
73
+ }): Promise<OAuthTokens>;
74
+ export declare function authorizeMcp(provider: OAuthClientProvider, options: OAuthFlowOptions): Promise<OAuthFlowResult>;
75
+ /**
76
+ * Auth provider for `StreamableHttpTransport`. After a 401 it refreshes the tokens, or throws
77
+ * `McpOAuthAuthorizationRequiredError` when the user has to authorize (again). Concurrent 401s share
78
+ * one refresh, and a request whose token was already replaced is just retried: with rotating refresh
79
+ * tokens, a second refresh with the old refresh token would fail and discard the new grant.
80
+ */
81
+ export declare function adaptOAuthProvider(provider: OAuthClientProvider): AuthProvider;
82
+ //# sourceMappingURL=flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/mcp/client/oauth/flow.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAuB,MAAM,qBAAqB,CAAC;AAevF,OAAO,EACN,KAAK,2BAA2B,EAEhC,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAGhB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,uBAAuB,GAAG,CACrC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,QAAQ,CAAC,EAAE,2BAA2B,KAClC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,KAAK,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,MA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