Skip to main content
Glama
vsoneji
by vsoneji
appConfig.ts1.99 kB
import { z } from 'zod' import { type Env, type ValidatedEnv } from '../../types/env.js' import { logger } from '../shared/log.js' const envSchema = z.object({ SCHWAB_CLIENT_ID: z .string({ required_error: 'SCHWAB_CLIENT_ID is required for OAuth authentication', }) .min(1, 'SCHWAB_CLIENT_ID cannot be empty'), SCHWAB_CLIENT_SECRET: z .string({ required_error: 'SCHWAB_CLIENT_SECRET is required for OAuth authentication', }) .min(1, 'SCHWAB_CLIENT_SECRET cannot be empty'), SCHWAB_REDIRECT_URI: z .string({ required_error: 'SCHWAB_REDIRECT_URI is required for OAuth callback', }) .url('SCHWAB_REDIRECT_URI must be a valid URL'), LOG_LEVEL: z .enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']) .optional() .default('info'), ENVIRONMENT: z .enum(['development', 'staging', 'production']) .optional() .default('production'), PORT: z.coerce.number().optional().default(3000), }) function buildConfigInternal(env: Env): ValidatedEnv { try { const validated = envSchema.parse(env) return Object.freeze(validated) as ValidatedEnv } catch (error) { if (error instanceof z.ZodError) { const issues = error.issues .map((issue) => { const path = issue.path.join('.') return ` - ${path}: ${issue.message}` }) .join('\n') const msg = `Environment validation failed:\n${issues}` logger.error(msg) throw new Error(msg) } throw error } } // Memoized singleton config getter export const getConfig = (() => { let cachedConfig: ValidatedEnv | null = null let cachedEnvHash: string | null = null return (env: Env): ValidatedEnv => { // Create a simple hash of the env object for memoization const envHash = JSON.stringify( Object.keys(env) .sort() .map((key) => [key, (env as any)[key]]), ) if (cachedConfig && cachedEnvHash === envHash) { return cachedConfig } cachedConfig = buildConfigInternal(env) cachedEnvHash = envHash return cachedConfig } })()

Latest Blog Posts

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/vsoneji/schwab-mcp'

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