@bytebase/dbhub 1.2.3 → 1.2.5

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.
@@ -1832,7 +1832,7 @@ var ConnectorManager = class {
1832
1832
  if (!lazySource) {
1833
1833
  if (sourceId) {
1834
1834
  throw new Error(
1835
- `Source '${sourceId}' not found. Available sources: ${this.sourceIds.join(", ")}`
1835
+ `Source '${sourceId}' not found. Available sources: ${this.getAvailableSourceIds().join(", ")}`
1836
1836
  );
1837
1837
  } else {
1838
1838
  throw new Error("No sources configured. Call connectWithSources() first.");
@@ -1871,6 +1871,7 @@ var ConnectorManager = class {
1871
1871
  const dsn = await this.buildConnectionDSN(source);
1872
1872
  console.error(` - ${sourceId}: ${redactDSN(dsn)}`);
1873
1873
  let actualDSN = dsn;
1874
+ let tunnel;
1874
1875
  if (source.ssh_host) {
1875
1876
  const sshConfigPath = getDefaultSSHConfigPath();
1876
1877
  let resolvedSSHConfig = null;
@@ -1914,7 +1915,7 @@ var ConnectorManager = class {
1914
1915
  const url = new URL(dsn);
1915
1916
  const targetHost = url.hostname;
1916
1917
  const targetPort = parseInt(url.port) || this.getDefaultPort(dsn);
1917
- const tunnel = new SSHTunnel();
1918
+ tunnel = new SSHTunnel();
1918
1919
  let tunnelInfo;
1919
1920
  try {
1920
1921
  tunnelInfo = await tunnel.establish(sshConfig, {
@@ -1962,7 +1963,19 @@ var ConnectorManager = class {
1962
1963
  if (source.collation) {
1963
1964
  config.collation = source.collation;
1964
1965
  }
1965
- await connector.connect(actualDSN, source.init_script, config);
1966
+ try {
1967
+ await connector.connect(actualDSN, source.init_script, config);
1968
+ } catch (error) {
1969
+ if (tunnel) {
1970
+ this.sshTunnels.delete(sourceId);
1971
+ try {
1972
+ await tunnel.close();
1973
+ } catch (closeError) {
1974
+ console.error(`Error closing SSH tunnel for source '${sourceId}':`, closeError);
1975
+ }
1976
+ }
1977
+ throw error;
1978
+ }
1966
1979
  this.connectors.set(sourceId, connector);
1967
1980
  if (!this.sourceIds.includes(sourceId)) {
1968
1981
  this.sourceIds.push(sourceId);
@@ -2012,7 +2025,7 @@ var ConnectorManager = class {
2012
2025
  if (!connector) {
2013
2026
  if (sourceId) {
2014
2027
  throw new Error(
2015
- `Source '${sourceId}' not found. Available sources: ${this.sourceIds.join(", ")}`
2028
+ `Source '${sourceId}' not found. Available sources: ${this.getAvailableSourceIds().join(", ")}`
2016
2029
  );
2017
2030
  } else {
2018
2031
  throw new Error("No sources connected. Call connectWithSources() first.");
@@ -2049,6 +2062,14 @@ var ConnectorManager = class {
2049
2062
  getSourceIds() {
2050
2063
  return [...this.sourceIds];
2051
2064
  }
2065
+ /**
2066
+ * Source IDs that can actually serve a request: connected, or registered for
2067
+ * lazy (re)connection on first use. Used for error messages so a source that
2068
+ * is neither is not reported as available.
2069
+ */
2070
+ getAvailableSourceIds() {
2071
+ return this.sourceIds.filter((id) => this.connectors.has(id) || this.lazySources.has(id));
2072
+ }
2052
2073
  /** Get all available source IDs */
2053
2074
  static getAvailableSourceIds() {
2054
2075
  if (!managerInstance) {
@@ -2126,7 +2147,7 @@ var ConnectorManager = class {
2126
2147
  error
2127
2148
  );
2128
2149
  } finally {
2129
- if (!this.isDisconnecting && this.sourceConfigs.has(sourceId)) {
2150
+ if (!this.isDisconnecting && this.connectors.has(sourceId)) {
2130
2151
  this.scheduleIamRefresh(source);
2131
2152
  }
2132
2153
  }
@@ -2153,7 +2174,14 @@ var ConnectorManager = class {
2153
2174
  if (this.isDisconnecting) {
2154
2175
  return;
2155
2176
  }
2156
- await this.connectSource(source);
2177
+ try {
2178
+ await this.connectSource(source);
2179
+ } catch (error) {
2180
+ if (!this.isDisconnecting && this.sourceConfigs.has(sourceId)) {
2181
+ this.lazySources.set(sourceId, source);
2182
+ }
2183
+ throw error;
2184
+ }
2157
2185
  }
2158
2186
  /**
2159
2187
  * Build a connection DSN, optionally replacing password with
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  resolveSourceConfigs,
19
19
  resolveTomlConfigPath,
20
20
  resolveTransport
21
- } from "./chunk-F5TPYAVO.js";
21
+ } from "./chunk-VDA5BVNE.js";
22
22
  import {
23
23
  allowedKeywords,
24
24
  getFirstKeyword,
@@ -1913,7 +1913,7 @@ See documentation for more details on configuring database connections.
1913
1913
  const sources = sourceConfigsData.sources;
1914
1914
  console.error(`Configuration source: ${sourceConfigsData.source}`);
1915
1915
  await connectorManager.connectWithSources(sources);
1916
- const { initializeToolRegistry: initializeToolRegistry2 } = await import("./registry-6ABK3M6V.js");
1916
+ const { initializeToolRegistry: initializeToolRegistry2 } = await import("./registry-UF3N2H4G.js");
1917
1917
  initializeToolRegistry2({
1918
1918
  sources: sourceConfigsData.sources,
1919
1919
  tools: sourceConfigsData.tools
@@ -2068,11 +2068,11 @@ See documentation for more details on configuring database connections.
2068
2068
 
2069
2069
  // src/index.ts
2070
2070
  var connectorModules = [
2071
- { load: () => import("./postgres-OVI2PNIJ.js"), name: "PostgreSQL", driver: "pg" },
2071
+ { load: () => import("./postgres-M3W3Y6F5.js"), name: "PostgreSQL", driver: "pg" },
2072
2072
  { load: () => import("./sqlserver-WNVSBFJ3.js"), name: "SQL Server", driver: "mssql" },
2073
2073
  { load: () => import("./sqlite-ASYMU5BI.js"), name: "SQLite", driver: "node:sqlite" },
2074
2074
  { load: () => import("./mysql-GXDUNLJ6.js"), name: "MySQL", driver: "mysql2" },
2075
- { load: () => import("./mariadb-DQ6P57IX.js"), name: "MariaDB", driver: "mariadb" }
2075
+ { load: () => import("./mariadb-EVJ5HLYH.js"), name: "MariaDB", driver: "mariadb" }
2076
2076
  ];
2077
2077
  loadConnectors(connectorModules).then(() => main()).catch((error) => {
2078
2078
  console.error("Fatal error:", error);
@@ -125,6 +125,12 @@ var MariaDBConnector = class _MariaDBConnector {
125
125
  try {
126
126
  const connectionConfig = await this.dsnParser.parse(dsn, config);
127
127
  this.pool = mariadb.createPool(connectionConfig);
128
+ this.pool.on("error", (err) => {
129
+ console.error(
130
+ `MariaDB pool (source "${this.sourceId}"): background connection error, pool will retry:`,
131
+ err.message
132
+ );
133
+ });
128
134
  const rows = await this.pool.query("SELECT VERSION() AS version");
129
135
  this.supportsReadOnlyTransaction = !isTiDBVersion(rows?.[0]?.version);
130
136
  } catch (err) {
@@ -179,6 +179,12 @@ var PostgresConnector = class _PostgresConnector {
179
179
  }
180
180
  }
181
181
  this.pool = new Pool(poolConfig);
182
+ this.pool.on("error", (err) => {
183
+ console.error(
184
+ `PostgreSQL pool (source "${this.sourceId}"): idle connection dropped, will reconnect on next query:`,
185
+ err.message
186
+ );
187
+ });
182
188
  const client = await this.pool.connect();
183
189
  client.release();
184
190
  } catch (err) {
@@ -226,7 +232,7 @@ var PostgresConnector = class _PostgresConnector {
226
232
  SELECT table_name
227
233
  FROM information_schema.tables
228
234
  WHERE table_schema = $1
229
- AND table_type = 'BASE TABLE'
235
+ AND table_type IN ('BASE TABLE', 'FOREIGN')
230
236
  ORDER BY table_name
231
237
  `,
232
238
  [schemaToUse]
@@ -305,7 +311,7 @@ var PostgresConnector = class _PostgresConnector {
305
311
  AND i.oid = ix.indexrelid
306
312
  AND a.attrelid = t.oid
307
313
  AND a.attnum = ANY(ix.indkey)
308
- AND t.relkind = 'r'
314
+ AND t.relkind IN ('r','p')
309
315
  AND t.relname = $1
310
316
  AND ns.oid = t.relnamespace
311
317
  AND ns.nspname = $2
@@ -2,7 +2,7 @@ import {
2
2
  ToolRegistry,
3
3
  getToolRegistry,
4
4
  initializeToolRegistry
5
- } from "./chunk-F5TPYAVO.js";
5
+ } from "./chunk-VDA5BVNE.js";
6
6
  import "./chunk-WVVMH6FJ.js";
7
7
  import "./chunk-MF6LSVWK.js";
8
8
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebase/dbhub",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "mcpName": "io.github.bytebase/dbhub",
5
5
  "description": "Minimal, token-efficient Database MCP Server for PostgreSQL, MySQL, SQL Server, SQLite, MariaDB",
6
6
  "repository": {