MCPcopy Create free account
hub / github.com/anus-dev/ANUS / loadTokens

Method loadTokens

packages/core/src/mcp/oauth-token-storage.ts:66–87  ·  view source on GitHub ↗

* Load all stored MCP OAuth tokens. * * @returns A map of server names to credentials

()

Source from the content-addressed store, hash-verified

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.

Callers 4

saveTokenMethod · 0.95
getTokenMethod · 0.95
removeTokenMethod · 0.95

Calls 4

getTokenFilePathMethod · 0.95
getErrorMessageFunction · 0.85
readFileMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected