Skip to main content
Glama

MCP Hub

by sentilabs01
useSimpleProviders.ts2.59 kB
import { useState, useEffect } from 'react'; import { Provider } from '../types'; const coreProviders: Provider[] = [ { id: 'openai', name: 'OpenAI', status: 'disconnected', color: 'from-green-500 to-emerald-600', icon: 'Bot', requestCount: 0 }, { id: 'anthropic', name: 'Anthropic', status: 'disconnected', color: 'from-orange-500 to-red-500', icon: 'Zap', requestCount: 0 }, { id: 'gemini', name: 'Gemini', status: 'disconnected', color: 'from-blue-500 to-purple-600', icon: 'Sparkles', requestCount: 0 }, { id: 'github', name: 'GitHub', status: 'disconnected', color: 'from-gray-700 to-black', icon: 'Bot', requestCount: 0 } ]; export const useSimpleProviders = () => { const [providers, setProviders] = useState<Provider[]>(coreProviders); const updateProvider = (id: string, updates: Partial<Provider>) => { setProviders(prev => prev.map(p => p.id === id ? { ...p, ...updates } : p) ); }; const setApiKey = async (providerId: string, apiKey: string) => { updateProvider(providerId, { apiKey, status: apiKey ? 'pending' : 'disconnected' }); try { // Save to backend if (apiKey) { await fetch(`/api/credentials/${providerId}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ credentials: { apiKey } }) }); } else { await fetch(`/api/credentials/${providerId}`, { method: 'DELETE' }); } } catch (err) { console.error('Failed to save credentials', err); updateProvider(providerId, { status: 'error' }); } }; const setStatus = (providerId: string, status: Provider['status']) => { updateProvider(providerId, { status }); }; // Load saved credentials on mount useEffect(() => { const loadCredentials = async () => { for (const provider of coreProviders) { try { const res = await fetch(`/api/credentials/${provider.id}`); if (res.ok) { const data = await res.json(); if (data.credentials?.apiKey) { updateProvider(provider.id, { apiKey: data.credentials.apiKey, status: 'connected' }); } } } catch (err) { console.warn(`Failed to load credentials for ${provider.id}`); } } }; loadCredentials(); }, []); return { providers, setApiKey, setStatus }; };

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/sentilabs01/mcpserver'

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