@bytebase/dbhub 0.11.8 → 0.11.10

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.
@@ -6,14 +6,14 @@ var __filename = fileURLToPath(import.meta.url);
6
6
  var __dirname = path.dirname(__filename);
7
7
  var DEMO_DATA_DIR;
8
8
  var projectRootPath = path.join(__dirname, "..", "..", "..");
9
- var projectResourcesPath = path.join(projectRootPath, "resources", "employee-sqlite");
10
- var distPath = path.join(__dirname, "resources", "employee-sqlite");
9
+ var projectResourcesPath = path.join(projectRootPath, "demo", "employee-sqlite");
10
+ var distPath = path.join(__dirname, "demo", "employee-sqlite");
11
11
  if (fs.existsSync(projectResourcesPath)) {
12
12
  DEMO_DATA_DIR = projectResourcesPath;
13
13
  } else if (fs.existsSync(distPath)) {
14
14
  DEMO_DATA_DIR = distPath;
15
15
  } else {
16
- DEMO_DATA_DIR = path.join(process.cwd(), "resources", "employee-sqlite");
16
+ DEMO_DATA_DIR = path.join(process.cwd(), "demo", "employee-sqlite");
17
17
  if (!fs.existsSync(DEMO_DATA_DIR)) {
18
18
  throw new Error(`Could not find employee-sqlite resources in any of the expected locations:
19
19
  - ${projectResourcesPath}
package/dist/index.js CHANGED
@@ -2626,9 +2626,11 @@ function resolveSSHConfig() {
2626
2626
  };
2627
2627
  }
2628
2628
  async function resolveSourceConfigs() {
2629
- const tomlConfig = loadTomlConfig();
2630
- if (tomlConfig) {
2631
- return tomlConfig;
2629
+ if (!isDemoMode()) {
2630
+ const tomlConfig = loadTomlConfig();
2631
+ if (tomlConfig) {
2632
+ return tomlConfig;
2633
+ }
2632
2634
  }
2633
2635
  const dsnResult = resolveDSN();
2634
2636
  if (dsnResult) {
@@ -2675,7 +2677,7 @@ async function resolveSourceConfigs() {
2675
2677
  source.max_rows = maxRowsResult.maxRows;
2676
2678
  }
2677
2679
  if (dsnResult.isDemo) {
2678
- const { getSqliteInMemorySetupSql } = await import("./demo-loader-EOVFD32T.js");
2680
+ const { getSqliteInMemorySetupSql } = await import("./demo-loader-PSMTLZ2T.js");
2679
2681
  source.init_script = getSqliteInMemorySetupSql();
2680
2682
  }
2681
2683
  return {
@@ -3437,15 +3439,31 @@ async function procedureDetailResourceHandler(uri, variables, _extra) {
3437
3439
 
3438
3440
  // src/resources/index.ts
3439
3441
  function registerResources(server) {
3440
- server.resource("schemas", "db://schemas", schemasResourceHandler);
3442
+ server.resource(
3443
+ "schemas",
3444
+ "db://schemas",
3445
+ {
3446
+ description: "List all schemas/databases available in the connected database",
3447
+ mimeType: "application/json"
3448
+ },
3449
+ schemasResourceHandler
3450
+ );
3441
3451
  server.resource(
3442
3452
  "tables_in_schema",
3443
3453
  new ResourceTemplate("db://schemas/{schemaName}/tables", { list: void 0 }),
3454
+ {
3455
+ description: "List all tables within a specific schema",
3456
+ mimeType: "application/json"
3457
+ },
3444
3458
  tablesResourceHandler
3445
3459
  );
3446
3460
  server.resource(
3447
3461
  "table_structure_in_schema",
3448
3462
  new ResourceTemplate("db://schemas/{schemaName}/tables/{tableName}", { list: void 0 }),
3463
+ {
3464
+ description: "Get detailed structure information for a specific table, including columns, data types, and constraints",
3465
+ mimeType: "application/json"
3466
+ },
3449
3467
  tableStructureResourceHandler
3450
3468
  );
3451
3469
  server.resource(
@@ -3453,11 +3471,19 @@ function registerResources(server) {
3453
3471
  new ResourceTemplate("db://schemas/{schemaName}/tables/{tableName}/indexes", {
3454
3472
  list: void 0
3455
3473
  }),
3474
+ {
3475
+ description: "List all indexes defined on a specific table",
3476
+ mimeType: "application/json"
3477
+ },
3456
3478
  indexesResourceHandler
3457
3479
  );
3458
3480
  server.resource(
3459
3481
  "procedures_in_schema",
3460
3482
  new ResourceTemplate("db://schemas/{schemaName}/procedures", { list: void 0 }),
3483
+ {
3484
+ description: "List all stored procedures/functions in a schema (not supported by SQLite)",
3485
+ mimeType: "application/json"
3486
+ },
3461
3487
  proceduresResourceHandler
3462
3488
  );
3463
3489
  server.resource(
@@ -3465,6 +3491,10 @@ function registerResources(server) {
3465
3491
  new ResourceTemplate("db://schemas/{schemaName}/procedures/{procedureName}", {
3466
3492
  list: void 0
3467
3493
  }),
3494
+ {
3495
+ description: "Get detailed information about a specific stored procedure, including parameters and definition (not supported by SQLite)",
3496
+ mimeType: "application/json"
3497
+ },
3468
3498
  procedureDetailResourceHandler
3469
3499
  );
3470
3500
  }
@@ -4123,10 +4153,10 @@ See documentation for more details on configuring database connections.
4123
4153
  await connectorManager.connectWithSources(sources);
4124
4154
  const transportData = resolveTransport();
4125
4155
  console.error(`MCP transport: ${transportData.type}`);
4126
- console.error(`Transport source: ${transportData.source}`);
4127
- const portData = resolvePort();
4128
- const port = portData.port;
4129
- console.error(`HTTP server port: ${port} (source: ${portData.source})`);
4156
+ const portData = transportData.type === "http" ? resolvePort() : null;
4157
+ if (portData) {
4158
+ console.error(`HTTP server port: ${portData.port} (source: ${portData.source})`);
4159
+ }
4130
4160
  const readonly = isReadOnlyMode();
4131
4161
  const activeModes = [];
4132
4162
  const modeDescriptions = [];
@@ -4146,37 +4176,44 @@ See documentation for more details on configuring database connections.
4146
4176
  console.error(`Running in ${activeModes.join(" and ")} mode - ${modeDescriptions.join(", ")}`);
4147
4177
  }
4148
4178
  console.error(generateBanner(SERVER_VERSION, activeModes));
4149
- const app = express();
4150
- app.use(express.json());
4151
- app.use((req, res, next) => {
4152
- const origin = req.headers.origin;
4153
- if (origin && !origin.startsWith("http://localhost") && !origin.startsWith("https://localhost")) {
4154
- return res.status(403).json({ error: "Forbidden origin" });
4155
- }
4156
- res.header("Access-Control-Allow-Origin", origin || "http://localhost");
4157
- res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
4158
- res.header("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id");
4159
- res.header("Access-Control-Allow-Credentials", "true");
4160
- if (req.method === "OPTIONS") {
4161
- return res.sendStatus(200);
4162
- }
4163
- next();
4164
- });
4165
- const frontendPath = path3.join(__dirname2, "public");
4166
- app.use(express.static(frontendPath));
4167
- app.get("/healthz", (req, res) => {
4168
- res.status(200).send("OK");
4169
- });
4170
- app.get("/api/sources", listSources);
4171
- app.get("/api/sources/:sourceId", getSource);
4172
4179
  if (transportData.type === "http") {
4180
+ const port = portData.port;
4181
+ const app = express();
4182
+ app.use(express.json());
4183
+ app.use((req, res, next) => {
4184
+ const origin = req.headers.origin;
4185
+ if (origin && !origin.startsWith("http://localhost") && !origin.startsWith("https://localhost")) {
4186
+ return res.status(403).json({ error: "Forbidden origin" });
4187
+ }
4188
+ res.header("Access-Control-Allow-Origin", origin || "http://localhost");
4189
+ res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
4190
+ res.header("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id");
4191
+ res.header("Access-Control-Allow-Credentials", "true");
4192
+ if (req.method === "OPTIONS") {
4193
+ return res.sendStatus(200);
4194
+ }
4195
+ next();
4196
+ });
4197
+ const frontendPath = path3.join(__dirname2, "public");
4198
+ app.use(express.static(frontendPath));
4199
+ app.get("/healthz", (req, res) => {
4200
+ res.status(200).send("OK");
4201
+ });
4202
+ app.get("/api/sources", listSources);
4203
+ app.get("/api/sources/:sourceId", getSource);
4204
+ app.get("/mcp", (req, res) => {
4205
+ res.status(405).json({
4206
+ error: "Method Not Allowed",
4207
+ message: "SSE streaming is not supported in stateless mode. Use POST requests with JSON responses."
4208
+ });
4209
+ });
4173
4210
  app.post("/mcp", async (req, res) => {
4174
4211
  try {
4175
4212
  const transport = new StreamableHTTPServerTransport({
4176
4213
  sessionIdGenerator: void 0,
4177
4214
  // Disable session management for stateless mode
4178
- enableJsonResponse: false
4179
- // Use SSE streaming
4215
+ enableJsonResponse: true
4216
+ // Use JSON responses (SSE not supported in stateless mode)
4180
4217
  });
4181
4218
  const server = createServer2();
4182
4219
  await server.connect(transport);
@@ -4188,30 +4225,27 @@ See documentation for more details on configuring database connections.
4188
4225
  }
4189
4226
  }
4190
4227
  });
4191
- }
4192
- app.get("*", (req, res) => {
4193
- res.sendFile(path3.join(frontendPath, "index.html"));
4194
- });
4195
- app.listen(port, "0.0.0.0", () => {
4196
- console.error(`DBHub HTTP server listening at http://0.0.0.0:${port}`);
4197
- if (process.env.NODE_ENV === "development") {
4198
- console.error("");
4199
- console.error("\u{1F680} Development mode detected!");
4200
- console.error(" Frontend dev server (with HMR): http://localhost:5173");
4201
- console.error(" Backend API: http://localhost:8080");
4202
- console.error("");
4203
- } else {
4204
- console.error(`Frontend accessible at http://0.0.0.0:${port}/`);
4228
+ if (process.env.NODE_ENV !== "development") {
4229
+ app.get("*", (req, res) => {
4230
+ res.sendFile(path3.join(frontendPath, "index.html"));
4231
+ });
4205
4232
  }
4206
- if (transportData.type === "http") {
4233
+ app.listen(port, "0.0.0.0", () => {
4234
+ if (process.env.NODE_ENV === "development") {
4235
+ console.error("Development mode detected!");
4236
+ console.error(" Admin console dev server (with HMR): http://localhost:5173");
4237
+ console.error(" Backend API: http://localhost:8080");
4238
+ console.error("");
4239
+ } else {
4240
+ console.error(`Admin console at http://0.0.0.0:${port}/`);
4241
+ }
4207
4242
  console.error(`MCP server endpoint at http://0.0.0.0:${port}/mcp`);
4208
- }
4209
- });
4210
- if (transportData.type === "stdio") {
4243
+ });
4244
+ } else {
4211
4245
  const server = createServer2();
4212
4246
  const transport = new StdioServerTransport();
4213
- console.error("Starting MCP with STDIO transport");
4214
4247
  await server.connect(transport);
4248
+ console.error("MCP server running on stdio");
4215
4249
  process.on("SIGINT", async () => {
4216
4250
  console.error("Shutting down...");
4217
4251
  await transport.close();