From 991f0138d8bf281a9974067341c08574b12e6f2c Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sun, 11 Jan 2026 23:20:41 +0000 Subject: [PATCH] Reinitialize MySQL Tool Handler when MCP variables change When LOAD MCP VARIABLES TO RUNTIME is called and the MCP server is already running, the MySQL Tool Handler is now recreated with the current configuration values. This allows changing MySQL connection parameters without restarting ProxySQL. The reinitialization: 1. Deletes the old MySQL Tool Handler 2. Creates a new one with current mcp-mysql_* values 3. Initializes the new handler 4. Logs success or failure --- lib/Admin_FlushVariables.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Admin_FlushVariables.cpp b/lib/Admin_FlushVariables.cpp index eb57fc634..7bd87b8fc 100644 --- a/lib/Admin_FlushVariables.cpp +++ b/lib/Admin_FlushVariables.cpp @@ -26,6 +26,7 @@ using json = nlohmann::json; #include "proxysql_config.h" #include "proxysql_restapi.h" #include "MCP_Thread.h" +#include "MySQL_Tool_Handler.h" #include "ProxySQL_MCP_Server.hpp" #include "proxysql_utils.h" #include "prometheus_helpers.h" @@ -1391,7 +1392,33 @@ void ProxySQL_Admin::flush_mcp_variables___runtime_to_database(SQLite3DB* db, bo } } } else { - proxy_info("MCP: Server already running\n"); + // Server is already running - check if MySQL configuration changed + // and reinitialize the tool handler if needed + proxy_info("MCP: Server already running, checking MySQL tool handler reinitialization\n"); + if (GloMCPH->mysql_tool_handler) { + // Delete old handler + delete GloMCPH->mysql_tool_handler; + GloMCPH->mysql_tool_handler = NULL; + } + + // Create new tool handler with current configuration + proxy_info("MCP: Reinitializing MySQL Tool Handler with current configuration\n"); + GloMCPH->mysql_tool_handler = new MySQL_Tool_Handler( + GloMCPH->variables.mcp_mysql_hosts ? GloMCPH->variables.mcp_mysql_hosts : "", + GloMCPH->variables.mcp_mysql_ports ? GloMCPH->variables.mcp_mysql_ports : "", + GloMCPH->variables.mcp_mysql_user ? GloMCPH->variables.mcp_mysql_user : "", + GloMCPH->variables.mcp_mysql_password ? GloMCPH->variables.mcp_mysql_password : "", + GloMCPH->variables.mcp_mysql_schema ? GloMCPH->variables.mcp_mysql_schema : "", + GloMCPH->variables.mcp_catalog_path ? GloMCPH->variables.mcp_catalog_path : "" + ); + + if (GloMCPH->mysql_tool_handler->init() != 0) { + proxy_error("MCP: Failed to reinitialize MySQL Tool Handler\n"); + delete GloMCPH->mysql_tool_handler; + GloMCPH->mysql_tool_handler = NULL; + } else { + proxy_info("MCP: MySQL Tool Handler reinitialized successfully\n"); + } } } else { // Stop the server if running