CREATE TABLE IF NOT EXISTS `mcp_bots` (
  `id` BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'Bot credential ID',
  `user_id` BIGINT NOT NULL COMMENT 'Owner user ID',
  `bot_id` VARCHAR(64) NOT NULL COMMENT 'External MCP bot id',
  `bot_secret` VARCHAR(255) NOT NULL COMMENT 'External MCP bot secret',
  `status` TINYINT DEFAULT 1 COMMENT 'Status: 0-disabled 1-enabled',
  `last_used_at` DATETIME DEFAULT NULL COMMENT 'Last successful MCP access time',
  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Created at',
  `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated at',
  UNIQUE KEY `uk_mcp_bots_user_id` (`user_id`),
  UNIQUE KEY `uk_mcp_bots_bot_id` (`bot_id`),
  INDEX `idx_mcp_bots_status` (`status`),
  CONSTRAINT `fk_mcp_bots_user_id` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MCP bot credentials';
