@vybestack/llxprt-code-core 0.2.24 → 0.3.4-nightly.250912.5e46408e

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 (194) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/code_assist/converter.js +35 -3
  5. package/dist/src/code_assist/converter.js.map +1 -1
  6. package/dist/src/code_assist/oauth2.d.ts +1 -1
  7. package/dist/src/code_assist/oauth2.js +18 -25
  8. package/dist/src/code_assist/oauth2.js.map +1 -1
  9. package/dist/src/config/config.d.ts +33 -2
  10. package/dist/src/config/config.js +73 -13
  11. package/dist/src/config/config.js.map +1 -1
  12. package/dist/src/config/storage.d.ts +33 -0
  13. package/dist/src/config/storage.js +93 -0
  14. package/dist/src/config/storage.js.map +1 -0
  15. package/dist/src/core/client.d.ts +8 -5
  16. package/dist/src/core/client.js +119 -20
  17. package/dist/src/core/client.js.map +1 -1
  18. package/dist/src/core/contentGenerator.js +11 -0
  19. package/dist/src/core/contentGenerator.js.map +1 -1
  20. package/dist/src/core/coreToolScheduler.d.ts +18 -12
  21. package/dist/src/core/coreToolScheduler.js +235 -241
  22. package/dist/src/core/coreToolScheduler.js.map +1 -1
  23. package/dist/src/core/logger.d.ts +3 -1
  24. package/dist/src/core/logger.js +5 -3
  25. package/dist/src/core/logger.js.map +1 -1
  26. package/dist/src/core/nonInteractiveToolExecutor.js +2 -2
  27. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  28. package/dist/src/core/subagent.js +2 -12
  29. package/dist/src/core/subagent.js.map +1 -1
  30. package/dist/src/core/turn.d.ts +13 -2
  31. package/dist/src/core/turn.js +15 -4
  32. package/dist/src/core/turn.js.map +1 -1
  33. package/dist/src/filters/EmojiFilter.d.ts +5 -0
  34. package/dist/src/filters/EmojiFilter.js +3 -2
  35. package/dist/src/filters/EmojiFilter.js.map +1 -1
  36. package/dist/src/ide/detect-ide.d.ts +8 -3
  37. package/dist/src/ide/detect-ide.js +29 -11
  38. package/dist/src/ide/detect-ide.js.map +1 -1
  39. package/dist/src/ide/ide-client.d.ts +5 -4
  40. package/dist/src/ide/ide-client.js +21 -17
  41. package/dist/src/ide/ide-client.js.map +1 -1
  42. package/dist/src/ide/ide-installer.d.ts +1 -1
  43. package/dist/src/ide/ide-installer.js +29 -20
  44. package/dist/src/ide/ide-installer.js.map +1 -1
  45. package/dist/src/ide/process-utils.d.ts +7 -5
  46. package/dist/src/ide/process-utils.js +80 -47
  47. package/dist/src/ide/process-utils.js.map +1 -1
  48. package/dist/src/index.d.ts +6 -0
  49. package/dist/src/index.js +7 -0
  50. package/dist/src/index.js.map +1 -1
  51. package/dist/src/mcp/file-token-store.d.ts +58 -0
  52. package/dist/src/mcp/file-token-store.js +181 -0
  53. package/dist/src/mcp/file-token-store.js.map +1 -0
  54. package/dist/src/mcp/oauth-token-storage.d.ts +13 -28
  55. package/dist/src/mcp/oauth-token-storage.js +21 -87
  56. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  57. package/dist/src/mcp/oauth-utils.d.ts +8 -0
  58. package/dist/src/mcp/oauth-utils.js +41 -27
  59. package/dist/src/mcp/oauth-utils.js.map +1 -1
  60. package/dist/src/mcp/token-store.d.ts +99 -0
  61. package/dist/src/mcp/token-store.js +77 -0
  62. package/dist/src/mcp/token-store.js.map +1 -0
  63. package/dist/src/parsers/TextToolCallParser.d.ts +5 -0
  64. package/dist/src/parsers/TextToolCallParser.js +3 -13
  65. package/dist/src/parsers/TextToolCallParser.js.map +1 -1
  66. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +5 -0
  67. package/dist/src/providers/anthropic/AnthropicProvider.js +26 -8
  68. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  69. package/dist/src/providers/gemini/GeminiProvider.js +16 -1
  70. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
  71. package/dist/src/providers/openai/OpenAIProvider.d.ts +15 -0
  72. package/dist/src/providers/openai/OpenAIProvider.js +99 -48
  73. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  74. package/dist/src/services/gitService.d.ts +3 -1
  75. package/dist/src/services/gitService.js +20 -10
  76. package/dist/src/services/gitService.js.map +1 -1
  77. package/dist/src/services/history/ContentConverters.js +40 -1
  78. package/dist/src/services/history/ContentConverters.js.map +1 -1
  79. package/dist/src/services/loopDetectionService.js +8 -2
  80. package/dist/src/services/loopDetectionService.js.map +1 -1
  81. package/dist/src/services/shellExecutionService.js +2 -1
  82. package/dist/src/services/shellExecutionService.js.map +1 -1
  83. package/dist/src/settings/SettingsService.d.ts +5 -0
  84. package/dist/src/settings/SettingsService.js +5 -0
  85. package/dist/src/settings/SettingsService.js.map +1 -1
  86. package/dist/src/settings/settingsServiceInstance.d.ts +5 -0
  87. package/dist/src/settings/settingsServiceInstance.js +5 -0
  88. package/dist/src/settings/settingsServiceInstance.js.map +1 -1
  89. package/dist/src/settings/types.d.ts +5 -0
  90. package/dist/src/settings/types.js +3 -1
  91. package/dist/src/settings/types.js.map +1 -1
  92. package/dist/src/tools/IToolFormatter.d.ts +5 -0
  93. package/dist/src/tools/IToolFormatter.js +3 -13
  94. package/dist/src/tools/IToolFormatter.js.map +1 -1
  95. package/dist/src/tools/ToolFormatter.d.ts +18 -0
  96. package/dist/src/tools/ToolFormatter.js +41 -13
  97. package/dist/src/tools/ToolFormatter.js.map +1 -1
  98. package/dist/src/tools/doubleEscapeUtils.d.ts +3 -13
  99. package/dist/src/tools/doubleEscapeUtils.js +5 -0
  100. package/dist/src/tools/doubleEscapeUtils.js.map +1 -1
  101. package/dist/src/tools/edit.js +10 -1
  102. package/dist/src/tools/edit.js.map +1 -1
  103. package/dist/src/tools/glob.d.ts +0 -4
  104. package/dist/src/tools/glob.js +18 -42
  105. package/dist/src/tools/glob.js.map +1 -1
  106. package/dist/src/tools/grep.d.ts +0 -4
  107. package/dist/src/tools/grep.js +41 -77
  108. package/dist/src/tools/grep.js.map +1 -1
  109. package/dist/src/tools/ls.d.ts +2 -6
  110. package/dist/src/tools/ls.js +18 -13
  111. package/dist/src/tools/ls.js.map +1 -1
  112. package/dist/src/tools/mcp-client.d.ts +7 -0
  113. package/dist/src/tools/mcp-client.js +26 -21
  114. package/dist/src/tools/mcp-client.js.map +1 -1
  115. package/dist/src/tools/mcp-tool.js +12 -2
  116. package/dist/src/tools/mcp-tool.js.map +1 -1
  117. package/dist/src/tools/memoryTool.js +7 -2
  118. package/dist/src/tools/memoryTool.js.map +1 -1
  119. package/dist/src/tools/read-file.js +2 -30
  120. package/dist/src/tools/read-file.js.map +1 -1
  121. package/dist/src/tools/read-many-files.js +29 -52
  122. package/dist/src/tools/read-many-files.js.map +1 -1
  123. package/dist/src/tools/ripGrep.d.ts +46 -0
  124. package/dist/src/tools/ripGrep.js +368 -0
  125. package/dist/src/tools/ripGrep.js.map +1 -0
  126. package/dist/src/tools/shell.js +13 -2
  127. package/dist/src/tools/shell.js.map +1 -1
  128. package/dist/src/tools/todo-pause.js +0 -1
  129. package/dist/src/tools/todo-pause.js.map +1 -1
  130. package/dist/src/tools/tool-error.d.ts +18 -2
  131. package/dist/src/tools/tool-error.js +27 -1
  132. package/dist/src/tools/tool-error.js.map +1 -1
  133. package/dist/src/tools/tool-registry.d.ts +13 -2
  134. package/dist/src/tools/tool-registry.js +30 -2
  135. package/dist/src/tools/tool-registry.js.map +1 -1
  136. package/dist/src/tools/tools.d.ts +7 -5
  137. package/dist/src/tools/tools.js +12 -0
  138. package/dist/src/tools/tools.js.map +1 -1
  139. package/dist/src/tools/web-fetch.js +101 -76
  140. package/dist/src/tools/web-fetch.js.map +1 -1
  141. package/dist/src/tools/web-search-invocation.js +13 -1
  142. package/dist/src/tools/web-search-invocation.js.map +1 -1
  143. package/dist/src/utils/deterministicEditCorrector.d.ts +28 -0
  144. package/dist/src/utils/deterministicEditCorrector.js +295 -0
  145. package/dist/src/utils/deterministicEditCorrector.js.map +1 -0
  146. package/dist/src/utils/editCorrector.d.ts +4 -4
  147. package/dist/src/utils/editCorrector.js +15 -213
  148. package/dist/src/utils/editCorrector.js.map +1 -1
  149. package/dist/src/utils/editor.js +1 -1
  150. package/dist/src/utils/editor.js.map +1 -1
  151. package/dist/src/utils/errors.d.ts +19 -0
  152. package/dist/src/utils/errors.js +32 -0
  153. package/dist/src/utils/errors.js.map +1 -1
  154. package/dist/src/utils/fileUtils.d.ts +2 -7
  155. package/dist/src/utils/fileUtils.js +16 -47
  156. package/dist/src/utils/fileUtils.js.map +1 -1
  157. package/dist/src/utils/filesearch/fileSearch.d.ts +1 -0
  158. package/dist/src/utils/filesearch/fileSearch.js +14 -9
  159. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  160. package/dist/src/utils/ignorePatterns.d.ts +103 -0
  161. package/dist/src/utils/ignorePatterns.js +220 -0
  162. package/dist/src/utils/ignorePatterns.js.map +1 -0
  163. package/dist/src/utils/installationManager.d.ts +16 -0
  164. package/dist/src/utils/installationManager.js +50 -0
  165. package/dist/src/utils/installationManager.js.map +1 -0
  166. package/dist/src/utils/memoryDiscovery.d.ts +1 -1
  167. package/dist/src/utils/memoryDiscovery.js +64 -43
  168. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  169. package/dist/src/utils/paths.d.ts +0 -17
  170. package/dist/src/utils/paths.js +0 -26
  171. package/dist/src/utils/paths.js.map +1 -1
  172. package/dist/src/utils/schemaValidator.js +4 -0
  173. package/dist/src/utils/schemaValidator.js.map +1 -1
  174. package/dist/src/utils/shell-utils.d.ts +1 -1
  175. package/dist/src/utils/shell-utils.js +23 -29
  176. package/dist/src/utils/shell-utils.js.map +1 -1
  177. package/dist/src/utils/tool-utils.d.ts +19 -0
  178. package/dist/src/utils/tool-utils.js +58 -0
  179. package/dist/src/utils/tool-utils.js.map +1 -0
  180. package/dist/src/utils/userAccountManager.d.ts +20 -0
  181. package/dist/src/utils/userAccountManager.js +122 -0
  182. package/dist/src/utils/userAccountManager.js.map +1 -0
  183. package/dist/src/utils/workspaceContext.js +11 -5
  184. package/dist/src/utils/workspaceContext.js.map +1 -1
  185. package/package.json +7 -3
  186. package/dist/src/utils/nextSpeakerChecker.d.ts +0 -12
  187. package/dist/src/utils/nextSpeakerChecker.js +0 -97
  188. package/dist/src/utils/nextSpeakerChecker.js.map +0 -1
  189. package/dist/src/utils/user_account.d.ts +0 -9
  190. package/dist/src/utils/user_account.js +0 -109
  191. package/dist/src/utils/user_account.js.map +0 -1
  192. package/dist/src/utils/user_id.d.ts +0 -11
  193. package/dist/src/utils/user_id.js +0 -49
  194. package/dist/src/utils/user_id.js.map +0 -1
