list-accounts
Retrieve all available Microsoft accounts for managing Microsoft 365 services across multiple tenants.
Instructions
List all available Microsoft accounts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/auth-tools.ts:95-124 (handler)The inline handler function for the 'list-accounts' MCP tool. It fetches all accounts using authManager.listAccounts(), identifies the selected one, maps to a simple format, and returns as JSON text content.server.tool('list-accounts', 'List all available Microsoft accounts', {}, async () => { try { const accounts = await authManager.listAccounts(); const selectedAccountId = authManager.getSelectedAccountId(); const result = accounts.map((account) => ({ id: account.homeAccountId, username: account.username, name: account.name, selected: account.homeAccountId === selectedAccountId, })); return { content: [ { type: 'text', text: JSON.stringify({ accounts: result }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Failed to list accounts: ${(error as Error).message}` }), }, ], }; } });
- src/auth-tools.ts:95-124 (registration)Registration of the 'list-accounts' tool on the MCP server within registerAuthTools, including empty input schema {} and the handler.server.tool('list-accounts', 'List all available Microsoft accounts', {}, async () => { try { const accounts = await authManager.listAccounts(); const selectedAccountId = authManager.getSelectedAccountId(); const result = accounts.map((account) => ({ id: account.homeAccountId, username: account.username, name: account.name, selected: account.homeAccountId === selectedAccountId, })); return { content: [ { type: 'text', text: JSON.stringify({ accounts: result }), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Failed to list accounts: ${(error as Error).message}` }), }, ], }; } });
- src/auth.ts:467-469 (helper)AuthManager.listAccounts() method, which retrieves all cached accounts from the MSAL token cache. Called by the tool handler.async listAccounts(): Promise<AccountInfo[]> { return await this.msalApp.getTokenCache().getAllAccounts(); }