Skip to content

bug: Pool.js is not passing properly the port #8

Description

@rubenmorim

Bug Description
The MySQL Query MCP Server does not properly read custom database port configurations from environment variables. When a non-standard port (e.g., 3307) is specified via [ENV]_DB_PORT environment variable, the server either fails to parse the port correctly or defaults to port 3306, resulting in connection failures.

Steps To Reproduce
Install mysql-query-mcp-server via npm install -g mysql-query-mcp-server
Configure .env file with custom port:
LOCAL_DB_HOST=localhost
LOCAL_DB_USER=root
LOCAL_DB_PASS=password
LOCAL_DB_NAME=testdb
LOCAL_DB_PORT=3307
Run the MCP server: mysql-query-mcp
Execute query through Cursor IDE: SELECT * FROM users LIMIT 1; on local environment
See connection error indicating wrong port is being used
Expected Behavior
The server should read the LOCAL_DB_PORT=3307 environment variable and connect to MySQL on port 3307. The port parsing logic in dist/db/pools.js line 33 should correctly parse the integer value and use it for the database connection.

Environment
MySQL Query MCP Server version: 1.2.0
Node.js version: 22.20.0
MySQL version: 8.0.x (assumed)
Operating System: macOS 15.6.1 (24G90)
AI Assistant being used: Cursor IDE
Error Log
If applicable, add the error message or log output to help explain your problem.

DEBUG [Pools]: Initializing database pools...
DEBUG [Pools]: === Initializing pool for local environment ===
DEBUG [Pools]: Using prefix: LOCAL
DEBUG [Pools]: PORT: 3307
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)
Additional Context
The issue appears to be in the port parsing logic at dist/db/pools.js:30-33. The code reads the environment variable but may not be properly converting it to an integer or passing it to the mysql2 connection pool configuration. The default port 3306 is being used instead of the configured custom port.

Relevant code section:

const portEnv = process.env[${envPrefix}_DB_PORT];
const config = {
host: process.env[${envPrefix}_DB_HOST],
port: portEnv ? parseInt(portEnv, 10) : 3306,

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions