@cainli/mcp-server-mysql 2.0.17 → 2.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,7 @@ function validateInfoSchemaQuery(sql, requiredDb) {
36
36
  return { valid: true };
37
37
  }
38
38
  const normalizedSql = sql.replace(/\s+/g, " ").trim().toLowerCase();
39
+ const normalizedRequiredDb = requiredDb.toLowerCase().replace(/`/g, "");
39
40
  const infoSchemaPatterns = [
40
41
  /from\s+information_schema\.tables\b/,
41
42
  /from\s+information_schema\.`tables`\b/,
@@ -46,16 +47,38 @@ function validateInfoSchemaQuery(sql, requiredDb) {
46
47
  if (!targetsInfoSchemaTables) {
47
48
  return { valid: true };
48
49
  }
49
- const hasTableSchemaFilter = normalizedSql.includes("table_schema") &&
50
- (normalizedSql.includes("=") ||
51
- normalizedSql.includes("in") ||
52
- normalizedSql.includes("?"));
53
- if (hasTableSchemaFilter) {
50
+ const whereMatch = normalizedSql.match(/\bwhere\s+(.+?)(?:\bgroup\s+by\b|\border\s+by\b|\blimit\b|$)/i);
51
+ if (!whereMatch) {
52
+ return {
53
+ valid: false,
54
+ reason: `Querying information_schema.tables requires a WHERE clause filtering by table_schema = '${requiredDb}'.`,
55
+ };
56
+ }
57
+ const whereClause = whereMatch[1];
58
+ const simpleEqualityPattern = new RegExp(`table_schema\\s*=\\s*['"\`]${normalizedRequiredDb}['"\`]`, 'i');
59
+ const parameterizedPattern = /table_schema\s*=\s*\?/i;
60
+ const inClausePattern = new RegExp(`table_schema\\s+in\\s*\\(\\s*['"\`]${normalizedRequiredDb}['"\`]\\s*\\)`, 'i');
61
+ const multiValueInPattern = /table_schema\s+in\s*\(\s*[^)]+,[^)]*\)/i;
62
+ const orPattern = /table_schema.*\bor\b.*table_schema/i;
63
+ const notPattern = /table_schema\s+(!=|not\s+in)/i;
64
+ const isValidFilter = simpleEqualityPattern.test(whereClause) ||
65
+ parameterizedPattern.test(whereClause) ||
66
+ inClausePattern.test(whereClause);
67
+ const hasProblematicPattern = multiValueInPattern.test(whereClause) ||
68
+ orPattern.test(whereClause) ||
69
+ notPattern.test(whereClause);
70
+ if (isValidFilter && !hasProblematicPattern) {
54
71
  return { valid: true };
55
72
  }
73
+ if (hasProblematicPattern) {
74
+ return {
75
+ valid: false,
76
+ reason: `Querying information_schema.tables with multiple databases or negative filters is not allowed. Use only 'WHERE table_schema = '${requiredDb}''.`,
77
+ };
78
+ }
56
79
  return {
57
80
  valid: false,
58
- reason: `Querying information_schema.tables requires a database filter. Please add 'WHERE table_schema = '${requiredDb}'' to your query. Required database: ${requiredDb}`,
81
+ reason: `Querying information_schema.tables requires a WHERE clause with 'table_schema = '${requiredDb}''.`,
59
82
  };
60
83
  }
61
84
  export { extractSchemaFromQuery, getQueryTypes, validateInfoSchemaQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cainli/mcp-server-mysql",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "MCP server for interacting with MySQL databases with write operations support",
5
5
  "license": "MIT",
6
6
  "author": "cainli (https://github.com/cainli)",