mirror of
https://github.com/executeautomation/mcp-database-server.git
synced 2025-12-09 21:12:57 +08:00
Add connection timeout support for PostgreSQL in MCP Database Server
Enhanced the PostgreSQL connection handling by introducing a `--connection-timeout` parameter, allowing users to specify a custom timeout in milliseconds. Updated relevant documentation in README and postgresql-setup.md to reflect this new option. Modified the PostgresqlAdapter to utilize the connection timeout setting during database connections.
This commit is contained in:
@@ -18,6 +18,7 @@ export class PostgresqlAdapter implements DbAdapter {
|
||||
port?: number;
|
||||
ssl?: boolean | object;
|
||||
options?: any;
|
||||
connectionTimeout?: number;
|
||||
}) {
|
||||
this.host = connectionInfo.host;
|
||||
this.database = connectionInfo.database;
|
||||
@@ -29,7 +30,9 @@ export class PostgresqlAdapter implements DbAdapter {
|
||||
port: connectionInfo.port || 5432,
|
||||
user: connectionInfo.user,
|
||||
password: connectionInfo.password,
|
||||
ssl: connectionInfo.ssl
|
||||
ssl: connectionInfo.ssl,
|
||||
// Add connection timeout if provided (in milliseconds)
|
||||
connectionTimeoutMillis: connectionInfo.connectionTimeout || 30000,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,6 +42,15 @@ export class PostgresqlAdapter implements DbAdapter {
|
||||
async init(): Promise<void> {
|
||||
try {
|
||||
console.error(`[INFO] Connecting to PostgreSQL: ${this.host}, Database: ${this.database}`);
|
||||
console.error(`[DEBUG] Connection details:`, {
|
||||
host: this.host,
|
||||
database: this.database,
|
||||
port: this.config.port,
|
||||
user: this.config.user,
|
||||
connectionTimeoutMillis: this.config.connectionTimeoutMillis,
|
||||
ssl: !!this.config.ssl
|
||||
});
|
||||
|
||||
this.client = new pg.Client(this.config);
|
||||
await this.client.connect();
|
||||
console.error(`[INFO] PostgreSQL connection established successfully`);
|
||||
|
||||
Reference in New Issue
Block a user