From 253db5ebc1d8f0324110339c53a2a8d2cf2547c2 Mon Sep 17 00:00:00 2001 From: Jerome Date: Thu, 12 Jun 2025 15:04:08 +0100 Subject: [PATCH] Enhance logout to clear MCP OAuth tokens and disconnect all servers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem The logout button only cleared inference provider authentication, leaving MCP OAuth tokens and server connections active. Users remained authenticated to MCP servers after logging out. ## Solution - **Clear MCP OAuth tokens**: Remove OAuth tokens and state for all MCP connections - **Disconnect all servers**: Remove all MCP server connections on logout - **Complete cleanup**: Comprehensive logout that clears all authentication state - **Enhanced confirmation**: Updated dialog to inform users about MCP disconnection ## Technical Implementation - Added MCP context integration to access connections and removal methods - Clear OAuth tokens from localStorage for each OAuth-enabled connection - Remove all MCP servers to properly disconnect and clean up connections - Maintained existing inference provider logout functionality ## User Experience - ✅ **Complete logout**: All authentication state cleared (inference + MCP) - ✅ **Clean slate**: No residual authentication data after logout - ✅ **Clear communication**: User informed about full scope of logout action - ✅ **Security**: No orphaned authentication tokens left behind ## Data Cleared on Logout - Inference provider API keys and OAuth tokens - MCP OAuth tokens and authentication state - Model selection preferences - All active MCP server connections Note: Conversation history remains intact as it's stored separately from auth data. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/components/ConversationSidebar.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/ConversationSidebar.tsx b/src/components/ConversationSidebar.tsx index 3568832..75cb848 100644 --- a/src/components/ConversationSidebar.tsx +++ b/src/components/ConversationSidebar.tsx @@ -2,6 +2,7 @@ import { useConversation } from '@/contexts/ConversationContext'; import { useInference } from '@/contexts/InferenceContext'; +import { useMCP } from '@/contexts/MCPContext'; export function ConversationSidebar() { const { @@ -13,14 +14,30 @@ export function ConversationSidebar() { } = useConversation(); const { clearProvider, provider } = useInference(); + const { connections, removeMcpServer } = useMCP(); const handleNewConversation = () => { createConversation(); }; const handleLogout = () => { - if (confirm('Are you sure you want to log out?')) { + if (confirm('Are you sure you want to log out? This will disconnect all MCP servers and clear your authentication.')) { + // Clear inference provider authentication clearProvider(); + + // Clear MCP OAuth tokens for all connections + connections.forEach(connection => { + if (connection.authType === 'oauth') { + // Clear OAuth tokens and state for this connection + localStorage.removeItem(`mcp_oauth_tokens_${connection.id}`); + localStorage.removeItem(`mcp_oauth_state_${connection.id}`); + } + }); + + // Remove all MCP servers (this will disconnect them) + connections.forEach(connection => { + removeMcpServer(connection.id); + }); } };