-- Migration: Add MCP Server Configuration Management
-- Date: 2026-02-06
-- Description: Adds mcp_server_configs table for runtime MCP server management

BEGIN;

CREATE TABLE IF NOT EXISTS mcp_server_configs (
  id              uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
  tenant_id       uuid,
  server_id       varchar(100) NOT NULL,
  name            varchar(255) NOT NULL,
  description     text,
  transport       varchar(20) NOT NULL CHECK (transport IN ('stdio', 'sse')),
  command         varchar(500),
  args            jsonb,
  env             jsonb,
  url             varchar(500),
  tools_concurrency_safe boolean DEFAULT true,
  connect_timeout_ms     integer DEFAULT 10000,
  tool_timeout_ms        integer DEFAULT 30000,
  enabled         boolean DEFAULT true,
  created_at      timestamptz DEFAULT now(),
  updated_at      timestamptz DEFAULT now(),
  created_by      uuid,
  updated_by      uuid,
  CONSTRAINT uq_mcp_server_tenant_server_id UNIQUE (tenant_id, server_id)
);

CREATE INDEX idx_mcp_server_configs_tenant ON mcp_server_configs(tenant_id);
CREATE INDEX idx_mcp_server_configs_enabled ON mcp_server_configs(tenant_id, enabled);

COMMIT;
