A community-driven registry for Claude, Cursor, Windsurf, Cline & more. Not affiliated with Anthropic.
Are you the author? Sign in to claim
postgres-mysql-mcp-server
A Model Context Protocol (MCP) server for querying PostgreSQL and MySQL databases.
Recommended: Use npx to run without installation:
npx postgres-mysql-mcp-server
For MCP client configuration (Cursor, Windsurf, etc.), use:
{
"mcpServers": {
"sql": {
"command": "npx",
"args": ["-y", "postgres-mysql-mcp-server"],
"env": {
"DB_TYPE": "postgresql",
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_DATABASE": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password"
}
}
}
}
Model Context Protocol (MCP) is a standardized protocol that enables AI assistants in code editors like Cursor, Windsurf, and other AI-powered development tools to securely interact with external systems and data sources.
This MCP server bridges the gap between your AI coding assistant and your databases, allowing the AI to:
When integrated with AI editors like Cursor or Windsurf, this MCP server transforms your AI assistant into a database-aware coding companion:
Example Use Cases:
Schema-Aware Code Generation
users table structure, and generates code that matches your exact column names and typesIntelligent Query Writing
Database Debugging
Data-Driven Development
Migration and Refactoring
The AI assistant can now "see" your database structure and data, making it much more helpful and accurate in generating database-related code.
Recommended: Run the server directly with npx without any installation. This is the simplest and most convenient method:
npx postgres-mysql-mcp-server
The -y flag is automatically handled by npx, so it will download and run the latest version without prompts.
If you prefer to install the package:
Global installation:
npm install -g postgres-mysql-mcp-server
Local installation in your project:
npm install postgres-mysql-mcp-server
For local development or contributing:
git clone https://github.com/TranChiHuu/postgres-mysql-mcp-server.git
cd postgres-mysql-mcp-server
npm install
The server runs on stdio and communicates via the MCP protocol.
Recommended: Using npx (no installation required)
npx postgres-mysql-mcp-server
This is the recommended way to run the server. npx will automatically download and run the latest version.
Alternative: Using globally installed package
postgres-mysql-mcp-server
For local development:
npm start
connect_databaseConnect 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:
{
"type": "postgresql",
"host": "localhost",
"port": 5432,
"database": "mydb",
"user": "postgres",
"password": "password"
}
Using environment variables (call without parameters):
{}
Mixing parameters with environment variables:
{
"type": "postgresql",
"host": "custom-host"
}
execute_queryExecute a SQL query on the connected database.
Parameters:
query (string, required): SQL query to executeparams (array, optional): Query parameters for parameterized queriesExample:
{
"query": "SELECT * FROM users WHERE id = $1",
"params": [123]
}
list_tablesList all tables in the connected database.
Parameters: None
describe_tableGet schema information for a specific table.
Parameters:
tableName (string, required): Name of the table to describeExample:
{
"tableName": "users"
}
disconnect_databaseDisconnect from the current database.
Parameters: None
You can configure database connection using environment variables. Create a .env file in the project root or set environment variables:
DB_TYPE=postgresql # or "mysql"
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=mydb
DB_USER=postgres
DB_PASSWORD=password
DB_SSL=false # optional, set to "true" for SSL
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=mydb
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_SSL=false # optional
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DATABASE=mydb
MYSQL_USER=root
MYSQL_PASSWORD=password
MYSQL_SSL=false # optional
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.
This MCP server integrates seamlessly with AI-powered code editors. Add it to your MCP client configuration to enable database-aware AI assistance.
For Cursor:
For Windsurf:
For other MCP-compatible editors:
Add the configuration to your MCP settings file (typically ~/.config/mcp/settings.json or editor-specific location)
This is the recommended configuration. npx automatically downloads and runs the latest version without requiring any installation:
{
"mcpServers": {
"sql": {
"command": "npx",
"args": ["-y", "postgres-mysql-mcp-server"],
"env": {
"DB_TYPE": "postgresql",
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_DATABASE": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password"
}
}
}
}
Benefits of using npx:
-y flag automatically answers "yes" to install promptsIf you've installed the package globally (npm install -g postgres-mysql-mcp-server):
{
"mcpServers": {
"sql": {
"command": "postgres-mysql-mcp-server",
"env": {
"DB_TYPE": "postgresql",
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_DATABASE": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password"
}
}
}
}
If you've installed the package locally in your project (npm install postgres-mysql-mcp-server):
{
"mcpServers": {
"sql": {
"command": "node",
"args": ["./node_modules/postgres-mysql-mcp-server/index.js"],
"env": {
"DB_TYPE": "postgresql",
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_DATABASE": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password"
}
}
}
}
If you're developing locally and have cloned the repository:
{
"mcpServers": {
"sql": {
"command": "npm",
"args": ["start"],
"cwd": "/path-to-source/postgres-mysql-mcp-server",
"env": {
"DB_TYPE": "postgresql",
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_DATABASE": "mydb",
"DB_USER": "postgres",
"DB_PASSWORD": "password"
}
}
}
}
Once configured, you can interact with your database through natural language:
Example Conversation:
You: "What tables are in my database?"
AI: [Uses list_tables tool] "Your database contains: users, orders, products, categories"
You: "Show me the structure of the users table"
AI: [Uses describe_table tool] "The users table has: id (integer), email (varchar), created_at (timestamp)..."
You: "Create an API endpoint to get user by ID"
AI: [Uses describe_table to understand schema, then generates code]
"Here's the endpoint matching your users table structure..."
The AI assistant automatically uses the appropriate MCP tools to query your database and provide accurate, schema-aware responses.
The project uses plain JavaScript (ES modules), so no build step is required. Just edit index.js and run npm start.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
Run Claude Code as an MCP server so any agent can delegate coding tasks to it
Browser automation using accessibility snapshots instead of screenshots
MCP server integration for DaVinci Resolve Studio
A Jetbrains IDE IntelliJ plugin aimed to provide coding agents the ability to leverage intelliJ's indexing of the codeba
via CLI