mcp-migration-advisor 0.2.4 → 0.2.6

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.
package/README.md CHANGED
@@ -22,6 +22,19 @@ Unlike MigrationPilot (PG-only, raw SQL analysis), this tool **parses Liquibase
22
22
  - **Rollback Validation**: Checks rollback completeness for each changeSet
23
23
  - **Actionable Recommendations**: Every risk includes a specific safe alternative
24
24
 
25
+ ## Pro Tier
26
+
27
+ **Generate exportable diagnostic reports (HTML + PDF)** with a Pro license key.
28
+
29
+ - Full JVM thread dump analysis report with actionable recommendations
30
+ - PDF export for sharing with your team
31
+ - Priority support
32
+
33
+ <!-- TODO: replace placeholder Stripe Payment Link once STRIPE_SECRET_KEY is configured -->
34
+ **$9.99/month** — [Get Pro License](https://buy.stripe.com/PLACEHOLDER)
35
+
36
+ Pro license key activates the `generate_report` MCP tool in mcp-jvm-diagnostics.
37
+
25
38
  ## Installation
26
39
 
27
40
  ```bash
@@ -153,6 +166,13 @@ Returns a conflict report with severity levels, affected tables/columns, and whe
153
166
  - **No execution**: The advisor analyzes but never executes migrations. All recommendations are advisory.
154
167
  - **Database-specific DDL**: Parser targets PostgreSQL/MySQL DDL syntax. Oracle PL/SQL or SQL Server T-SQL may not be fully recognized.
155
168
 
169
+ ## Part of the MCP Java Backend Suite
170
+
171
+ - [mcp-db-analyzer](https://www.npmjs.com/package/mcp-db-analyzer) — PostgreSQL/MySQL/SQLite schema analysis
172
+ - [mcp-spring-boot-actuator](https://www.npmjs.com/package/mcp-spring-boot-actuator) — Spring Boot health, metrics, and bean analysis
173
+ - [mcp-jvm-diagnostics](https://www.npmjs.com/package/mcp-jvm-diagnostics) — Thread dump and GC log analysis
174
+ - [mcp-redis-diagnostics](https://www.npmjs.com/package/mcp-redis-diagnostics) — Redis memory, slowlog, and client diagnostics
175
+
156
176
  ## License
157
177
 
158
178
  MIT
@@ -8,16 +8,6 @@
8
8
  * - Table drops
9
9
  * - CASCADE operations
10
10
  */
11
- // Types that lose precision when converted
12
- const NARROWING_CONVERSIONS = {
13
- "BIGINT": ["INTEGER", "SMALLINT", "TINYINT"],
14
- "INTEGER": ["SMALLINT", "TINYINT"],
15
- "DOUBLE PRECISION": ["REAL", "FLOAT4", "NUMERIC"],
16
- "TEXT": ["VARCHAR", "CHAR"],
17
- "VARCHAR": ["CHAR"],
18
- "TIMESTAMP": ["DATE", "TIME"],
19
- "TIMESTAMPTZ": ["DATE", "TIME", "TIMESTAMP"],
20
- };
21
11
  /**
22
12
  * Analyze a migration for data loss risks.
23
13
  */
@@ -86,7 +76,7 @@ export function analyzeDataLoss(migration) {
86
76
  case "OTHER": {
87
77
  // Detect TRUNCATE
88
78
  if (upper.includes("TRUNCATE")) {
89
- const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(\w+)/i);
79
+ const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(?:\w+\.)?(\w+)/i);
90
80
  issues.push({
91
81
  risk: "CERTAIN",
92
82
  statement: truncate(stmt.raw),
@@ -97,7 +87,7 @@ export function analyzeDataLoss(migration) {
97
87
  }
98
88
  // Detect DELETE without WHERE
99
89
  if (upper.match(/DELETE\s+FROM/) && !upper.includes("WHERE")) {
100
- const tableMatch = stmt.raw.match(/DELETE\s+FROM\s+(?:`|"|)?(\w+)/i);
90
+ const tableMatch = stmt.raw.match(/DELETE\s+FROM\s+(?:`|"|)?(?:\w+\.)?(\w+)/i);
101
91
  issues.push({
102
92
  risk: "CERTAIN",
103
93
  statement: truncate(stmt.raw),
@@ -108,7 +98,7 @@ export function analyzeDataLoss(migration) {
108
98
  }
109
99
  // Detect UPDATE without WHERE
110
100
  if (upper.match(/^UPDATE\b/) && !upper.includes("WHERE")) {
111
- const tableMatch = stmt.raw.match(/UPDATE\s+(?:`|"|)?(\w+)/i);
101
+ const tableMatch = stmt.raw.match(/UPDATE\s+(?:`|"|)?(?:\w+\.)?(\w+)/i);
112
102
  issues.push({
113
103
  risk: "LIKELY",
114
104
  statement: truncate(stmt.raw),
@@ -149,7 +149,7 @@ function analyzeStatement(stmt) {
149
149
  }
150
150
  // TRUNCATE acquires ACCESS EXCLUSIVE lock — same severity as DROP TABLE
151
151
  if (stmt.type === "OTHER" && /\bTRUNCATE\b/i.test(stmt.raw)) {
152
- const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(\w+)/i);
152
+ const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(?:\w+\.)?(\w+)/i);
153
153
  risks.push({
154
154
  severity: "HIGH",
155
155
  statement: truncate(stmt.raw),
package/build/index.js CHANGED
@@ -33,7 +33,7 @@ function formatParserWarnings(migration) {
33
33
  }
34
34
  // Handle --help
35
35
  if (process.argv.includes("--help") || process.argv.includes("-h")) {
36
- console.log(`mcp-migration-advisor v0.2.4 — MCP server for database migration risk analysis
36
+ console.log(`mcp-migration-advisor v0.2.5 — MCP server for database migration risk analysis
37
37
 
38
38
  Usage:
39
39
  mcp-migration-advisor [options]
@@ -52,7 +52,7 @@ Tools provided:
52
52
  }
53
53
  const server = new McpServer({
54
54
  name: "mcp-migration-advisor",
55
- version: "0.2.4",
55
+ version: "0.2.5",
56
56
  });
57
57
  // Tool 1: analyze_migration
58
58
  server.tool("analyze_migration", "Analyze a SQL migration file for lock risks, data loss potential, and unsafe patterns. Supports Flyway (V__*.sql) and plain SQL.", {
@@ -190,7 +190,7 @@ server.tool("analyze_liquibase_yaml", "Analyze a Liquibase YAML changelog for lo
190
190
  return { content: [{ type: "text", text: output }] };
191
191
  });
192
192
  // Tool 4: score_risk
193
- server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL migration. Higher scores indicate more dangerous migrations.", {
193
+ server.tool("score_risk", "Calculate the combined risk score (0-100) for a SQL migration. Aggregates both lock risk severity (ACCESS EXCLUSIVE, SHARE locks) and data loss potential (DROP, TRUNCATE, type changes) into a single score. Useful for CI gates and automated migration review pipelines.", {
194
194
  filename: z.string().describe("Migration filename"),
195
195
  sql: z.string().describe("The SQL content of the migration file"),
196
196
  }, async ({ filename, sql }) => {
@@ -202,35 +202,40 @@ server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL mi
202
202
  const highCount = lockRisks.filter(r => r.severity === "HIGH").length;
203
203
  const dataLossCertain = dataLossIssues.filter(i => i.risk === "CERTAIN").length;
204
204
  const dataLossLikely = dataLossIssues.filter(i => i.risk === "LIKELY").length;
205
+ const dataLossPossible = dataLossIssues.filter(i => i.risk === "POSSIBLE").length;
206
+ // Combine lock risk score with data loss severity for a complete picture
207
+ const dataLossScore = Math.min(100, dataLossCertain * 25 + dataLossLikely * 15 + dataLossPossible * 5);
208
+ const combinedScore = Math.min(100, riskScore + dataLossScore);
205
209
  let verdict;
206
- if (riskScore >= 60 || dataLossCertain > 0) {
210
+ if (combinedScore >= 60 || dataLossCertain > 0) {
207
211
  verdict = "HIGH RISK — requires careful review and testing before deployment";
208
212
  }
209
- else if (riskScore >= 30 || dataLossLikely > 0) {
213
+ else if (combinedScore >= 30 || dataLossLikely > 0) {
210
214
  verdict = "MODERATE RISK — review lock duration and test on staging";
211
215
  }
212
216
  else {
213
217
  verdict = "LOW RISK — standard migration, proceed with normal deployment";
214
218
  }
215
- const output = `## Risk Score: ${riskScore}/100
219
+ const output = `## Risk Score: ${combinedScore}/100
216
220
 
217
221
  **Verdict**: ${verdict}
218
222
 
219
223
  ### Breakdown
220
224
 
221
- | Category | Count |
222
- |----------|-------|
223
- | CRITICAL lock risks | ${criticalCount} |
224
- | HIGH lock risks | ${highCount} |
225
- | Certain data loss | ${dataLossCertain} |
226
- | Likely data loss | ${dataLossLikely} |
227
- | Total statements | ${migration.statements.length} |
225
+ | Category | Count | Score contribution |
226
+ |----------|-------|--------------------|
227
+ | CRITICAL lock risks | ${criticalCount} | ${criticalCount * 30} |
228
+ | HIGH lock risks | ${highCount} | ${highCount * 20} |
229
+ | Certain data loss | ${dataLossCertain} | ${dataLossCertain * 25} |
230
+ | Likely data loss | ${dataLossLikely} | ${dataLossLikely * 15} |
231
+ | Possible data loss | ${dataLossPossible} | ${dataLossPossible * 5} |
232
+ | Total statements | ${migration.statements.length} | — |
228
233
  `;
229
234
  return {
230
235
  content: [{ type: "text", text: output }],
231
236
  };
232
237
  });
233
- // Tool 4: generate_rollback
238
+ // Tool 5: generate_rollback
234
239
  server.tool("generate_rollback", "Generate reverse DDL to undo a SQL migration. Produces rollback SQL with warnings for irreversible operations (DROP TABLE, DROP COLUMN, type changes). Includes Flyway schema_history cleanup.", {
235
240
  filename: z.string().describe("Migration filename (e.g., V2__add_user_email.sql)"),
236
241
  sql: z.string().describe("The SQL content of the migration file"),
@@ -33,6 +33,8 @@ export function parseFlywayFilename(filename) {
33
33
  * Split SQL text into individual statements.
34
34
  * Handles semicolons, ignoring those inside string literals and comments.
35
35
  * Single-quoted strings are tracked; escaped quotes ('') are handled correctly.
36
+ * PostgreSQL dollar-quoted strings ($$ or $tag$) are also tracked so that
37
+ * semicolons inside function/trigger bodies are not treated as statement separators.
36
38
  */
37
39
  function splitStatements(sql) {
38
40
  // Remove block comments
@@ -42,9 +44,40 @@ function splitStatements(sql) {
42
44
  const stmts = [];
43
45
  let current = "";
44
46
  let inString = false;
47
+ let dollarTag = null; // non-null while inside a $tag$...$tag$ block
45
48
  let i = 0;
46
49
  while (i < cleaned.length) {
47
50
  const char = cleaned[i];
51
+ // Dollar-quote handling (PostgreSQL $tag$...$tag$ or $$...$$).
52
+ // Must be checked before the regular single-quote path.
53
+ if (char === "$" && !inString) {
54
+ const rest = cleaned.substring(i);
55
+ if (dollarTag === null) {
56
+ // Try to open a dollar-quoted block
57
+ const openMatch = rest.match(/^\$(\w*)\$/);
58
+ if (openMatch) {
59
+ dollarTag = openMatch[0]; // e.g. "$$" or "$body$"
60
+ current += dollarTag;
61
+ i += dollarTag.length;
62
+ continue;
63
+ }
64
+ }
65
+ else {
66
+ // Try to close the current dollar-quoted block
67
+ if (rest.startsWith(dollarTag)) {
68
+ current += dollarTag;
69
+ i += dollarTag.length;
70
+ dollarTag = null;
71
+ continue;
72
+ }
73
+ }
74
+ }
75
+ // While inside a dollar-quoted block, pass everything through verbatim
76
+ if (dollarTag !== null) {
77
+ current += char;
78
+ i++;
79
+ continue;
80
+ }
48
81
  if (char === "'" && !inString) {
49
82
  inString = true;
50
83
  current += char;
@@ -81,11 +114,13 @@ function splitStatements(sql) {
81
114
  }
82
115
  return stmts;
83
116
  }
84
- // Pattern matchers for DDL statement types
85
- const CREATE_TABLE_RE = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
86
- const ALTER_TABLE_RE = /ALTER\s+TABLE\s+(?:ONLY\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
87
- const DROP_TABLE_RE = /DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
88
- const CREATE_INDEX_RE = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|\s).*?\bON\s+(?:`|"|)?(\w+)(?:`|"|)?/i;
117
+ // Pattern matchers for DDL statement types.
118
+ // Table name patterns use (?:\w+\.)? to optionally consume a schema prefix (e.g. public.users),
119
+ // so that only the unqualified table name is captured in group 1.
120
+ const CREATE_TABLE_RE = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
121
+ const ALTER_TABLE_RE = /ALTER\s+TABLE\s+(?:ONLY\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
122
+ const DROP_TABLE_RE = /DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
123
+ const CREATE_INDEX_RE = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|\s).*?\bON\s+(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
89
124
  const DROP_INDEX_RE = /DROP\s+INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
90
125
  const ADD_COLUMN_RE = /ADD\s+(?:COLUMN\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
91
126
  const DROP_COLUMN_RE = /DROP\s+(?:COLUMN\s+)?(?:IF\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "mcp-migration-advisor",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "MCP server for database migration risk analysis — Flyway and Liquibase XML/YAML/SQL support with lock detection and conflict analysis",
5
- "mcpName": "Migration Advisor",
5
+ "mcpName": "io.github.dmitriusan/mcp-migration-advisor",
6
6
  "main": "build/index.js",
7
7
  "bin": {
8
8
  "mcp-migration-advisor": "build/index.js"