package/dist/src/index.js CHANGED
@@ -44,9 +44,11 @@ export * from './utils/textUtils.js';
44
44
  export * from './utils/formatters.js';
45
45
  export * from './utils/sanitization.js';
46
46
  export * from './utils/unicodeUtils.js';
47
+ export * from './utils/generateContentResponseUtilities.js';
47
48
  export * from './utils/filesearch/fileSearch.js';
48
49
  export * from './utils/secure-browser-launcher.js';
49
50
  export * from './utils/errorParsing.js';
51
+ export * from './utils/ignorePatterns.js';
50
52
  // Export auth system
51
53
  export * from './auth/token-store.js';
52
54
  export * from './auth/types.js';
@@ -81,6 +83,7 @@ export * from './prompt-config/types.js';
81
83
  export * from './tools/read-file.js';
82
84
  export * from './tools/ls.js';
83
85
  export * from './tools/grep.js';
86
+ export * from './tools/ripGrep.js';
84
87
  export * from './tools/glob.js';
85
88
  export * from './tools/edit.js';
86
89
  export * from './tools/write-file.js';
@@ -100,6 +103,8 @@ export * from './tools/todo-events.js';
100
103
  // MCP OAuth
101
104
  export { MCPOAuthProvider } from './mcp/oauth-provider.js';
