list-accounts
Retrieve all Microsoft accounts accessible through the ForIT Microsoft Graph server to manage 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-123 (registration)Registration of the 'list-accounts' MCP tool, including description, empty input schema, and handler function that lists accounts via AuthManager and returns formatted JSON.server.tool('list-accounts', 'List all available Microsoft accounts', {}, async () => { try { const accounts = await authManager.listAccounts(); // No 'selected' field - accountId is always required when multiple accounts exist const result = accounts.map((account) => ({ id: account.homeAccountId, username: account.username, name: account.name, })); 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-123 (handler)The inline async handler function for the 'list-accounts' tool that executes the logic: fetches accounts from AuthManager, maps to id/username/name, and returns as MCP content.server.tool('list-accounts', 'List all available Microsoft accounts', {}, async () => { try { const accounts = await authManager.listAccounts(); // No 'selected' field - accountId is always required when multiple accounts exist const result = accounts.map((account) => ({ id: account.homeAccountId, username: account.username, name: account.name, })); 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:483-485 (helper)Supporting method in AuthManager class that retrieves all cached Microsoft accounts from the MSAL token cache.async listAccounts(): Promise<AccountInfo[]> { return await this.msalApp.getTokenCache().getAllAccounts(); }