# n8n Documentation MCP Server Configuration

# ====================
# COMMON CONFIGURATION
# ====================

# Database Configuration
# For local development: ./data/nodes.db
# For Docker: /app/data/nodes.db
# Custom paths supported in v2.7.16+ (must end with .db)
NODE_DB_PATH=./data/nodes.db

# Logging Level (debug, info, warn, error)
MCP_LOG_LEVEL=info

# Node Environment (development, production)
NODE_ENV=development

# Rebuild database on startup (true/false)
REBUILD_ON_START=false

# =========================
# LOCAL MODE CONFIGURATION
# =========================
# Used when running: npm run start:v2 or npm run dev:v2

# Local MCP Server Configuration
MCP_SERVER_PORT=3000
MCP_SERVER_HOST=localhost
# MCP_AUTH_TOKEN=optional-for-local-development

# =========================
# SIMPLE HTTP MODE
# =========================
# Used for private single-user deployments

# Server mode: stdio (local) or http (remote)
MCP_MODE=stdio

# DEPRECATED: USE_FIXED_HTTP is deprecated as of v2.31.8
# The fixed HTTP implementation does not support SSE streaming required by
# clients like OpenAI Codex. Use the default SingleSessionHTTPServer instead.
# See: https://github.com/czlonkowski/n8n-mcp/issues/524
# USE_FIXED_HTTP=true  # DO NOT USE - deprecated

# HTTP Server Configuration (only used when MCP_MODE=http)
PORT=3000
HOST=0.0.0.0

# Base URL Configuration (optional)
# Set this when running behind a proxy or when the server is accessed via a different URL
# than what it binds to. If not set, URLs will be auto-detected from proxy headers (if TRUST_PROXY is set)
# or constructed from HOST and PORT.
# Examples:
# BASE_URL=https://n8n-mcp.example.com
# BASE_URL=https://your-domain.com:8443
# PUBLIC_URL=https://n8n-mcp.mydomain.com  (alternative to BASE_URL)

# Authentication token for HTTP mode (REQUIRED)
# Generate with: openssl rand -base64 32
AUTH_TOKEN=your-secure-token-here

# CORS origin for HTTP mode (optional)
# Default: * (allow all origins)
# For production, set to your specific domain
# CORS_ORIGIN=https://your-client-domain.com

# Trust proxy configuration for correct IP logging (0=disabled, 1=trust first proxy)
# Set to 1 when running behind a reverse proxy (Nginx, Traefik, etc.)
# Set to the number of proxy hops if behind multiple proxies
# Default: 0 (disabled)
# TRUST_PROXY=0

# =========================
# SECURITY CONFIGURATION
# =========================

# Rate Limiting Configuration
# Protects authentication endpoint from brute force attacks
# Window: Time period in milliseconds (default: 900000 = 15 minutes)
# Max: Maximum authentication attempts per IP within window (default: 20)
# AUTH_RATE_LIMIT_WINDOW=900000
# AUTH_RATE_LIMIT_MAX=20

# SSRF Protection Mode
# Prevents webhooks from accessing internal networks and cloud metadata
#
# Modes:
# - strict (default): Block localhost + private IPs + cloud metadata
#   Use for: Production deployments, cloud environments
#   Security: Maximum
#
# - moderate: Allow localhost, block private IPs + cloud metadata
#   Use for: Local development with local n8n instance
#   Security: Good balance
#   Example: n8n running on http://localhost:5678 or http://host.docker.internal:5678
#
# - permissive: Allow localhost + private IPs, block cloud metadata
#   Use for: Internal network testing, private cloud (NOT for production)
#   Security: Minimal - use with caution
#
# Default: strict
# WEBHOOK_SECURITY_MODE=strict
#
# For local development with local n8n:
# WEBHOOK_SECURITY_MODE=moderate

# Disabled Tools Configuration
# Filter specific tools from registration at startup
# Useful for multi-tenant deployments, security hardening, or feature flags
#
# Format: Comma-separated list of tool names
# Example: DISABLED_TOOLS=n8n_diagnostic,n8n_health_check,custom_tool
#
# Common use cases:
# - Multi-tenant: Hide tools that check env vars instead of instance context
#   Example: DISABLED_TOOLS=n8n_diagnostic,n8n_health_check
# - Security: Disable management tools in production for certain users
# - Feature flags: Gradually roll out new tools
# - Deployment-specific: Different tool sets for cloud vs self-hosted
#
# Default: (empty - all tools enabled)
# DISABLED_TOOLS=

