Skip to content

Commit 35b0b22

Browse files
committed
refactor: Remove mcp-catalog_path variable and hardcode catalog path
Remove the mcp-catalog_path configuration variable and hardcode the catalog database path to datadir/mcp_catalog.db for stability. Rationale: The catalog database is session state, not user configuration. Runtime swapping of the catalog could cause tables to be missed and the catalog to fail even if it was succeeding a second earlier. Changes: - Removed catalog_path from mcp_thread_variables_names array - Removed mcp_catalog_path from MCP_Thread variables struct - Removed getter/setter logic for catalog_path - Hardcoded catalog path to GloVars.datadir/mcp_catalog.db in: - ProxySQL_MCP_Server.cpp (Query_Tool_Handler initialization) - Admin_FlushVariables.cpp (MySQL_Tool_Handler reinitialization) - Updated VARIABLES.md to document the hardcoded path - Updated configure_mcp.sh to remove catalog_path configuration - Updated MCP README to remove catalog_path references
1 parent a816a75 commit 35b0b22

7 files changed

Lines changed: 16 additions & 35 deletions

File tree

doc/MCP/VARIABLES.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,11 @@ The MySQL Tool Handler provides LLM-based tools for MySQL database exploration,
175175

176176
### Catalog Configuration
177177

178-
#### `mcp-catalog_path`
179-
- **Type:** String (file path)
180-
- **Default:** `"mcp_catalog.db"`
181-
- **Description:** Path to the SQLite catalog database (relative to ProxySQL datadir)
182-
- **Runtime:** Yes
183-
- **Example:**
184-
```sql
185-
SET mcp-catalog_path='/path/to/mcp_catalog.db';
186-
LOAD MCP VARIABLES TO RUNTIME;
187-
```
178+
The catalog database path is **hardcoded** to `mcp_catalog.db` in the ProxySQL datadir and cannot be changed at runtime. The catalog stores:
179+
- Database schemas discovered during two-phase discovery
180+
- LLM memories (summaries, domains, metrics)
181+
- Tool usage statistics
182+
- Search history
188183

189184
## Management Commands
190185

include/MCP_Thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MCP_Threads_Handler
5555
char* mcp_mysql_user; ///< MySQL username for tool connections
5656
char* mcp_mysql_password; ///< MySQL password for tool connections
5757
char* mcp_mysql_schema; ///< Default schema/database
58-
char* mcp_catalog_path; ///< Path to catalog SQLite database
58+
// Catalog path is hardcoded to mcp_catalog.db in the datadir
5959
} variables;
6060

