# Full MCP Gateway configuration -- all options with defaults shown.
# Copy this file and uncomment/modify sections as needed.
# Usage: mcp-gateway --config gateway-full.yaml

# Load environment files before config processing.
# Supports ~ expansion. Files that don't exist are silently skipped.
# Variables are set into the process environment for {env.VAR} resolution.
env_files:
  - ~/.mcp-gateway/.env
  # - ~/.claude/secrets.env

# --- Server ---

server:
  host: "127.0.0.1"              # Bind address
  port: 39400                     # Listen port
  request_timeout: 30s            # Per-request timeout
  shutdown_timeout: 30s           # Graceful shutdown timeout
  max_body_size: 10485760         # Max request body size in bytes (10 MB)

# --- Authentication ---

auth:
  enabled: false                  # Enable auth (set true for networked deployments)

  # Bearer token for simple auth.
  # Options: "auto" (random, logged at startup), "env:VAR_NAME", or a literal string.
  # bearer_token: "auto"

  # API keys for multi-client access with per-client restrictions.
  # `env:VAR_NAME` secret references must exist at startup.
  # api_keys:
  #   - key: "env:CLIENT_A_KEY"
  #     name: "Client A"
  #     rate_limit: 100           # Requests per minute (0 = unlimited)
  #     backends: ["tavily"]      # Restrict to specific backends (empty = all)
  #     admin: false              # Set true only for UI/config management keys
  #   - key: "my-literal-key"
  #     name: "Client B"
  #     backends: []              # All backends

  # Paths that bypass authentication.
  public_paths:
    - /health

# --- Meta-MCP ---

meta_mcp:
  enabled: true                   # Enable Meta-MCP mode (12 tools minimum / 15 with webhook status; README benchmark uses 14 without it)
  cache_tools: true               # Cache tool lists from backends
  cache_ttl: 5m                   # Tool cache TTL
  # Backends to pre-connect and cache on startup.
  warm_start: []
  # warm_start:
  #   - tavily

  # Pin high-value tools directly in tools/list for one-hop invocation.
  # These tools appear with full schemas alongside the Meta-MCP surface,
  # while preserving a small prompt footprint for everything else.
  # Backends hosting surfaced tools are auto-added to warm_start.
  surfaced_tools: []
  # surfaced_tools:
  #   - server: tavily
  #     tool: tavily_search
  #   - server: brave
  #     tool: brave_web_search

# --- Streaming ---

streaming:
  enabled: true                   # Enable SSE streaming for notifications
  buffer_size: 100                # Notification buffer size per client
  keep_alive_interval: 15s        # SSE keep-alive interval
  # Backends to auto-subscribe for notifications.
  auto_subscribe: []

# --- Failsafes ---

failsafe:
  circuit_breaker:
    enabled: true
    failure_threshold: 5          # Failures before circuit opens
    success_threshold: 3          # Successes in half-open to close
    reset_timeout: 30s            # Time before half-open retry

  retry:
    enabled: true
    max_attempts: 3               # Total attempts (1 original + 2 retries)
    initial_backoff: 100ms        # First retry delay
    max_backoff: 10s              # Maximum retry delay
    multiplier: 2.0               # Backoff multiplier

  rate_limit:
    enabled: true
    requests_per_second: 100      # Per-backend RPS
    burst_size: 50                # Token bucket burst

  health_check:
    enabled: true
    interval: 30s                 # Health check interval
    timeout: 5s                   # Health check timeout

# --- Response Cache ---

cache:
  enabled: true                   # Enable response caching
  default_ttl: 60s                # Default cache TTL
  max_entries: 10000              # Max cached responses before eviction

# --- Capabilities (REST API integration) ---

capabilities:
  enabled: true                   # Enable capability system
  name: fulcrum                   # Backend name shown in gateway_list_servers
  directories:                    # Directories to load capability YAMLs from
    - ./capabilities

# --- Cost Governance (RFC-0075) ---

# cost_governance:
#   enabled: false                  # Enable cost tracking and budget enforcement
#   currency: "USD"                 # Currency label (informational)
#   default_cost: 0.0              # Default cost per tool invocation
#   budgets:
#     daily: 10.0                  # Daily budget limit (null = unlimited)
#     per_tool:                    # Per-tool daily budget overrides
#       expensive_api: 2.0
#     per_key:                     # Per-API-key daily budgets
#       heavy_user_key: 5.0
#   alerts:                        # Budget alert thresholds (sorted by at_percent)
#     - at_percent: 50
#       action: Log                # Log, Notify, or Block
#     - at_percent: 80
#       action: Notify
#     - at_percent: 100
#       action: Block
#   tool_costs:                    # Explicit per-tool costs (overrides default_cost)
#     tavily_search: 0.01
#     brave_search: 0.005
#   alternatives:                  # Cheaper alternatives for cost suggestions
#     search: [brave_search, tavily_search]

# --- Security Firewall (RFC-0071) ---

