config.ts•1.62 kB
/**
* Configuration management for Forensics Connection MCP Server
*/
import { config as loadEnv } from 'dotenv';
// Load environment variables
loadEnv();
export interface Config {
/** OpenAI API key for LLM-powered relationship analysis */
openaiApiKey: string;
/** OpenAI model to use for analysis (default: gpt-4o-mini) */
openaiModel: string;
/** OpenAI organization ID (optional) */
openaiOrgId?: string;
/** Server port for HTTP transport */
port: number;
/** Environment (development/production) */
environment: string;
}
/**
* Load and validate configuration from environment variables
*/
export function loadConfig(): Config {
const openaiApiKey = process.env.OPENAI_API_KEY;
if (!openaiApiKey) {
throw new Error(
'OPENAI_API_KEY environment variable is required. ' +
'Please set it to your OpenAI API key.'
);
}
return {
openaiApiKey,
openaiModel: process.env.OPENAI_MODEL || 'gpt-4o-mini',
openaiOrgId: process.env.OPENAI_ORG_ID,
port: parseInt(process.env.PORT || '3002', 10),
environment: process.env.NODE_ENV || 'development',
};
}
/**
* Validate configuration values
*/
export function validateConfig(config: Config): void {
if (!config.openaiApiKey || typeof config.openaiApiKey !== 'string') {
throw new Error('Invalid OpenAI API key configuration');
}
if (config.port < 1 || config.port > 65535) {
throw new Error('Port must be between 1 and 65535');
}
if (!['development', 'production', 'test'].includes(config.environment)) {
console.warn(`Unknown environment: ${config.environment}`);
}
}