MCPcopy Create free account
hub / github.com/bytebase/dbhub / main

Function main

src/server.ts:55–338  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53 * Initialize and start the DBHub server
54 */
55export async function main(): Promise<void> {
56 try {
57 // Resolve source configurations from TOML or fallback to single DSN
58 const sourceConfigsData = await resolveSourceConfigs();
59
60 if (!sourceConfigsData) {
61 const samples = ConnectorRegistry.getAllSampleDSNs();
62 const sampleFormats = Object.entries(samples)
63 .map(([id, dsn]) => ` - ${id}: ${dsn}`)
64 .join("\n");
65
66 console.error(`
67ERROR: Database connection configuration is required.
68Please provide configuration in one of these ways (in order of priority):
69
701. Use demo mode: --demo (uses in-memory SQLite with sample employee database)
712. TOML config file: --config=path/to/dbhub.toml or ./dbhub.toml
723. Command line argument: --dsn="your-connection-string"
734. Environment variable: export DSN="your-connection-string"
745. .env file: DSN=your-connection-string
75
76Example DSN formats:
77${sampleFormats}
78
79Example TOML config (dbhub.toml):
80 [[sources]]
81 id = "my_db"
82 dsn = "postgres://user:pass@localhost:5432/dbname"
83
84See documentation for more details on configuring database connections.
85`);
86 process.exit(1);
87 }
88
89 // Create connector manager and connect to database(s)
90 const connectorManager = new ConnectorManager();
91 const sources = sourceConfigsData.sources;
92
93 console.error(`Configuration source: ${sourceConfigsData.source}`);
94
95 // Connect to database(s) - works uniformly for all modes (demo, single DSN, multi-source TOML)
96 await connectorManager.connectWithSources(sources);
97
98 // Initialize tool registry (manages both built-in and custom tools)
99 // This must happen AFTER ConnectorManager is initialized so source validation works
100 const { initializeToolRegistry } = await import("./tools/registry.js");
101 initializeToolRegistry({
102 sources: sourceConfigsData.sources,
103 tools: sourceConfigsData.tools,
104 });
105 console.error("Tool registry initialized");
106
107 // Start watching TOML config file for hot reload (only when using TOML config).
108 // In STDIO mode, tool list is registered once — hot reload updates connections and
109 // tool registry, but STDIO clients won't see added/removed tools without restart.
110 // HTTP transport creates a new server per request, so tool changes apply immediately.
111 const stopConfigWatcher = startConfigWatcher({
112 connectorManager,

Callers 1

index.tsFile · 0.85

Calls 15

connectWithSourcesMethod · 0.95
resolveSourceConfigsFunction · 0.85
initializeToolRegistryFunction · 0.85
startConfigWatcherFunction · 0.85
resolveTransportFunction · 0.85
resolvePortFunction · 0.85
resolveHostFunction · 0.85
buildAllowedHostsFunction · 0.85
resolveAllowedHostsFunction · 0.85
getSelfHostsFunction · 0.85
isDemoModeFunction · 0.85
generateBannerFunction · 0.85

Tested by

no test coverage detected