diff --git a/.DS_Store b/.DS_Store index 615e03b..2cccfe8 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/docs/postgresql-setup.md b/docs/postgresql-setup.md index fc1691c..db6e322 100644 --- a/docs/postgresql-setup.md +++ b/docs/postgresql-setup.md @@ -25,6 +25,9 @@ node dist/src/index.js --postgresql --host localhost --database yourdb --user po # With SSL enabled node dist/src/index.js --postgresql --host localhost --database yourdb --user postgres --password yourpassword --ssl true + +# With custom connection timeout (in milliseconds) +node dist/src/index.js --postgresql --host localhost --database yourdb --user postgres --password yourpassword --connection-timeout 60000 ``` ## Command Line Arguments @@ -36,6 +39,7 @@ node dist/src/index.js --postgresql --host localhost --database yourdb --user po - `--password`: The password for the PostgreSQL user. - `--port`: The port the PostgreSQL server is listening on (default: 5432). - `--ssl`: Whether to use SSL for the connection (true/false). +- `--connection-timeout`: The connection timeout in milliseconds (default: 30000). ## Usage from MCP Client diff --git a/readme.md b/readme.md index 6eacbba..2148f14 100644 --- a/readme.md +++ b/readme.md @@ -88,6 +88,7 @@ Optional parameters: - `--password`: Password for PostgreSQL authentication - `--port`: Port number (default: 5432) - `--ssl`: Enable SSL connection (true/false) +- `--connection-timeout`: Connection timeout in milliseconds (default: 30000) ## Configuring Claude Desktop diff --git a/src/.DS_Store b/src/.DS_Store index c60d577..5909162 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/db/postgresql-adapter.ts b/src/db/postgresql-adapter.ts index 1b68297..6e95cf1 100644 --- a/src/db/postgresql-adapter.ts +++ b/src/db/postgresql-adapter.ts @@ -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 { 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`); diff --git a/src/index.ts b/src/index.ts index 5da0fee..6b29b06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,7 +92,8 @@ else if (args.includes('--postgresql') || args.includes('--postgres')) { user: undefined, password: undefined, port: undefined, - ssl: undefined + ssl: undefined, + connectionTimeout: undefined }; // Parse PostgreSQL connection parameters @@ -109,6 +110,8 @@ else if (args.includes('--postgresql') || args.includes('--postgres')) { connectionInfo.port = parseInt(args[i + 1], 10); } else if (args[i] === '--ssl' && i + 1 < args.length) { connectionInfo.ssl = args[i + 1] === 'true'; + } else if (args[i] === '--connection-timeout' && i + 1 < args.length) { + connectionInfo.connectionTimeout = parseInt(args[i + 1], 10); } }