"use client"; import { useState, useEffect } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { auth } from '@/lib/firebase/config'; import { toast } from 'sonner'; import { Copy, Eye, EyeOff, RefreshCw, Trash2, ExternalLink } from 'lucide-react'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export function MCPConnectionCard() { const [apiKey, setApiKey] = useState(''); const [loading, setLoading] = useState(false); const [showKey, setShowKey] = useState(false); const [hasKey, setHasKey] = useState(false); const mcpServerUrl = typeof window !== 'undefined' ? `${window.location.origin}/api/mcp` : 'https://vibnai.com/api/mcp'; useEffect(() => { loadExistingKey(); }, []); const loadExistingKey = async () => { try { const user = auth.currentUser; if (!user) return; const token = await user.getIdToken(); const response = await fetch('/api/mcp/generate-key', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, }, }); if (response.ok) { const data = await response.json(); setApiKey(data.apiKey); setHasKey(true); } } catch (error) { console.error('Error loading MCP key:', error); } }; const generateKey = async () => { setLoading(true); try { const user = auth.currentUser; if (!user) { toast.error('Please sign in to generate an API key'); return; } const token = await user.getIdToken(); const response = await fetch('/api/mcp/generate-key', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, }, }); if (!response.ok) { throw new Error('Failed to generate API key'); } const data = await response.json(); setApiKey(data.apiKey); setHasKey(true); toast.success('MCP API key generated!'); } catch (error) { console.error('Error generating API key:', error); toast.error('Failed to generate API key'); } finally { setLoading(false); } }; const revokeKey = async () => { setLoading(true); try { const user = auth.currentUser; if (!user) return; const token = await user.getIdToken(); const response = await fetch('/api/mcp/generate-key', { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}`, }, }); if (!response.ok) { throw new Error('Failed to revoke API key'); } setApiKey(''); setHasKey(false); toast.success('MCP API key revoked'); } catch (error) { console.error('Error revoking API key:', error); toast.error('Failed to revoke API key'); } finally { setLoading(false); } }; const copyToClipboard = (text: string, label: string) => { navigator.clipboard.writeText(text); toast.success(`${label} copied to clipboard`); }; const copyAllSettings = () => { const settings = `Name: Vibn Description: Access your Vibn coding projects, sessions, and AI conversation history MCP Server URL: ${mcpServerUrl} Authentication: Bearer API Key: ${apiKey}`; navigator.clipboard.writeText(settings); toast.success('All settings copied! Paste into ChatGPT'); }; return (
ChatGPT Integration (MCP) Connect ChatGPT to your Vibn data using the Model Context Protocol
Setup Guide
{!hasKey ? (

Generate an API key to connect ChatGPT to your Vibn projects. This key allows ChatGPT to access your project data, coding sessions, and conversation history.

) : (
{/* MCP Server URL */}
{/* API Key */}

This key doesn't expire. Keep it secure and never share it publicly.

{/* Quick Copy Button */}

Quick Setup for ChatGPT

Click below to copy all settings, then paste them into ChatGPT's "New Connector" form

{/* Setup Instructions */}

Setup Steps:

  1. Click "Copy All Settings" above
  2. Open ChatGPT and go to Settings → Personalization → Custom Tools
  3. Click "Add New Connector"
  4. Fill in the form with the copied settings
  5. Set Authentication to "Bearer" and paste the API Key
  6. Check "I understand" and click Create
{/* Try It */}

✨ Try asking ChatGPT:

  • • "Show me my Vibn projects"
  • • "What are my recent coding sessions?"
  • • "How much have I spent on AI this month?"
{/* Revoke Key */}
Revoke MCP API Key? This will immediately disconnect ChatGPT from your Vibn data. You'll need to generate a new key to reconnect. Cancel Revoke Key
)}
); }