mcp-db-analyzer 0.2.11 → 0.2.13

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.
@@ -34,7 +34,7 @@ async function analyzePostgresConnections() {
34
34
  let totalConnections = 0;
35
35
  for (const row of summary.rows) {
36
36
  lines.push(`| ${row.state} | ${row.count} |`);
37
- totalConnections += parseInt(row.count, 10);
37
+ totalConnections += parseInt(row.count, 10) || 0;
38
38
  }
39
39
  lines.push(`| **Total** | **${totalConnections}** |`);
40
40
  lines.push("");
@@ -158,7 +158,7 @@ async function analyzeMysqlConnections() {
158
158
  let total = 0;
159
159
  for (const row of summary.rows) {
160
160
  lines.push(`| ${row.state} | ${row.count} |`);
161
- total += parseInt(row.count, 10);
161
+ total += parseInt(row.count, 10) || 0;
162
162
  }
163
163
  lines.push(`| **Total** | **${total}** |`);
164
164
  lines.push("");
@@ -194,7 +194,14 @@ async function analyzeMysqlConnections() {
194
194
  }
195
195
  lines.push("");
196
196
  }
197
- if (longQueries.rows.length === 0) {
197
+ if (longQueries.rows.length > 0) {
198
+ lines.push("### Recommendations\n");
199
+ lines.push("- Set `max_execution_time` (per-session) or `innodb_lock_wait_timeout` to limit runaway queries");
200
+ lines.push("- Investigate long-running queries with `EXPLAIN` and optimize or add indexes");
201
+ lines.push("- Use `KILL <id>` to terminate a blocking query if needed");
202
+ lines.push("");
203
+ }
204
+ else {
198
205
  lines.push("### No connection issues detected.\n");
199
206
  }
200
207
  return lines.join("\n");
@@ -41,10 +41,23 @@ async function explainQuerySqlite(sql) {
41
41
  if (result.rows.length === 0) {
42
42
  return "Could not parse query plan.";
43
43
  }
44
+ // Build a depth map from the parent chain. SQLite's id field is a node
45
+ // identifier (can be 2, 4, 10...), not a depth — depth must be computed
46
+ // by following parent references.
47
+ const depthMap = new Map();
48
+ for (const row of result.rows) {
49
+ if (row.parent === 0 || row.parent === row.id) {
50
+ depthMap.set(row.id, 0);
51
+ }
52
+ else {
53
+ depthMap.set(row.id, (depthMap.get(row.parent) ?? 0) + 1);
54
+ }
55
+ }
44
56
  const lines = ["## Query Plan Analysis (SQLite)\n"];
45
57
  lines.push("```");
46
58
  for (const row of result.rows) {
47
- const indent = " ".repeat(Math.max(0, row.id));
59
+ const depth = depthMap.get(row.id) ?? 0;
60
+ const indent = " ".repeat(depth);
48
61
  lines.push(`${indent}${row.detail}`);
49
62
  }
50
63
  lines.push("```\n");
package/build/index.js CHANGED
@@ -248,7 +248,7 @@ server.tool("analyze_slow_queries", "Find the slowest queries using pg_stat_stat
248
248
  }
249
249
  });
250
250
  // Tool 7: analyze_connections
251
- server.tool("analyze_connections", "Analyze active database connections. Detects idle-in-transaction sessions (which hold locks and block other queries), long-running queries (flagged at >30 seconds), lock contention between sessions, and connection pool utilization. PostgreSQL and MySQL only.", {
251
+ server.tool("analyze_connections", "Analyze active database connections. Detects idle-in-transaction sessions and lock contention between sessions (PostgreSQL), long-running queries flagged at >30 seconds, and connection pool utilization. Idle-in-transaction and lock contention detection are not available on MySQL — use this tool's output to investigate PostgreSQL-specific blocking scenarios. Not available for SQLite.", {
252
252
  timeout_ms: timeoutParam,
253
253
  }, async ({ timeout_ms }) => {
254
254
  applyTimeout(timeout_ms);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-db-analyzer",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "MCP server for PostgreSQL, MySQL, and SQLite schema analysis, index optimization, and query plan inspection",
5
5
  "mcpName": "io.github.dmitriusan/mcp-db-analyzer",
6
6
  "author": "Dmytro Lisnichenko",