@cainli/mcp-server-mysql 2.0.8 → 2.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -72,6 +72,10 @@ export const configSchema = z.object({
72
72
  debug: z.boolean().default(false).describe("Enable debug logging"),
73
73
  });
74
74
  export default function createMcpServer({ sessionId, config, }) {
75
+ const isDebugEnabled = config?.debug ?? false;
76
+ if (isDebugEnabled) {
77
+ log("info", "Debug mode enabled");
78
+ }
75
79
  const server = new Server({
76
80
  name: "MySQL MCP Server",
77
81
  version: process.env.npm_package_version || "1.0.0",
@@ -123,12 +127,17 @@ export default function createMcpServer({ sessionId, config, }) {
123
127
  information_schema.tables
124
128
  WHERE
125
129
  table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
126
- ${!isMultiDbMode && mcpConfig.mysql.database ? `AND table_schema = '${mcpConfig.mysql.database}'` : ''}
127
130
  ORDER BY
128
131
  table_schema, table_name
129
132
  `;
130
- const queryResult = (await executeReadOnlyQuery(tablesQuery));
131
- const tables = JSON.parse(queryResult.content[0].text);
133
+ let queryParams = [];
134
+ let finalQuery = tablesQuery;
135
+ if (!isMultiDbMode && mcpConfig.mysql.database) {
136
+ finalQuery = tablesQuery.replace('ORDER BY', `AND table_schema = ?\n ORDER BY`);
137
+ queryParams.push(mcpConfig.mysql.database);
138
+ }
139
+ const rawResult = await executeQuery(finalQuery, queryParams);
140
+ const tables = rawResult[0];
132
141
  log("info", `Found ${tables.length} tables`);
133
142
  const resources = tables.map((table) => ({
134
143
  uri: `mysql://tables/${table.name}`,
@@ -164,11 +173,18 @@ export default function createMcpServer({ sessionId, config, }) {
164
173
  let columnsQuery = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = ?";
165
174
  let queryParams = [tableName];
166
175
  const schemaName = dbName || (!isMultiDbMode ? mcpConfig.mysql.database : null);
176
+ if (!/^[a-zA-Z0-9_]+$/.test(tableName)) {
177
+ throw new Error(`Invalid table name: ${tableName}`);
178
+ }
179
+ if (schemaName && !/^[a-zA-Z0-9_]+$/.test(schemaName)) {
180
+ throw new Error(`Invalid schema name: ${schemaName}`);
181
+ }
167
182
  if (schemaName) {
168
183
  columnsQuery += " AND table_schema = ?";
169
184
  queryParams.push(schemaName);
170
185
  }
171
- const results = (await executeQuery(columnsQuery, queryParams));
186
+ const rawResult = await executeQuery(columnsQuery, queryParams);
187
+ const results = rawResult[0];
172
188
  return {
173
189
  contents: [
174
190
  {
@@ -306,7 +322,7 @@ if (isMainModule()) {
306
322
  log("info", "Running in standalone mode");
307
323
  (async () => {
308
324
  try {
309
- const mcpServer = createMcpServer({ config: { debug: false } });
325
+ const mcpServer = createMcpServer({});
310
326
  if (IS_REMOTE_MCP && REMOTE_SECRET_KEY?.length) {
311
327
  const app = express();
312
328
  app.use(express.json());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cainli/mcp-server-mysql",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
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)",