Get the FREE Ultimate OpenClaw Setup Guide →

postgres-mysql

MCP server from TranChiHuu/postgres-mysql-mcp-server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio tranchihuu-postgres-mysql-mcp-server npx -y postgres-mysql-mcp-server \
  --env DB_HOST="localhost" \
  --env DB_PORT="5432" \
  --env DB_TYPE="postgresql" \
  --env DB_USER="postgres" \
  --env DB_DATABASE="mydb" \
  --env DB_PASSWORD="password"

How to use

This MCP server provides a database-aware bridge between your AI coding assistants and your PostgreSQL or MySQL databases. It exposes tools to connect to a database, run SQL queries, and inspect schema details so your editor plugins (like Cursor or Windsurf) can generate accurate code and queries based on your actual schema. After starting the server (for example via npx as shown above), you can configure your MCP client with the provided sql server definition and environment variables to auto-connect to your database on startup. The server supports executing parameterized queries, listing tables, describing table schemas, and disconnecting from the database, all through MCP calls from your editor.

How to install

Prerequisites:

  • Node.js and npm or npx available on your machine
  • Access to run npm install or npx to fetch packages

Option 1: Use with npx (no installation required)

  • Run the server directly: npx postgres-mysql-mcp-server

Option 2: Install via npm (global or local)

  • Global installation: npm install -g postgres-mysql-mcp-server
  • Local installation in your project: npm install postgres-mysql-mcp-server

Option 3: Development installation (for contributors)

Additional notes

Tips and notes:

  • You can configure automatic connection by setting environment variables (DB_TYPE, DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD). If those are present, the server will auto-connect on startup.
  • The MCP client configuration example uses the npx command; you can adapt the same approach with custom host/port or different DB credentials.
  • Ensure your database accepts connections from the host running the MCP server and that the user has appropriate privileges for the requested operations.
  • For production deployments, consider using a proper database connection pool and secure handling of credentials (e.g., managed secrets, environment variable protections).
  • The server supports both PostgreSQL and MySQL connections; use DB_TYPE to switch between them as needed.

Related MCP Servers

Sponsor this space

Reach thousands of developers