# MCP Server Schema
# Model Context Protocol server with tools, prompts, resources, and sampling

let workspace_schema = import "./common/workspace.ncl" in
let server_schema = import "./common/server.ncl" in
let security_schema = import "./common/security.ncl" in
let monitoring_schema = import "./common/monitoring.ncl" in
let logging_schema = import "./common/logging.ncl" in

{
  MCPServerConfig = {
    # Workspace configuration
    workspace | workspace_schema.WorkspaceConfig,

    # HTTP server settings
    server | server_schema.ServerConfig,

    # MCP Protocol Configuration
    protocol | {
      # Protocol version
      version | String | default = "1.0",

      # Server role (standard MCP roles)

      # Transport mechanism
      transport | {
        # HTTP/WebSocket/stdio

        # Server endpoint
        endpoint | String | optional,

        # WebSocket path
        ws_path | String | optional,

        # Timeout in milliseconds
        timeout | Number | optional,
      } | optional,
    },

    # Tools Configuration
    tools | {
      # Enable tools
      enabled | Bool | default = true,

      # Max concurrent tool executions
      max_concurrent | Number | default = 5,

      # Tool execution timeout in milliseconds
      timeout | Number | default = 30000,

      # Tool categories
      categories | Array String | optional,

      # Tool validation
      validation | {
        enabled | Bool | default = true,
        strict_mode | Bool | default = false,
      } | optional,

      # Tool caching
      cache | {
        enabled | Bool | default = false,
        ttl | Number | optional,
      } | optional,
    },

    # Prompts Configuration
    prompts | {
      # Enable prompts
      enabled | Bool | default = true,

      # Max custom templates
      max_templates | Number | default = 100,

      # Template engine

      # Prompt caching
      cache | {
        enabled | Bool | default = true,
        ttl | Number | optional,
      } | optional,

      # Prompt versioning
      versioning | {
        enabled | Bool | default = false,
        max_versions | Number | optional,
      } | optional,
    },

    # Resources Configuration
    resources | {
      # Enable resources
      enabled | Bool | default = true,

      # Max resource size in bytes
      max_size | Number | default = 104857600,

      # Supported resource types
      types | Array String | optional,

      # Resource caching
      cache | {
        enabled | Bool | default = true,
        max_size_mb | Number | optional,
        ttl | Number | optional,
      } | optional,

      # Resource validation
      validation | {
        enabled | Bool | default = true,
        max_depth | Number | optional,
      } | optional,
    },

    # Sampling Configuration
    sampling | {
      # Enable sampling
      enabled | Bool | default = false,

      # Max tokens for sampling
      max_tokens | Number | optional,

      # Sampling model
      model | String | optional,

      # Temperature
      temperature | Number | optional,

      # Sampling cache
      cache | {
        enabled | Bool | default = true,
        ttl | Number | optional,
      } | optional,
    },

    # Capabilities Declaration
    capabilities | {
      # Tools capability
      tools | {
        enabled | Bool | default = true,
        list_changed_callback | Bool | default = false,
      } | optional,

      # Prompts capability
      prompts | {
        enabled | Bool | default = true,
        list_changed_callback | Bool | default = false,
      } | optional,

      # Resources capability
      resources | {
        enabled | Bool | default = true,
        list_changed_callback | Bool | default = false,
        subscribe | Bool | default = false,
      } | optional,

      # Sampling capability
      sampling | {
        enabled | Bool | default = false,
      } | optional,
    } | optional,

    # Integration with Orchestrator
    orchestrator_integration | {
      # Enable orchestrator integration
      enabled | Bool | default = false,

      # Orchestrator endpoint
      endpoint | String | optional,

      # Authentication token
      token | String | optional,

      # Workspace to connect to
      workspace | String | optional,
    } | optional,

    # Integration with Control Center
    control_center_integration | {
      # Enable control center integration
      enabled | Bool | default = false,

      # Control center endpoint
      endpoint | String | optional,

      # RBAC enforcement
      enforce_rbac | Bool | default = true,
    } | optional,

    # Security configuration
    security | security_schema.SecurityConfig | optional,

    # Monitoring configuration
    monitoring | monitoring_schema.MonitoringConfig | optional,

    # Logging configuration
    logging | logging_schema.LoggingConfig | optional,

    # Performance tuning
    performance | {
      # Connection pooling
      pool_size | Number | optional,

      # Request buffering
      buffer_size | Number | optional,

      # Enable compression
      compression | Bool | default = false,

      # Compression level
      compression_level | String | optional,
    } | optional,
  },
}
