logout
Invalidate the current authentication token to securely end your session with the PI Dashboard API.
Instructions
Invalidate the current token and end the session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- build/index.js:536-572 (registration)Registration and handler implementation of the 'logout' tool. It checks if API URL and auth token are set, calls the /tokens/invalidate endpoint to invalidate the session on the server, clears local authToken and connectionVerified state, and handles errors by forcing local logout.// Logout tool server.tool("logout", "Invalidate the current token and end the session", {}, async () => { try { if (!apiUrlSet) { return { isError: true, content: [{ type: "text", text: "API URL not set. Please set the API URL first using the set-api-url tool." }] }; } if (!authToken) { return { isError: true, content: [{ type: "text", text: "Not authenticated yet. No need to logout." }] }; } await authenticatedRequest("/tokens/invalidate", "POST"); authToken = null; connectionVerified = false; return { content: [{ type: "text", text: "Logged out successfully. Token invalidated." }] }; } catch (error) { authToken = null; // Force logout even if API call fails connectionVerified = false; return { isError: true, content: [{ type: "text", text: `Error during logout: ${getErrorMessage(error)}. Token cleared locally.` }] }; } });