Skip to main content
Glama

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
NameRequiredDescriptionDefault
accountIdYesThe account ID to remove

Implementation Reference

  • 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}`, }), }, ], }; } }
  • Zod input schema for the remove-account tool defining the accountId parameter.
    { accountId: z.string().describe('The account ID to remove'), },
  • 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}`, }), }, ], }; } } );
  • 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; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ForITLLC/forit-microsoft-graph'

If you have feedback or need assistance with the MCP directory API, please join our Discord server