MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / validateEnvironment

Function validateEnvironment

server/src/env-validation.ts:110–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108 * Exits the process if any required variables are missing
109 */
110export function validateEnvironment(): void {
111 const missing: string[] = [];
112 const warnings: string[] = [];
113
114 // Check required variables
115 for (const { name, description } of envConfig.required) {
116 if (!process.env[name]) {
117 missing.push(` ${name}: ${description}`);
118 }
119 }
120
121 // Check optional variables and set defaults
122 for (const { name, description, defaultValue } of envConfig.optional) {
123 if (!process.env[name]) {
124 if (defaultValue) {
125 process.env[name] = defaultValue;
126 } else {
127 warnings.push(` ${name}: ${description} (optional, but recommended)`);
128 }
129 }
130 }
131
132 // Validate WORKOS_COOKIE_PASSWORD length if provided
133 if (process.env.WORKOS_COOKIE_PASSWORD && process.env.WORKOS_COOKIE_PASSWORD.length < 32) {
134 warnings.push(' WORKOS_COOKIE_PASSWORD: Must be at least 32 characters long (authentication features will be disabled)');
135 }
136
137 // Report results
138 if (missing.length > 0) {
139 console.error('\n❌ Missing required environment variables:\n');
140 console.error(missing.join('\n'));
141 console.error('\nPlease set these variables in your .env file or environment.');
142 console.error('See .env.example for a template.\n');
143 process.exit(1);
144 }
145
146 if (warnings.length > 0) {
147 console.warn('\n⚠️ Optional environment variables not set:\n');
148 console.warn(warnings.join('\n'));
149 console.warn('\nNote: Authentication and billing features will be disabled without required configuration.\n');
150 } else {
151 console.log('✅ Environment variables validated successfully\n');
152 }
153}
154
155/**
156 * Get a list of all environment variables for documentation

Callers 1

index.tsFile · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected