select-account
Select a specific Microsoft account to manage multiple tenants and access Microsoft 365 services through the Microsoft Graph API.
Instructions
Select a specific Microsoft account to use
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | The account ID to select |
Implementation Reference
- src/auth-tools.ts:125-166 (registration)Registers the 'select-account' MCP tool. Includes tool name, description, input schema (accountId: string), and handler function that calls authManager.selectAccount and returns success/error response.server.tool( 'select-account', 'Select a specific Microsoft account to use', { accountId: z.string().describe('The account ID to select'), }, async ({ accountId }) => { try { const success = await authManager.selectAccount(accountId); if (success) { return { content: [ { type: 'text', text: JSON.stringify({ message: `Selected account: ${accountId}` }), }, ], }; } else { return { content: [ { type: 'text', text: JSON.stringify({ error: `Account not found: ${accountId}` }), }, ], }; } } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Failed to select account: ${(error as Error).message}`, }), }, ], }; } } );
- src/auth-tools.ts:131-166 (handler)The handler function for the 'select-account' tool. Takes accountId, calls authManager.selectAccount(accountId), and formats success or error response as MCP content.async ({ accountId }) => { try { const success = await authManager.selectAccount(accountId); if (success) { return { content: [ { type: 'text', text: JSON.stringify({ message: `Selected account: ${accountId}` }), }, ], }; } else { return { content: [ { type: 'text', text: JSON.stringify({ error: `Account not found: ${accountId}` }), }, ], }; } } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Failed to select account: ${(error as Error).message}`, }), }, ], }; } } );
- src/auth.ts:487-505 (helper)Core helper method in AuthManager class that implements account selection logic: finds account by ID, sets selectedAccountId, persists to storage (keytar/file), clears token cache, and logs.async selectAccount(accountId: string): Promise<boolean> { const accounts = await this.listAccounts(); const account = accounts.find((acc: AccountInfo) => acc.homeAccountId === accountId); if (!account) { logger.error(`Account with ID ${accountId} not found`); return false; } this.selectedAccountId = accountId; await this.saveSelectedAccount(); // Clear cached tokens to force refresh with new account this.accessToken = null; this.tokenExpiry = null; logger.info(`Selected account: ${account.username} (${accountId})`); return true; }