remove-account
Remove cached Microsoft accounts from the ForIT Microsoft Graph server to manage multi-tenant access and maintain account security.
Instructions
Remove a Microsoft account from the cache
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | The account ID to remove |
Implementation Reference
- src/auth-tools.ts:175-209 (handler)The handler function that implements the 'remove-account' MCP tool logic. It calls AuthManager.removeAccount(accountId) and formats the response as MCP content.async ({ accountId }) => { try { const success = await authManager.removeAccount(accountId); if (success) { return { content: [ { type: 'text', text: JSON.stringify({ message: `Removed 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 remove account: ${(error as Error).message}`, }), }, ], }; } }
- src/auth-tools.ts:172-174 (schema)Zod input schema for the remove-account tool defining the accountId parameter.{ accountId: z.string().describe('The account ID to remove'), },
- src/auth-tools.ts:169-210 (registration)Registration of the 'remove-account' MCP tool using server.tool(), including name, description, schema, and handler.server.tool( 'remove-account', 'Remove a Microsoft account from the cache', { accountId: z.string().describe('The account ID to remove'), }, async ({ accountId }) => { try { const success = await authManager.removeAccount(accountId); if (success) { return { content: [ { type: 'text', text: JSON.stringify({ message: `Removed 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 remove account: ${(error as Error).message}`, }), }, ], }; } } );
- src/auth.ts:491-517 (helper)AuthManager.removeAccount helper method that removes the specified account from the MSAL token cache and handles selected account clearing.async removeAccount(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; } try { await this.msalApp.getTokenCache().removeAccount(account); // If this was the selected account, clear the selection if (this.selectedAccountId === accountId) { this.selectedAccountId = null; await this.saveSelectedAccount(); this.accessToken = null; this.tokenExpiry = null; } logger.info(`Removed account: ${account.username} (${accountId})`); return true; } catch (error) { logger.error(`Failed to remove account ${accountId}: ${(error as Error).message}`); return false; } }