UNPKG

@dw8k/mcp-fallback-server

Version:

MCP fallback server that extracts keywords from prompts and triggers tool recommendations.

50 lines 3.03 kB
import { z } from 'zod'; // console.error('[MCP Fallback Server DEBUG] Config loading started.'); // console.error('[MCP Fallback Server DEBUG] Initial NODE_ENV:', process.env.NODE_ENV); // console.error('[MCP Fallback Server DEBUG] Initial CRAWLER_API_BASE_URL:', process.env.CRAWLER_API_BASE_URL); // console.error('[MCP Fallback Server DEBUG] Initial GUI_BE_API_BASE_URL:', process.env.GUI_BE_API_BASE_URL); // console.error('[MCP Fallback Server DEBUG] process.cwd():', process.cwd()); // dotenv related lines removed as environment variables are expected to be injected directly // console.error('[MCP Fallback Server DEBUG] Using direct process.env values:'); // console.error('[MCP Fallback Server DEBUG] process.env.CRAWLER_API_BASE_URL:', process.env.CRAWLER_API_BASE_URL); // console.error('[MCP Fallback Server DEBUG] process.env.GUI_BE_API_BASE_URL:', process.env.GUI_BE_API_BASE_URL); // Define the schema for environment variables const appSchema = z.object({ NODE_ENV: z.enum(['development', 'production', 'test']).default('development'), GUI_BE_API_BASE_URL: z.string().url({ message: "Invalid or missing GUI_BE_API_BASE_URL" }), CRAWLER_API_BASE_URL: z.string().url({ message: "Invalid or missing CRAWLER_API_BASE_URL" }), SERVER_NAME: z.string().default('MCP Fallback Server'), SERVER_VERSION: z.string().default('0.1.0'), // This could also be sourced from package.json // Add other environment variables here }); // Validate and export the configuration // eslint-disable-next-line @typescript-eslint/no-explicit-any let validatedConfig; try { // console.error('[MCP Fallback Server DEBUG] Attempting to parse process.env with Zod.'); validatedConfig = appSchema.parse(process.env); // console.error('[MCP Fallback Server DEBUG] Zod parsing successful.'); } catch (error) { // console.error('[MCP Fallback Server DEBUG] Error during Zod parsing or other initialization error:', error); if (error instanceof z.ZodError) { console.error('[MCP Fallback Server CRITICAL] Environment variable validation error (ZodError details):', JSON.stringify(error.errors, null, 2)); // Rethrow or handle critical error, exiting might be too abrupt for a library // but for a standalone server, it's often appropriate. // For now, log and rethrow to ensure visibility. // process.exit(1); // Avoid process.exit in library-like modules if possible, let the application handle it. throw new Error(`Configuration validation failed: ${error.message}`); } // Re-throw other errors throw error; } export const config = { nodeEnv: validatedConfig.NODE_ENV, crawlerApiBaseUrl: validatedConfig.CRAWLER_API_BASE_URL, guiBeApiBaseUrl: validatedConfig.GUI_BE_API_BASE_URL, serverName: validatedConfig.SERVER_NAME, serverVersion: validatedConfig.SERVER_VERSION, // Add other config properties here }; // console.error('[MCP Fallback Server DEBUG] Config loading finished.'); //# sourceMappingURL=index.js.map