Skip to main content
Glama

Ultra MCP

connection.ts1.51 kB
import { drizzle } from 'drizzle-orm/libsql'; import { createClient } from '@libsql/client'; import { ConfigManager } from '../config/manager'; import * as schema from './schema'; import { logger } from '../utils/logger'; let db: ReturnType<typeof drizzle> | null = null; export async function getDatabase() { if (db) { return db; } const configManager = new ConfigManager(); const dbPath = configManager.getDatabasePath(); try { // Use libsql with local file const client = createClient({ url: `file:${dbPath}`, }); db = drizzle(client, { schema }); // Test the connection by creating the table if it doesn't exist // This is a simple way to initialize the database try { await db.select().from(schema.llmRequests).limit(1).execute(); } catch { // Table might not exist yet, that's fine logger.log('Database initialized, will create tables on first migration'); } logger.log('Database connected using @libsql/client'); return db; } catch (error) { throw new Error(`Failed to connect to database: ${error instanceof Error ? error.message : String(error)}`); } } export function isDatabaseConnected(): boolean { return db !== null; } // Close database connection export async function closeDatabase(): Promise<void> { if (db) { try { // libsql client doesn't need explicit closing db = null; } catch (error) { logger.warn('Error closing database:', error); } } }

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/RealMikeChong/ultra-mcp'

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