102
105
  export { MCPOAuthTokenStorage, } from './mcp/oauth-token-storage.js';
106
+ export { BaseTokenStore, } from './mcp/token-store.js';
107
+ export { FileTokenStore } from './mcp/file-token-store.js';
103
108
  export { OAuthUtils } from './mcp/oauth-utils.js';
104
109
  // Export telemetry functions
105
110
  export * from './telemetry/index.js';
@@ -144,4 +149,6 @@ export { getSettingsService, resetSettingsService, } from './settings/settingsSe
144
149
  export { EmojiFilter } from './filters/EmojiFilter.js';
145
150
  // Export debug system
146
151
  export { ConfigurationManager, DebugLogger, FileOutput, } from './debug/index.js';
152
+ // Export Storage
153
+ export { Storage } from './config/storage.js';
147
154
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAE3C,kBAAkB;AAClB,cAAc,iCAAiC,CAAC;AAEhD,eAAe;AACf,cAAc,wBAAwB,CAAC;AAEvC,oBAAoB;AACpB,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AAErD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AAEvC,mBAAmB;AACnB,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,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AAkC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yDAAyD,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AAEtC,oBAAoB;AACpB,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,oBAAoB,CAAC;AACnC,cAAc,6CAA6C,CAAC;AAE5D,kBAAkB;AAClB,cAAc,8BAA8B,CAAC;AAE7C,iBAAiB;AACjB,cAAc,iCAAiC,CAAC;AAEhD,yBAAyB;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AAEzC,yBAAyB;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,uCAAuC,CAAC;AAa/C,6BAA6B;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOvD,sBAAsB;AACtB,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAI1B,iBAAiB;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTokenStore, MCPOAuthToken, MCPOAuthCredentials } from './token-store.js';
7
+ /**
8
+ * File-based implementation of the BaseTokenStore.
9
+ * Stores MCP OAuth tokens in a JSON file in the user's configuration directory.
10
+ */
11
+ export declare class FileTokenStore extends BaseTokenStore {
12
+ private readonly tokenFilePath;
13
+ constructor(tokenFilePath?: string);
14
+ /**
15
+ * Ensure the config directory exists.
16
+ */
17
+ private ensureConfigDir;
18
+ /**
19
+ * Load all stored MCP OAuth tokens.
20
+ *
21
+ * @returns A map of server names to credentials
22
+ */
23
+ loadTokens(): Promise<Map<string, MCPOAuthCredentials>>;
24
+ /**
25
+ * Save a token for a specific MCP server.
26
+ *
27
+ * @param serverName The name of the MCP server
28
+ * @param token The OAuth token to save
29
+ * @param clientId Optional client ID used for this token
30
+ * @param tokenUrl Optional token URL used for this token
31
+ * @param mcpServerUrl Optional MCP server URL
32
+ */
33
+ saveToken(serverName: string, token: MCPOAuthToken, clientId?: string, tokenUrl?: string, mcpServerUrl?: string): Promise<void>;
34
+ /**
35
+ * Get a token for a specific MCP server.
36
+ *
37
+ * @param serverName The name of the MCP server
38
+ * @returns The stored credentials or null if not found
39
+ */
40
+ getToken(serverName: string): Promise<MCPOAuthCredentials | null>;
41
+ /**
42
+ * Remove a token for a specific MCP server.
43
+ *
44
+ * @param serverName The name of the MCP server
45
+ */
46
+ removeToken(serverName: string): Promise<void>;
47
+ /**
48
+ * Clear all stored MCP OAuth tokens.
49
+ */
50
+ clearAllTokens(): Promise<void>;
51
+ /**
52
+ * Validate that credentials object has the required structure.
53
+ *
54
+ * @param credentials The credentials to validate
55
+ * @returns True if valid, false otherwise
56
+ */
57
+ private isValidCredentials;
58
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { promises as fs } from 'node:fs';
7
+ import * as path from 'node:path';
8
+ import { Storage } from '../config/storage.js';
9
+ import { getErrorMessage } from '../utils/errors.js';
10
+ import { BaseTokenStore, } from './token-store.js';
11
+ /**
12
+ * File-based implementation of the BaseTokenStore.
13
+ * Stores MCP OAuth tokens in a JSON file in the user's configuration directory.
14
+ */
15
+ export class FileTokenStore extends BaseTokenStore {
16
+ tokenFilePath;
17
+ constructor(tokenFilePath) {
18
+ super();
19
+ this.tokenFilePath = tokenFilePath || Storage.getMcpOAuthTokensPath();
20
+ }
21
+ /**
22
+ * Ensure the config directory exists.
23
+ */
24
+ async ensureConfigDir() {
25
+ const configDir = path.dirname(this.tokenFilePath);
26
+ try {
27
+ await fs.mkdir(configDir, { recursive: true });
28
+ }
29
+ catch (error) {
30
+ console.error(`Failed to create config directory ${configDir}: ${getErrorMessage(error)}`);
31
+ throw error;
32
+ }
33
+ }
34
+ /**
35
+ * Load all stored MCP OAuth tokens.
36
+ *
37
+ * @returns A map of server names to credentials
38
+ */
39
+ async loadTokens() {
40
+ const tokenMap = new Map();
41
+ try {
42
+ const data = await fs.readFile(this.tokenFilePath, 'utf-8');
43
+ const tokens = JSON.parse(data);
44
+ // Validate the loaded data structure
45
+ if (!Array.isArray(tokens)) {
46
+ console.warn('Token file contains invalid data structure, ignoring');
47
+ return tokenMap;
48
+ }
49
+ for (const credential of tokens) {
50
+ if (this.isValidCredentials(credential)) {
51
+ tokenMap.set(credential.serverName, credential);
52
+ }
53
+ else {
54
+ console.warn(`Skipping invalid credential entry for server: ${credential?.serverName || 'unknown'}`);
55
+ }
56
+ }
57
+ }
58
+ catch (error) {
59
+ // File doesn't exist or is invalid, return empty map
60
+ if (error.code !== 'ENOENT') {
61
+ console.error(`Failed to load MCP OAuth tokens from ${this.tokenFilePath}: ${getErrorMessage(error)}`);
62
+ }
63
+ }
64
+ return tokenMap;
65
+ }
66
+ /**
67
+ * Save a token for a specific MCP server.
68
+ *
69
+ * @param serverName The name of the MCP server
70
+ * @param token The OAuth token to save
71
+ * @param clientId Optional client ID used for this token
72
+ * @param tokenUrl Optional token URL used for this token
73
+ * @param mcpServerUrl Optional MCP server URL
74
+ */
75
+ async saveToken(serverName, token, clientId, tokenUrl, mcpServerUrl) {
76
+ await this.ensureConfigDir();
77
+ const tokens = await this.loadTokens();
78
+ const credential = this.createCredentials(serverName, token, clientId, tokenUrl, mcpServerUrl);
79
+ tokens.set(serverName, credential);
80
+ const tokenArray = Array.from(tokens.values());
81
+ try {
82
+ await fs.writeFile(this.tokenFilePath, JSON.stringify(tokenArray, null, 2), { mode: 0o600 });
83
+ // Token saved successfully
84
+ }
85
+ catch (error) {
86
+ console.error(`Failed to save MCP OAuth token for ${serverName}: ${getErrorMessage(error)}`);
87
+ throw error;
88
+ }
89
+ }
90
+ /**
91
+ * Get a token for a specific MCP server.
92
+ *
93
+ * @param serverName The name of the MCP server
94
+ * @returns The stored credentials or null if not found
95
+ */
96
+ async getToken(serverName) {
97
+ this.validateServerName(serverName);
98
+ const tokens = await this.loadTokens();
99
+ const credential = tokens.get(serverName) || null;
100
+ // Return credential if found
101
+ return credential;
102
+ }
103
+ /**
104
+ * Remove a token for a specific MCP server.
105
+ *
106
+ * @param serverName The name of the MCP server
107
+ */
108
+ async removeToken(serverName) {
109
+ this.validateServerName(serverName);
110
+ const tokens = await this.loadTokens();
111
+ if (tokens.delete(serverName)) {
112
+ const tokenArray = Array.from(tokens.values());
113
+ try {
114
+ if (tokenArray.length === 0) {
115
+ // Remove file if no tokens left
116
+ await fs.unlink(this.tokenFilePath);
117
+ // Token file removed successfully
118
+ }
119
+ else {
120
+ await fs.writeFile(this.tokenFilePath, JSON.stringify(tokenArray, null, 2), { mode: 0o600 });
121
+ // Token removed successfully
122
+ }
123
+ }
124
+ catch (error) {
125
+ console.error(`Failed to remove MCP OAuth token for ${serverName}: ${getErrorMessage(error)}`);
126
+ // Don't throw - removal from memory map succeeded
127
+ }
128
+ }
129
+ else {
130
+ // No token found to remove
131
+ }
132
+ }
133
+ /**
134
+ * Clear all stored MCP OAuth tokens.
135
+ */
136
+ async clearAllTokens() {
137
+ try {
138
+ await fs.unlink(this.tokenFilePath);
139
+ // All tokens cleared successfully
140
+ }
141
+ catch (error) {
142
+ if (error.code === 'ENOENT') {
143
+ // No token file to clear
144
+ }
145
+ else {
146
+ console.error(`Failed to clear MCP OAuth tokens: ${getErrorMessage(error)}`);
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Validate that credentials object has the required structure.
152
+ *
153
+ * @param credentials The credentials to validate
154
+ * @returns True if valid, false otherwise
155
+ */
156
+ isValidCredentials(credentials) {
157
+ if (!credentials || typeof credentials !== 'object') {
158
+ return false;
159
+ }
160
+ const cred = credentials;
161
+ // Check required fields
162
+ if (!cred.serverName || typeof cred.serverName !== 'string') {
163
+ return false;
164
+ }
165
+ if (!cred.token || typeof cred.token !== 'object') {
166
+ return false;
167
+ }
168
+ const token = cred.token;
169
+ if (!token.accessToken || typeof token.accessToken !== 'string') {
170
+ return false;
171
+ }
172
+ if (!token.tokenType || typeof token.tokenType !== 'string') {
173
+ return false;
174
+ }
175
+ if (typeof cred.updatedAt !== 'number') {
176
+ return false;
177
+ }
178
+ return true;
179
+ }
180
+ }
181
+ //# sourceMappingURL=file-token-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-token-store.js","sourceRoot":"","sources":["../../../src/mcp/file-token-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,cAAc,GAGf,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,cAAc;IAC/B,aAAa,CAAS;IAEvC,YAAY,aAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IACxE,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,eAAe;QAC3B,MAAM,SAAS,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AyB;YAC3B,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,qCAAqC,eAAe,CAAC,KAAK,CAAC,EAAE,CAC9D,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,kBAAkB,CACxB,WAAoB;QAEpB,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,WAAsC,CAAC;QAEpD,wBAAwB;QACxB,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC5D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAgC,CAAC;QACpD,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;YAChE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC5D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -3,43 +3,28 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- /**
7
- * Interface for MCP OAuth tokens.
8
- */
9
- export interface MCPOAuthToken {
10
- accessToken: string;
11
- refreshToken?: string;
12
- expiresAt?: number;
13
- tokenType: string;
14
- scope?: string;
15
- }
16
- /**
17
- * Interface for stored MCP OAuth credentials.
18
- */
19
- export interface MCPOAuthCredentials {
20
- serverName: string;
21
- token: MCPOAuthToken;
22
- clientId?: string;
23
- tokenUrl?: string;
24
- mcpServerUrl?: string;
25
- updatedAt: number;
26
- }
6
+ import { BaseTokenStore, MCPOAuthToken, MCPOAuthCredentials } from './token-store.js';
7
+ export type { MCPOAuthToken, MCPOAuthCredentials };
27
8
  /**
28
9
  * Class for managing MCP OAuth token storage and retrieval.
10
+ * This class provides backward compatibility with the existing API while
11
+ * delegating to the new BaseTokenStore architecture.
29
12
  */
30
13
  export declare class MCPOAuthTokenStorage {
31
- private static readonly TOKEN_FILE;
32
- private static readonly CONFIG_DIR;
14
+ private static tokenStore;
33
15
  /**
34
- * Get the path to the token storage file.
16
+ * Set a custom token store implementation.
17
+ * This allows for dependency injection and testing with mock implementations.
35
18
  *
36
- * @returns The full path to the token storage file
19
+ * @param store The token store to use
37
20
  */
38
- private static getTokenFilePath;
21
+ static setTokenStore(store: BaseTokenStore): void;
39
22
  /**
40
- * Ensure the config directory exists.
23
+ * Get the current token store implementation.
24
+ *
25
+ * @returns The current token store
41
26
  */
42
- private static ensureConfigDir;
27
+ static getTokenStore(): BaseTokenStore;
43
28
  /**
44
29
  * Load all stored MCP OAuth tokens.
45
30
  *
@@ -3,31 +3,31 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { promises as fs } from 'node:fs';
7
- import * as path from 'node:path';
8
- import * as os from 'node:os';
9
- import { getErrorMessage } from '../utils/errors.js';
6
+ import { FileTokenStore } from './file-token-store.js';
7
+ import { BaseTokenStore, } from './token-store.js';
10
8
  /**
11
9
  * Class for managing MCP OAuth token storage and retrieval.
10
+ * This class provides backward compatibility with the existing API while
11
+ * delegating to the new BaseTokenStore architecture.
12
12
  */
13
13
  export class MCPOAuthTokenStorage {
14
- static TOKEN_FILE = 'mcp-oauth-tokens.json';
15
- static CONFIG_DIR = '.gemini';
14
+ static tokenStore = new FileTokenStore();
16
15
  /**
17
- * Get the path to the token storage file.
16
+ * Set a custom token store implementation.
17
+ * This allows for dependency injection and testing with mock implementations.
18
18
  *
19
- * @returns The full path to the token storage file
19
+ * @param store The token store to use
20
20
  */
21
- static getTokenFilePath() {
22
- const homeDir = os.homedir();
23
- return path.join(homeDir, this.CONFIG_DIR, this.TOKEN_FILE);
21
+ static setTokenStore(store) {
22
+ this.tokenStore = store;
24
23
  }
25
24
  /**
26
- * Ensure the config directory exists.
25
+ * Get the current token store implementation.
26
+ *
27
+ * @returns The current token store
27
28
  */
28
- static async ensureConfigDir() {
29
- const configDir = path.dirname(this.getTokenFilePath());
30
- await fs.mkdir(configDir, { recursive: true });
29
+ static getTokenStore() {
30
+ return this.tokenStore;
31
31
  }
32
32
  /**
33
33
  * Load all stored MCP OAuth tokens.
@@ -35,22 +35,7 @@ export class MCPOAuthTokenStorage {
35
35
  * @returns A map of server names to credentials
36
36
  */
37
37
  static async loadTokens() {
38
- const tokenMap = new Map();
39
- try {
40
- const tokenFile = this.getTokenFilePath();
41
- const data = await fs.readFile(tokenFile, 'utf-8');
42
- const tokens = JSON.parse(data);
43
- for (const credential of tokens) {
44
- tokenMap.set(credential.serverName, credential);
45
- }
46
- }
47
- catch (error) {
48
- // File doesn't exist or is invalid, return empty map
49
- if (error.code !== 'ENOENT') {
50
- console.error(`Failed to load MCP OAuth tokens: ${getErrorMessage(error)}`);
51
- }
52
- }
53
- return tokenMap;
38
+ return this.tokenStore.loadTokens();
54
39
  }
55
40
  /**
56
41
  * Save a token for a specific MCP server.
@@ -62,26 +47,7 @@ export class MCPOAuthTokenStorage {
62
47
  * @param mcpServerUrl Optional MCP server URL
63
48
  */
64
49
  static async saveToken(serverName, token, clientId, tokenUrl, mcpServerUrl) {
65
- await this.ensureConfigDir();
66
- const tokens = await this.loadTokens();
67
- const credential = {
68
- serverName,
69
- token,
70
- clientId,
71
- tokenUrl,
72
- mcpServerUrl,
73
- updatedAt: Date.now(),
74
- };
75
- tokens.set(serverName, credential);
76
- const tokenArray = Array.from(tokens.values());
77
- const tokenFile = this.getTokenFilePath();
78
- try {
79
- await fs.writeFile(tokenFile, JSON.stringify(tokenArray, null, 2), { mode: 0o600 });
80
- }
81
- catch (error) {
82
- console.error(`Failed to save MCP OAuth token: ${getErrorMessage(error)}`);
83
- throw error;
84
- }
50
+ return this.tokenStore.saveToken(serverName, token, clientId, tokenUrl, mcpServerUrl);
85
51
  }
86
52
  /**
87
53
  * Get a token for a specific MCP server.
@@ -90,8 +56,7 @@ export class MCPOAuthTokenStorage {
90
56
  * @returns The stored credentials or null if not found
91
57
  */
92
58
  static async getToken(serverName) {
93
- const tokens = await this.loadTokens();
94
- return tokens.get(serverName) || null;
59
+ return this.tokenStore.getToken(serverName);
95
60
  }
96
61
  /**
97
62
  * Remove a token for a specific MCP server.
@@ -99,25 +64,7 @@ export class MCPOAuthTokenStorage {
99
64
  * @param serverName The name of the MCP server
100
65
  */
101
66
  static async removeToken(serverName) {
102
- const tokens = await this.loadTokens();
103
- if (tokens.delete(serverName)) {
104
- const tokenArray = Array.from(tokens.values());
105
- const tokenFile = this.getTokenFilePath();
106
- try {
107
- if (tokenArray.length === 0) {
108
- // Remove file if no tokens left
109
- await fs.unlink(tokenFile);
110
- }
111
- else {
112
- await fs.writeFile(tokenFile, JSON.stringify(tokenArray, null, 2), {
113
- mode: 0o600,
114
- });
115
- }
116
- }
117
- catch (error) {
118
- console.error(`Failed to remove MCP OAuth token: ${getErrorMessage(error)}`);
119
- }
120
- }
67
+ return this.tokenStore.removeToken(serverName);
121
68
  }
122
69
  /**
123
70
  * Check if a token is expired.
@@ -126,26 +73,13 @@ export class MCPOAuthTokenStorage {
126
73
  * @returns True if the token is expired
127
74
  */
128
75
  static isTokenExpired(token) {
129
- if (!token.expiresAt) {
130
- return false; // No expiry, assume valid
131
- }
132
- // Add a 5-minute buffer to account for clock skew
133
- const bufferMs = 5 * 60 * 1000;
134
- return Date.now() + bufferMs >= token.expiresAt;
76
+ return BaseTokenStore.isTokenExpired(token);
135
77
  }
136
78
  /**
137
79
  * Clear all stored MCP OAuth tokens.
138
80
  */
139
81
  static async clearAllTokens() {
140
- try {
141
- const tokenFile = this.getTokenFilePath();
142
- await fs.unlink(tokenFile);
143
- }
144
- catch (error) {
145
- if (error.code !== 'ENOENT') {
146
- console.error(`Failed to clear MCP OAuth tokens: ${getErrorMessage(error)}`);
147
- }
148
- }
82
+ return this.tokenStore.clearAllTokens();
149
83
  }
150
84
  }
151
85
  //# sourceMappingURL=oauth-token-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-token-storage.js","sourceRoot":"","sources":["../../../src/mcp/oauth-token-storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAyBrD;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACvB,MAAM,CAAU,UAAU,GAAG,uBAAuB,CAAC;IACrD,MAAM,CAAU,UAAU,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACK,MAAM,CAAC,gBAAgB;QAC7B,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,KAAK,CAAC,eAAe;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QACxD,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,E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;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAqB;QACxC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CACpB,UAAkB,EAClB,KAAoB,EACpB,QAAiB,EACjB,QAAiB,EACjB,YAAqB;QAErB,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9B,UAAU,EACV,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,YAAY,CACb,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CACnB,UAAkB;QAElB,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,UAAkB;QACzC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAoB;QACxC,OAAO,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC"}
@@ -66,6 +66,14 @@ export declare class OAuthUtils {
66
66
  * @returns The OAuth configuration
67
67
  */
68
68
  static metadataToOAuthConfig(metadata: OAuthAuthorizationServerMetadata): MCPOAuthConfig;
69
+ /**
70
+ * Discover Oauth Authorization server metadata given an Auth server URL, by
71
+ * trying the standard well-known endpoints.
72
+ *
73
+ * @param authServerUrl The authorization server URL
74
+ * @returns The authorization server metadata or null if not found
75
+ */
76
+ static discoverAuthorizationServerMetadata(authServerUrl: string): Promise<OAuthAuthorizationServerMetadata | null>;
69
77
  /**
70
78
  * Discover OAuth configuration using the standard well-known endpoints.
71
79
  *
@@ -81,6 +81,42 @@ export class OAuthUtils {
81
81
  scopes: metadata.scopes_supported || [],
82
82
  };
83
83
  }
84
+ /**
85
+ * Discover Oauth Authorization server metadata given an Auth server URL, by
86
+ * trying the standard well-known endpoints.
87
+ *
88
+ * @param authServerUrl The authorization server URL
89
+ * @returns The authorization server metadata or null if not found
90
+ */
91
+ static async discoverAuthorizationServerMetadata(authServerUrl) {
92
+ const authServerUrlObj = new URL(authServerUrl);
93
+ const base = `${authServerUrlObj.protocol}//${authServerUrlObj.host}`;
94
+ const endpointsToTry = [];
95
+ // With issuer URLs with path components, try the following well-known
96
+ // endpoints in order:
97
+ if (authServerUrlObj.pathname !== '/') {
98
+ // 1. OAuth 2.0 Authorization Server Metadata with path insertion
99
+ endpointsToTry.push(new URL(`/.well-known/oauth-authorization-server${authServerUrlObj.pathname}`, base).toString());
100
+ // 2. OpenID Connect Discovery 1.0 with path insertion
101
+ endpointsToTry.push(new URL(`/.well-known/openid-configuration${authServerUrlObj.pathname}`, base).toString());
102
+ // 3. OpenID Connect Discovery 1.0 with path appending
103
+ endpointsToTry.push(new URL(`${authServerUrlObj.pathname}/.well-known/openid-configuration`, base).toString());
104
+ }
105
+ // With issuer URLs without path components, and those that failed previous
106
+ // discoveries, try the following well-known endpoints in order:
107
+ // 1. OAuth 2.0 Authorization Server Metadata
108
+ endpointsToTry.push(new URL('/.well-known/oauth-authorization-server', base).toString());
109
+ // 2. OpenID Connect Discovery 1.0
110
+ endpointsToTry.push(new URL('/.well-known/openid-configuration', base).toString());
111
+ for (const endpoint of endpointsToTry) {
112
+ const authServerMetadata = await this.fetchAuthorizationServerMetadata(endpoint);
113
+ if (authServerMetadata) {
114
+ return authServerMetadata;
115
+ }
116
+ }
117
+ console.debug(`Metadata discovery failed for authorization server ${authServerUrl}`);
118
+ return null;
119
+ }
84
120
  /**
85
121
  * Discover OAuth configuration using the standard well-known endpoints.
86
122
  *
@@ -104,18 +140,7 @@ export class OAuthUtils {
104
140
  if (resourceMetadata?.authorization_servers?.length) {
105
141
  // Use the first authorization server
106
142
  const authServerUrl = resourceMetadata.authorization_servers[0];
107
- // The authorization server URL may include a path (e.g., https://github.com/login/oauth)
108
- // We need to preserve this path when constructing the metadata URL
109
- const authServerUrlObj = new URL(authServerUrl);
110
- const authServerPath = authServerUrlObj.pathname === '/' ? '' : authServerUrlObj.pathname;
111
- // Try with the authorization server's path first
112
- let authServerMetadataUrl = new URL(`/.well-known/oauth-authorization-server${authServerPath}`, `${authServerUrlObj.protocol}//${authServerUrlObj.host}`).toString();
113
- let authServerMetadata = await this.fetchAuthorizationServerMetadata(authServerMetadataUrl);
114
- // If that fails, try root as fallback
115
- if (!authServerMetadata && authServerPath) {
116
- authServerMetadataUrl = new URL('/.well-known/oauth-authorization-server', `${authServerUrlObj.protocol}//${authServerUrlObj.host}`).toString();
117
- authServerMetadata = await this.fetchAuthorizationServerMetadata(authServerMetadataUrl);
118
- }
143
+ const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl);
119
144
  if (authServerMetadata) {
120
145
  const config = this.metadataToOAuthConfig(authServerMetadata);
121
146
  if (authServerMetadata.registration_endpoint) {
@@ -124,9 +149,9 @@ export class OAuthUtils {
124
149
  return config;
125
150
  }
126
151
  }
127
- // Fallback: try /.well-known/oauth-authorization-server at the base URL
128
- console.debug(`Trying OAuth discovery fallback at ${wellKnownUrls.authorizationServer}`);
129
- const authServerMetadata = await this.fetchAuthorizationServerMetadata(wellKnownUrls.authorizationServer);
152
+ // Fallback: try well-known endpoints at the base URL
153
+ console.debug(`Trying OAuth discovery fallback at ${serverUrl}`);
154
+ const authServerMetadata = await this.discoverAuthorizationServerMetadata(serverUrl);
130
155
  if (authServerMetadata) {
131
156
  const config = this.metadataToOAuthConfig(authServerMetadata);
132
157
  if (authServerMetadata.registration_endpoint) {
@@ -171,18 +196,7 @@ export class OAuthUtils {
171
196
  return null;
172
197
  }
173
198
  const authServerUrl = resourceMetadata.authorization_servers[0];
174
- // The authorization server URL may include a path (e.g., https://github.com/login/oauth)
175
- // We need to preserve this path when constructing the metadata URL
176
- const authServerUrlObj = new URL(authServerUrl);
177
- const authServerPath = authServerUrlObj.pathname === '/' ? '' : authServerUrlObj.pathname;
178
- // Build auth server metadata URL with the authorization server's path
179
- const authServerMetadataUrl = new URL(`/.well-known/oauth-authorization-server${authServerPath}`, `${authServerUrlObj.protocol}//${authServerUrlObj.host}`).toString();
180
- let authServerMetadata = await this.fetchAuthorizationServerMetadata(authServerMetadataUrl);
181
- // If that fails and we have a path, also try the root path as a fallback
182
- if (!authServerMetadata && authServerPath) {
183
- const rootAuthServerMetadataUrl = new URL('/.well-known/oauth-authorization-server', `${authServerUrlObj.protocol}//${authServerUrlObj.host}`).toString();
184
- authServerMetadata = await this.fetchAuthorizationServerMetadata(rootAuthServerMetadataUrl);
185
- }
199
+ const authServerMetadata = await this.discoverAuthorizationServerMetadata(authServerUrl);
186
200
  if (authServerMetadata) {
187
201
  return this.metadataToOAuthConfig(authServerMetadata);
188
202
  }