fix: resolve tool count discrepancy in Docker environments (#6)
- Implement dynamic n8n API configuration checking - Remove static config export in favor of lazy getter function - Fix management tools not being registered when env vars set after startup - Optimize logger performance with cached environment variables - Clean up debug logging and remove console.error usage - Bump version to 2.7.1 This ensures all 38 tools (22 documentation + 16 management) are properly registered regardless of when environment variables become available. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,9 +2,6 @@ import { z } from 'zod';
|
||||
import dotenv from 'dotenv';
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
|
||||
// n8n API configuration schema
|
||||
const n8nApiConfigSchema = z.object({
|
||||
N8N_API_URL: z.string().url().optional(),
|
||||
@@ -13,12 +10,20 @@ const n8nApiConfigSchema = z.object({
|
||||
N8N_API_MAX_RETRIES: z.coerce.number().positive().default(3),
|
||||
});
|
||||
|
||||
// Track if we've loaded env vars
|
||||
let envLoaded = false;
|
||||
|
||||
// Parse and validate n8n API configuration
|
||||
export function loadN8nApiConfig() {
|
||||
export function getN8nApiConfig() {
|
||||
// Load environment variables on first access
|
||||
if (!envLoaded) {
|
||||
dotenv.config();
|
||||
envLoaded = true;
|
||||
}
|
||||
|
||||
const result = n8nApiConfigSchema.safeParse(process.env);
|
||||
|
||||
if (!result.success) {
|
||||
logger.warn('n8n API configuration validation failed:', result.error.format());
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,16 +31,9 @@ export function loadN8nApiConfig() {
|
||||
|
||||
// Check if both URL and API key are provided
|
||||
if (!config.N8N_API_URL || !config.N8N_API_KEY) {
|
||||
logger.info('n8n API not configured. Management tools will be disabled.');
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.info('n8n API configured successfully', {
|
||||
url: config.N8N_API_URL,
|
||||
timeout: config.N8N_API_TIMEOUT,
|
||||
maxRetries: config.N8N_API_MAX_RETRIES,
|
||||
});
|
||||
|
||||
return {
|
||||
baseUrl: config.N8N_API_URL,
|
||||
apiKey: config.N8N_API_KEY,
|
||||
@@ -44,13 +42,11 @@ export function loadN8nApiConfig() {
|
||||
};
|
||||
}
|
||||
|
||||
// Export the configuration (null if not configured)
|
||||
export const n8nApiConfig = loadN8nApiConfig();
|
||||
|
||||
// Helper to check if n8n API is configured
|
||||
// Helper to check if n8n API is configured (lazy check)
|
||||
export function isN8nApiConfigured(): boolean {
|
||||
return n8nApiConfig !== null;
|
||||
const config = getN8nApiConfig();
|
||||
return config !== null;
|
||||
}
|
||||
|
||||
// Type export
|
||||
export type N8nApiConfig = NonNullable<ReturnType<typeof loadN8nApiConfig>>;
|
||||
export type N8nApiConfig = NonNullable<ReturnType<typeof getN8nApiConfig>>;
|
||||
Reference in New Issue
Block a user