6161
/**

lib/Admin_FlushVariables.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,13 +1538,17 @@ void ProxySQL_Admin::flush_mcp_variables___runtime_to_database(SQLite3DB* db, bo
15381538

15391539
// Create new tool handler with current configuration
15401540
proxy_info("MCP: Reinitializing MySQL Tool Handler with current configuration\n");
1541+
1542+
// Hardcode catalog path to datadir/mcp_catalog.db for stability
1543+
std::string catalog_path = std::string(GloVars.datadir) + "/mcp_catalog.db";
1544+
15411545
GloMCPH->mysql_tool_handler = new MySQL_Tool_Handler(
15421546
GloMCPH->variables.mcp_mysql_hosts ? GloMCPH->variables.mcp_mysql_hosts : "",
15431547
GloMCPH->variables.mcp_mysql_ports ? GloMCPH->variables.mcp_mysql_ports : "",
15441548
GloMCPH->variables.mcp_mysql_user ? GloMCPH->variables.mcp_mysql_user : "",
15451549
GloMCPH->variables.mcp_mysql_password ? GloMCPH->variables.mcp_mysql_password : "",
15461550
GloMCPH->variables.mcp_mysql_schema ? GloMCPH->variables.mcp_mysql_schema : "",
1547-
GloMCPH->variables.mcp_catalog_path ? GloMCPH->variables.mcp_catalog_path : ""
1551+
catalog_path.c_str()
15481552
);
15491553

15501554
if (GloMCPH->mysql_tool_handler->init() != 0) {

lib/MCP_Thread.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ static const char* mcp_thread_variables_names[] = {
2929
"mysql_user",
3030
"mysql_password",
3131
"mysql_schema",
32-
"catalog_path",
3332
NULL
3433
};
3534

@@ -54,7 +53,6 @@ MCP_Threads_Handler::MCP_Threads_Handler() {
5453
variables.mcp_mysql_user = strdup("");
5554
variables.mcp_mysql_password = strdup("");
5655
variables.mcp_mysql_schema = strdup("");
57-
variables.mcp_catalog_path = strdup("mcp_catalog.db");
5856

5957
status_variables.total_requests = 0;
6058
status_variables.failed_requests = 0;
@@ -93,8 +91,6 @@ MCP_Threads_Handler::~MCP_Threads_Handler() {
9391
free(variables.mcp_mysql_password);
9492
if (variables.mcp_mysql_schema)
9593
free(variables.mcp_mysql_schema);
96-
if (variables.mcp_catalog_path)
97-
free(variables.mcp_catalog_path);
9894

9995
if (mcp_server) {
10096
delete mcp_server;
@@ -216,10 +212,6 @@ int MCP_Threads_Handler::get_variable(const char* name, char* val) {
216212
sprintf(val, "%s", variables.mcp_mysql_schema ? variables.mcp_mysql_schema : "");
217213
return 0;
218214
}
219-
if (!strcmp(name, "catalog_path")) {
220-
sprintf(val, "%s", variables.mcp_catalog_path ? variables.mcp_catalog_path : "");
221-
return 0;
222-
}
223215

224216
return -1;
225217
}
@@ -316,12 +308,6 @@ int MCP_Threads_Handler::set_variable(const char* name, const char* value) {
316308
variables.mcp_mysql_schema = strdup(value);
317309
return 0;
318310
}
319-
if (!strcmp(name, "catalog_path")) {
320-
if (variables.mcp_catalog_path)
321-
free(variables.mcp_catalog_path);
322-
variables.mcp_catalog_path = strdup(value);
323-
return 0;
324-
}
325311

326312
return -1;
327313
}

lib/ProxySQL_MCP_Server.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ ProxySQL_MCP_Server::ProxySQL_MCP_Server(int p, MCP_Threads_Handler* h)
7676

7777
// 2. Query Tool Handler (uses Discovery_Schema directly for two-phase discovery)
7878
proxy_info("Initializing Query Tool Handler...\n");
79+
80+
// Hardcode catalog path to datadir/mcp_catalog.db for stability
81+
std::string catalog_path = std::string(GloVars.datadir) + "/mcp_catalog.db";
82+
7983
handler->query_tool_handler = new Query_Tool_Handler(
8084
handler->variables.mcp_mysql_hosts ? handler->variables.mcp_mysql_hosts : "",
8185
handler->variables.mcp_mysql_ports ? handler->variables.mcp_mysql_ports : "",
8286
handler->variables.mcp_mysql_user ? handler->variables.mcp_mysql_user : "",
8387
handler->variables.mcp_mysql_password ? handler->variables.mcp_mysql_password : "",
8488
handler->variables.mcp_mysql_schema ? handler->variables.mcp_mysql_schema : "",
85-
handler->variables.mcp_catalog_path ? handler->variables.mcp_catalog_path : "mcp_catalog.db"
89+
catalog_path.c_str()
8690
);
8791
if (handler->query_tool_handler->init() == 0) {
8892
proxy_info("Query Tool Handler initialized successfully\n");

scripts/mcp/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ MCP (Model Context Protocol) is a JSON-RPC 2.0 protocol that allows AI/LLM appli
104104
| `mcp-mysql_hosts` | 127.0.0.1 | MySQL server(s) for tool execution |
105105
| `mcp-mysql_ports` | 3306 | MySQL port(s) |
106106
| `mcp-mysql_user` | (empty) | MySQL username for connections |
107-
| `mcp-mysql_password` | (empty) | MySQL password |
108-
| `mcp-mysql_schema` | (empty) | Default schema for queries |
109-
| `mcp-catalog_path` | mcp_catalog.db | SQLite catalog database path (relative to datadir) |
110-
111-
**Endpoints:**
112107
- `POST https://localhost:6071/config` - Initialize, ping, tools/list
113108
- `POST https://localhost:6071/query` - Execute tools (tools/call)
114109

@@ -545,7 +540,6 @@ MySQL Tool Handler initialized for schema 'testdb'
545540
| `mcp-mysql_user` | (empty) | MySQL username |
546541
| `mcp-mysql_password` | (empty) | MySQL password |
547542
| `mcp-mysql_schema` | (empty) | Default schema |
548-
| `mcp-catalog_path` | mcp_catalog.db | Catalog database path (relative to datadir) |
549543

550544
---
551545

scripts/mcp/configure_mcp.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ configure_mcp() {
113113
exec_admin_silent "SET mcp-mysql_user='${MYSQL_USER}';" || { log_error "Failed to set mcp-mysql_user"; errors=$((errors + 1)); }
114114
exec_admin_silent "SET mcp-mysql_password='${MYSQL_PASSWORD}';" || { log_error "Failed to set mcp-mysql_password"; errors=$((errors + 1)); }
115115
exec_admin_silent "SET mcp-mysql_schema='${MYSQL_DATABASE}';" || { log_error "Failed to set mcp-mysql_schema"; errors=$((errors + 1)); }
116-
exec_admin_silent "SET mcp-catalog_path='mcp_catalog.db';" || { log_error "Failed to set mcp-catalog_path"; errors=$((errors + 1)); }
117116
exec_admin_silent "SET mcp-port='${MCP_PORT}';" || { log_error "Failed to set mcp-port"; errors=$((errors + 1)); }
118117
exec_admin_silent "SET mcp-enabled='${enable}';" || { log_error "Failed to set mcp-enabled"; errors=$((errors + 1)); }
119118

@@ -128,7 +127,6 @@ configure_mcp() {
128127
echo " mcp-mysql_user = ${MYSQL_USER}"
129128
echo " mcp-mysql_password = ${MYSQL_PASSWORD}"
130129
echo " mcp-mysql_schema = ${MYSQL_DATABASE}"
131-
echo " mcp-catalog_path = mcp_catalog.db (relative to datadir)"
132130
echo " mcp-port = ${MCP_PORT}"
133131
echo " mcp-enabled = ${enable}"
134132
}

0 commit comments

Comments
 (0)