select-account
Choose a specific Microsoft account to access Microsoft Graph API services across multiple tenants, enabling interaction with Microsoft 365 resources.
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:126-167 (registration)Registration of the MCP 'select-account' tool, including schema (accountId: string) and handler that calls AuthManager.selectAccount() and formats 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.ts:471-489 (handler)Core implementation of account selection logic in AuthManager: locates account by ID, updates selectedAccountId, persists to storage (keytar/file), clears token cache for refresh.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; }
- src/server.ts:82-84 (registration)Calls registerAuthTools to register all authentication tools including 'select-account' on the MCP server.// Pass graphClient to enable the graph-request tool registerAuthTools(this.server, this.authManager, this.graphClient); }