Enables querying MySQL databases with support for executing SQL queries, listing tables, describing table schemas, and parameterized queries with connection pooling.
Enables querying PostgreSQL databases with support for executing SQL queries, listing tables, describing table schemas, and parameterized queries with connection pooling.
MCP SQL Server
A Model Context Protocol (MCP) server for querying PostgreSQL and MySQL databases.
Features
Connect to PostgreSQL and MySQL databases
Execute SQL queries
List database tables
Describe table schemas
Parameterized query support
Connection pooling for better performance
Installation
Install dependencies:
Usage
Running the Server
The server runs on stdio and communicates via the MCP protocol:
Available Tools
1. connect_database
Connect to a PostgreSQL or MySQL database. Parameters can be provided directly, loaded from environment variables, or a combination of both. If environment variables are set, the server will auto-connect on startup.
Parameters (all optional if using environment variables):
type(string, optional): Database type - "postgresql" or "mysql"host(string, optional): Database hostport(number, optional): Database portdatabase(string, optional): Database nameuser(string, optional): Database userpassword(string, optional): Database passwordssl(boolean, optional): Use SSL connection (default: false)
Examples:
Using parameters:
Using environment variables (call without parameters):
Mixing parameters with environment variables:
2. execute_query
Execute a SQL query on the connected database.
Parameters:
query(string, required): SQL query to executeparams(array, optional): Query parameters for parameterized queries
Example:
3. list_tables
List all tables in the connected database.
Parameters: None
4. describe_table
Get schema information for a specific table.
Parameters:
tableName(string, required): Name of the table to describe
Example:
5. disconnect_database
Disconnect from the current database.
Parameters: None
Configuration
Environment Variables
You can configure database connection using environment variables. Create a .env file in the project root or set environment variables:
Option 1: Generic Environment Variables (works for both PostgreSQL and MySQL)
Option 2: PostgreSQL-Specific Environment Variables
Option 3: MySQL-Specific Environment Variables
Note: If environment variables are set, the server will automatically connect on startup. You can also call connect_database without parameters to use environment variables, or provide partial parameters that will be merged with environment variables.
MCP Client Configuration
Add this to your MCP client configuration (e.g., in Cursor or other MCP-compatible tools):
Important: Always include "cwd" when using the node command directly, so Node can find the node_modules directory.
Or if using npm script:
Development
The project uses plain JavaScript (ES modules), so no build step is required. Just edit index.js and run npm start.
Security Notes
Never commit database credentials to version control
Use environment variables or secure credential management
The server supports SSL connections for secure database access
Always validate and sanitize SQL queries in production environments
Requirements
Node.js 18+
PostgreSQL or MySQL database access
License
MIT