@yawlabs/postgres-mcp 0.5.0 → 0.5.2
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/dist/index.js +20 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35368,6 +35368,14 @@ async function runUserQueryBounded(client, sql, params, maxRows) {
|
|
|
35368
35368
|
});
|
|
35369
35369
|
}
|
|
35370
35370
|
}
|
|
35371
|
+
async function safeResolveTypeNames(client, fields) {
|
|
35372
|
+
try {
|
|
35373
|
+
return await resolveTypeNames(client, [...new Set(fields.map((f) => f.dataTypeID))]);
|
|
35374
|
+
} catch (err) {
|
|
35375
|
+
console.error(`[postgres-mcp] type-name resolution failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
35376
|
+
return {};
|
|
35377
|
+
}
|
|
35378
|
+
}
|
|
35371
35379
|
function toQueryResult(result, maxRows, typeNames = {}) {
|
|
35372
35380
|
const truncated = result.rows.length > maxRows;
|
|
35373
35381
|
const rows = truncated ? result.rows.slice(0, maxRows) : result.rows;
|
|
@@ -35390,7 +35398,7 @@ async function runReadOnly(sql, params = [], hooks = {}) {
|
|
|
35390
35398
|
if (hooks.setup) await hooks.setup(client);
|
|
35391
35399
|
const result = await runUserQueryBounded(client, sql, params, maxRows);
|
|
35392
35400
|
await client.query("ROLLBACK");
|
|
35393
|
-
const typeNames = await
|
|
35401
|
+
const typeNames = await safeResolveTypeNames(client, result.fields);
|
|
35394
35402
|
return { ok: true, data: toQueryResult(result, maxRows, typeNames) };
|
|
35395
35403
|
} catch (err) {
|
|
35396
35404
|
try {
|
|
@@ -35421,7 +35429,7 @@ async function runReadWrite(sql, params = []) {
|
|
|
35421
35429
|
await client.query("BEGIN");
|
|
35422
35430
|
const result = await runUserQueryBounded(client, sql, params, maxRows);
|
|
35423
35431
|
await client.query("COMMIT");
|
|
35424
|
-
const typeNames = await
|
|
35432
|
+
const typeNames = await safeResolveTypeNames(client, result.fields);
|
|
35425
35433
|
return { ok: true, data: toQueryResult(result, maxRows, typeNames) };
|
|
35426
35434
|
} catch (err) {
|
|
35427
35435
|
try {
|
|
@@ -35447,7 +35455,7 @@ async function runReadWriteRollback(sql, params = [], hooks = {}) {
|
|
|
35447
35455
|
if (hooks.setup) await hooks.setup(client);
|
|
35448
35456
|
const result = await runUserQueryBounded(client, sql, params, maxRows);
|
|
35449
35457
|
await client.query("ROLLBACK");
|
|
35450
|
-
const typeNames = await
|
|
35458
|
+
const typeNames = await safeResolveTypeNames(client, result.fields);
|
|
35451
35459
|
return { ok: true, data: toQueryResult(result, maxRows, typeNames) };
|
|
35452
35460
|
} catch (err) {
|
|
35453
35461
|
try {
|
|
@@ -35742,16 +35750,19 @@ var adminTools = [
|
|
|
35742
35750
|
run(
|
|
35743
35751
|
// pg_sequences was added in PG10. last_value can be NULL on a never-
|
|
35744
35752
|
// touched sequence; we filter those out (nothing to report yet).
|
|
35753
|
+
// Divide in `numeric`, not `float8`: BIGINT sequences past 2^53 lose
|
|
35754
|
+
// precision in float8, and the danger zone (>= threshold) is exactly
|
|
35755
|
+
// where the reported pct_used must stay accurate.
|
|
35745
35756
|
`SELECT
|
|
35746
35757
|
schemaname AS schema,
|
|
35747
35758
|
sequencename AS sequence,
|
|
35748
35759
|
last_value::text AS last_value,
|
|
35749
35760
|
max_value::text AS max_value,
|
|
35750
|
-
(last_value::
|
|
35761
|
+
(last_value::numeric / NULLIF(max_value::numeric, 0))::numeric(6, 4)::float8 AS pct_used
|
|
35751
35762
|
FROM pg_catalog.pg_sequences
|
|
35752
35763
|
WHERE last_value IS NOT NULL
|
|
35753
35764
|
AND max_value > 0
|
|
35754
|
-
AND (last_value::
|
|
35765
|
+
AND (last_value::numeric / max_value::numeric) >= $1
|
|
35755
35766
|
ORDER BY pct_used DESC NULLS LAST
|
|
35756
35767
|
LIMIT $2`,
|
|
35757
35768
|
[seqExhaustionThreshold, limit]
|
|
@@ -35890,7 +35901,8 @@ function buildHypopgHooks(indexes) {
|
|
|
35890
35901
|
for (const idx of indexes) {
|
|
35891
35902
|
const cols = idx.columns.map(quoteIdent).join(", ");
|
|
35892
35903
|
const tbl = quoteQualifiedTable(idx.table);
|
|
35893
|
-
const
|
|
35904
|
+
const using = idx.using ?? "btree";
|
|
35905
|
+
const createSql = `CREATE INDEX ON ${tbl} USING ${using} (${cols})`;
|
|
35894
35906
|
const r = await client.query(
|
|
35895
35907
|
"SELECT (hypopg_create_index($1)).indexname AS indexname",
|
|
35896
35908
|
[createSql]
|
|
@@ -36333,6 +36345,7 @@ var schemaTools = [
|
|
|
36333
36345
|
}
|
|
36334
36346
|
const kind = kindRes.ok ? kindRes.data?.[0]?.kind ?? "table" : "table";
|
|
36335
36347
|
const warnings = [];
|
|
36348
|
+
if (!kindRes.ok) warnings.push(`kind fetch failed, reported as "table": ${kindRes.error}`);
|
|
36336
36349
|
if (!pk.ok) warnings.push(`primary_key fetch failed: ${pk.error}`);
|
|
36337
36350
|
if (!fks.ok) warnings.push(`foreign_keys fetch failed: ${fks.error}`);
|
|
36338
36351
|
if (!idxs.ok) warnings.push(`indexes fetch failed: ${idxs.error}`);
|
|
@@ -36662,7 +36675,7 @@ function compareVersions(a, b) {
|
|
|
36662
36675
|
}
|
|
36663
36676
|
|
|
36664
36677
|
// src/index.ts
|
|
36665
|
-
var version2 = true ? "0.5.
|
|
36678
|
+
var version2 = true ? "0.5.2" : (await null).createRequire(import.meta.url)("../package.json").version;
|
|
36666
36679
|
var subcommand = process.argv[2];
|
|
36667
36680
|
if (subcommand === "version" || subcommand === "--version") {
|
|
36668
36681
|
console.log(version2);
|
package/package.json
CHANGED