UNPKG

mcp-turso-cloud

Version:

MCP server for integrating Turso with LLMs

49 lines (48 loc) 1.73 kB
/** * Configuration management for the Turso MCP server */ import { z } from 'zod'; // Define configuration schema as specified in the plan export const ConfigSchema = z.object({ // Organization-level authentication TURSO_API_TOKEN: z.string().min(1), TURSO_ORGANIZATION: z.string().min(1), // Optional default database TURSO_DEFAULT_DATABASE: z.string().optional(), // Token management settings TOKEN_EXPIRATION: z.string().default('7d'), TOKEN_PERMISSION: z .enum(['full-access', 'read-only']) .default('full-access'), }); // Parse environment variables using the schema export function load_config() { try { return ConfigSchema.parse({ TURSO_API_TOKEN: process.env.TURSO_API_TOKEN, TURSO_ORGANIZATION: process.env.TURSO_ORGANIZATION, TURSO_DEFAULT_DATABASE: process.env.TURSO_DEFAULT_DATABASE, TOKEN_EXPIRATION: process.env.TOKEN_EXPIRATION || '7d', TOKEN_PERMISSION: process.env.TOKEN_PERMISSION || 'full-access', }); } catch (error) { if (error instanceof z.ZodError) { const missing_fields = error.issues .filter((err) => err.code === 'invalid_type' && err.received === 'undefined') .map((err) => err.path.join('.')); throw new Error(`Missing required configuration: ${missing_fields.join(', ')}\n` + 'Please set these environment variables.'); } throw error; } } // Singleton instance of the configuration let config = null; // Get the configuration, loading it if necessary export function get_config() { if (!config) { config = load_config(); } return config; }