# =========================
# MULTI-TENANT CONFIGURATION
# =========================
# Enable multi-tenant mode for dynamic instance support
# When enabled, n8n API tools will be available for all sessions,
# and instance configuration will be determined from HTTP headers.
# Requests MUST supply both x-n8n-url and x-n8n-key headers; requests
# without complete tenant headers are rejected with HTTP 400. The
# process-level N8N_API_URL / N8N_API_KEY are NOT used as a fallback.
# Default: false (single-tenant mode using environment variables)
ENABLE_MULTI_TENANT=false

# Session isolation strategy for multi-tenant mode
# - "instance": Create separate sessions per instance ID (recommended)
# - "shared": Share sessions but switch contexts (advanced)
# Default: instance
# MULTI_TENANT_SESSION_STRATEGY=instance

# =========================
# N8N API CONFIGURATION
# =========================
# Optional: Enable n8n management tools by providing API credentials
# These tools allow creating, updating, and executing workflows

# n8n instance API URL (without /api/v1 suffix)
# Example: https://your-n8n-instance.com
# N8N_API_URL=

# n8n API Key (get from Settings > API in your n8n instance)
# N8N_API_KEY=

# n8n API request timeout in milliseconds (default: 30000)
# N8N_API_TIMEOUT=30000

# Maximum number of API request retries (default: 3)
# N8N_API_MAX_RETRIES=3

# =========================
# CACHE CONFIGURATION
# =========================
# Optional: Configure instance cache settings for flexible instance support

# Maximum number of cached instances (default: 100, min: 1, max: 10000)
# INSTANCE_CACHE_MAX=100

# Cache TTL in minutes (default: 30, min: 1, max: 1440/24 hours)
# INSTANCE_CACHE_TTL_MINUTES=30

# =========================
# OPENAI API CONFIGURATION
# =========================
# Optional: Enable AI-powered template metadata generation
# Provides structured metadata for improved template discovery

# OpenAI API Key (get from https://platform.openai.com/api-keys)
# OPENAI_API_KEY=

# OpenAI Model for metadata generation (default: gpt-4o-mini)
# OPENAI_MODEL=gpt-4o-mini

# Batch size for metadata generation (default: 100)
# Templates are processed in batches using OpenAI's Batch API for 50% cost savings
# OPENAI_BATCH_SIZE=100

# Enable metadata generation during template fetch (default: false)
# Set to true to automatically generate metadata when running fetch:templates
# METADATA_GENERATION_ENABLED=false

# ========================================
# INTEGRATION TESTING CONFIGURATION
# ========================================
# Configuration for integration tests that call real n8n instance API

# n8n API Configuration for Integration Tests
# For local development: Use your local n8n instance
# For CI: These will be provided by GitHub secrets
# N8N_API_URL=http://localhost:5678
# N8N_API_KEY=

# Pre-activated Webhook Workflows for Testing
# These workflows must be created manually in n8n and activated
# because n8n API doesn't support workflow activation.
#
# Setup Instructions:
# 1. Create 4 workflows in n8n UI (one for each HTTP method)
# 2. Each workflow should have a single Webhook node
# 3. Configure webhook paths: mcp-test-get, mcp-test-post, mcp-test-put, mcp-test-delete
# 4. ACTIVATE each workflow in n8n UI
# 5. Copy the workflow IDs here
#
# N8N_TEST_WEBHOOK_GET_ID=      # Workflow ID for GET method webhook
# N8N_TEST_WEBHOOK_POST_ID=     # Workflow ID for POST method webhook
# N8N_TEST_WEBHOOK_PUT_ID=      # Workflow ID for PUT method webhook
# N8N_TEST_WEBHOOK_DELETE_ID=   # Workflow ID for DELETE method webhook

# Test Configuration
N8N_TEST_CLEANUP_ENABLED=true         # Enable automatic cleanup of test workflows
N8N_TEST_TAG=mcp-integration-test     # Tag applied to all test workflows
N8N_TEST_NAME_PREFIX=[MCP-TEST]       # Name prefix for test workflows