logout
Terminate active Microsoft account sessions to end access to Microsoft 365 services and protect account security.
Instructions
Log out from Microsoft account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/auth-tools.ts:59-80 (handler)MCP tool 'logout' handler: executes authManager.logout() and returns JSON text response with success or error message.server.tool('logout', 'Log out from Microsoft account', {}, async () => { try { await authManager.logout(); return { content: [ { type: 'text', text: JSON.stringify({ message: 'Logged out successfully' }), }, ], }; } catch { return { content: [ { type: 'text', text: JSON.stringify({ error: 'Logout failed' }), }, ], }; } });
- src/auth.ts:431-464 (helper)AuthManager.logout(): core implementation that clears MSAL token cache, removes all accounts, deletes stored credentials from keytar or fallback files, and resets auth state.async logout(): Promise<boolean> { try { const accounts = await this.msalApp.getTokenCache().getAllAccounts(); for (const account of accounts) { await this.msalApp.getTokenCache().removeAccount(account); } this.accessToken = null; this.tokenExpiry = null; this.selectedAccountId = null; try { const kt = await getKeytar(); if (kt) { await kt.deletePassword(SERVICE_NAME, TOKEN_CACHE_ACCOUNT); await kt.deletePassword(SERVICE_NAME, SELECTED_ACCOUNT_KEY); } } catch (keytarError) { logger.warn(`Keychain deletion failed: ${(keytarError as Error).message}`); } if (fs.existsSync(FALLBACK_PATH)) { fs.unlinkSync(FALLBACK_PATH); } if (fs.existsSync(SELECTED_ACCOUNT_PATH)) { fs.unlinkSync(SELECTED_ACCOUNT_PATH); } return true; } catch (error) { logger.error(`Error during logout: ${(error as Error).message}`); throw error; } }
- src/server.ts:81-83 (registration)Calls registerAuthTools which includes registration of the 'logout' tool among other auth tools.if (shouldRegisterAuthTools) { // Pass graphClient to enable the graph-request tool registerAuthTools(this.server, this.authManager, this.graphClient);