* Load all stored MCP OAuth tokens. * * @returns A map of server names to credentials
()
| 64 | * @returns A map of server names to credentials |
| 65 | */ |
| 66 | static async loadTokens(): Promise<Map<string, MCPOAuthCredentials>> { |
| 67 | const tokenMap = new Map<string, MCPOAuthCredentials>(); |
| 68 | |
| 69 | try { |
| 70 | const tokenFile = this.getTokenFilePath(); |
| 71 | const data = await fs.readFile(tokenFile, 'utf-8'); |
| 72 | const tokens = JSON.parse(data) as MCPOAuthCredentials[]; |
| 73 | |
| 74 | for (const credential of tokens) { |
| 75 | tokenMap.set(credential.serverName, credential); |
| 76 | } |
| 77 | } catch (error) { |
| 78 | // File doesn't exist or is invalid, return empty map |
| 79 | if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { |
| 80 | console.error( |
| 81 | `Failed to load MCP OAuth tokens: ${getErrorMessage(error)}`, |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return tokenMap; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Save a token for a specific MCP server. |
no test coverage detected