# security:
#   firewall:
#     enabled: true                # Enable bidirectional request/response scanning
#     scan_requests: true          # Scan tool arguments for injection
#     scan_responses: true         # Scan tool outputs for credential leaks
#     credential_redaction: true   # Auto-redact AWS keys, GitHub tokens, JWTs, etc.
#     prompt_injection_detection: true
#     anomaly_detection: false     # Opt-in: flag unusual tool transition patterns
#     anomaly_threshold: 0.7      # 0.0-1.0, higher = more permissive
#     audit_log: /var/log/mcp-gateway/audit.ndjson  # NDJSON audit trail
#     rules:                       # Per-tool glob-matched rules
#       - tool_match: "exec_*"
#         action: Block            # Allow, Warn, or Block
#         reason: "Execution tools blocked by policy"
#         scan: [ShellInjection, PathTraversal]
#       - tool_match: "*"
#         action: Warn
#         scan: [Credentials, SqlInjection]

# --- Context Integrity (tool-result boundary protection) ---

# security:
#   context_integrity:
#     # monitor_only is the default safe rollout. Use team_shared to enforce the
#     # free/core shared-team baseline. enterprise_strict is enterprise scope.
#     preset: monitor_only          # monitor_only, local_developer, team_shared, audit_only, enterprise_strict

# --- Config Export (RFC-0070) ---

# config_export:
#   enabled: true                  # Enable `mcp-gateway config export` command
#   format: yaml                   # Export format: yaml or json
#   redact_secrets: true           # Mask secrets (env vars, tokens) as "***"
#   include_defaults: true         # Include default values in export

# --- Auto-Discovery (RFC-0074) ---

# discovery:
#   enabled: true                  # Enable automatic MCP server discovery
#   scan_interval: 60s             # How often to scan for new servers
#   sources:                       # Discovery sources to scan
#     - type: npm                  # Scan node_modules for MCP servers
#       enabled: true
#     - type: pip                  # Scan pip packages for MCP servers
#       enabled: true
#     - type: docker               # Scan Docker containers exposing MCP
#       enabled: false
#   auto_register: false           # Auto-register discovered servers (requires confirmation if false)
#   quality_threshold: 0.5         # Minimum quality score (0.0-1.0) to suggest a discovery

# --- Semantic Search (RFC-0072) ---

# semantic_search:
#   enabled: true                  # Enable TF-IDF semantic tool search
#   max_results: 10                # Maximum results per search query
#   min_score: 0.1                 # Minimum relevance score (0.0-1.0)
#   feedback_enabled: true         # Enable relevance feedback learning
#   feedback_decay: 0.95           # Decay factor for older feedback signals

# --- Tool Profiles (RFC-0073) ---

# tool_profiles:
#   enabled: true                  # Enable tool usage profiling and analytics
#   persistence_path: ./data/tool_profiles.json  # Where to persist profile data
#   persistence_interval: 300s     # How often to flush profiles to disk
#   max_tools_tracked: 10000       # Maximum number of tools to track
#   analytics:
#     latency_histogram: true      # Track latency distribution per tool
#     error_categorization: true   # Categorize errors by type
#     usage_trends: true           # Track hourly/daily usage trends

# --- Backends (MCP servers) ---

backends:
  # Example: stdio backend (spawns a subprocess)
  # tavily:
  #   command: "npx -y @anthropic/mcp-server-tavily"
  #   description: "Web search via Tavily"
  #   enabled: true
  #   timeout: 30s
  #   idle_timeout: 300s          # Hibernate after 5 min idle
  #   env:
  #     TAVILY_API_KEY: "${TAVILY_API_KEY}"
  #   cwd: /tmp                   # Working directory (stdio only)

  # Example: HTTP backend (connects to running server)
  # context7:
  #   http_url: "http://localhost:8080/mcp"
  #   description: "Documentation lookup"
  #   streamable_http: true       # Use Streamable HTTP (no SSE handshake)
  #   protocol_version: "2025-03-26"  # Override protocol version
  #   headers:
  #     Authorization: "Bearer ${API_TOKEN}"

  # Example: SSE backend
  # pieces:
  #   http_url: "http://localhost:39300/sse"
  #   description: "Pieces LTM"

  # Example: GitMCP — free remote MCP server that auto-generates docs + code
  # search tools for any public GitHub repository (https://gitmcp.io).
  #
  # The `/docs` route is a dynamic dispatcher: the tools it exposes
  # (`fetch_generic_url_content`, `search_generic_code`, `search_generic_documentation`)
  # accept a repo URL as an argument, so a single backend covers every GitHub repo.
  #
  # For a repo-pinned backend, point `http_url` at the repo-specific route:
  #   gitmcp_mcp_gateway:
  #     http_url: "https://gitmcp.io/MikkoParkkola/mcp-gateway/sse"
  #     description: "GitMCP — docs + search for MikkoParkkola/mcp-gateway"
  # Repo-pinned routes expose tools named after the repo
  # (e.g. `fetch_mcp_gateway_documentation`, `search_mcp_gateway_code`).
  #
  # Transport: SSE (http_url ends in /sse, streamable_http defaults to false).
  # Auth: none required for public repos.
  # gitmcp_docs:
  #   http_url: "https://gitmcp.io/docs/sse"
  #   description: "GitMCP — on-demand docs + code search for any GitHub repo"
  #   timeout: 30s

  # Example: backend with OAuth
  # google:
  #   http_url: "https://mcp.googleapis.com/mcp"
  #   description: "Google services"
  #   oauth:
  #     enabled: true
  #     scopes:
  #       - "https://www.googleapis.com/auth/gmail.readonly"
  #     client_id: "env:GOOGLE_CLIENT_ID"
