Postgres Mysql MCP Server
P

Postgres Mysql MCP Server

An MCP server for querying PostgreSQL and MySQL databases, supporting functions such as connecting to databases, executing queries, and viewing table structures through AI editors.
2.5 points
7.7K

What is MCP SQL Server?

MCP SQL Server is a bridge tool that connects AI assistants to databases. It allows AI code editors like Cursor and Windsurf to directly access your PostgreSQL or MySQL databases, view table structures, execute queries, and generate accurate code that perfectly matches your database.

How to use MCP SQL Server?

Just configure it once in your AI editor, and the AI assistant can gain database access capabilities. The AI can automatically query your table structures, generate matching SQL statements, check data issues, and create application code that is fully compatible with your database.

Use cases

Suitable for developers when using AI-assisted programming, especially when generating database-related code, debugging SQL issues, understanding existing database structures, or creating APIs that interact with databases.

Main features

Dual database support
Supports both PostgreSQL and MySQL, two mainstream databases, without the need to switch tools.
Intelligent connection management
Supports environment variable configuration, can automatically connect, and parameters can override environment variables.
Database exploration
List all data tables, view table structures, and understand field types and relationships.
Secure query execution
Supports parameterized queries to prevent SQL injection and ensure query security.
Zero-installation operation
Can be directly run via npx without local installation, always keeping the latest version.
Editor integration
Perfectly integrates with AI editors such as Cursor and Windsurf to improve development efficiency.
Advantages
๐Ÿš€ Improve development efficiency: AI can directly access the database, generate accurate code, and reduce the time for manual table lookup.
๐Ÿ”’ Secure and reliable: Supports SSL connections and parameterized queries to protect database security.
๐Ÿ”„ Flexible configuration: Supports multiple configuration methods (environment variables, direct parameters, mixed use).
๐Ÿ“ฑ Widely compatible: Supports mainstream AI editors (Cursor, Windsurf, etc.).
โšก Performance optimization: Built-in connection pool for fast query response.
๐ŸŽฏ Precise code: Generate code based on the actual database structure to avoid field name errors.
Limitations
๐Ÿ“š Learning cost: Need to understand the MCP protocol and editor configuration.
๐Ÿ”ง Environment dependency: Requires a Node.js 18+ runtime environment.
๐ŸŒ Network requirement: Need to be able to access the database server.
๐Ÿ›ก๏ธ Permission control: AI has database connection permissions, which need to be carefully managed.
๐Ÿ’พ Memory usage: May occupy a certain amount of memory during long-term operation.

How to use

Choose the running method
It is recommended to use npx to run directly without installation. You can also install it globally or locally.
Configure the editor
Add server configuration in the MCP settings of Cursor or Windsurf and set the database connection information.
Set environment variables
Create a .env file or set system environment variables, including database connection information.
Start using
Ask questions or request code in the AI editor, and the AI will automatically use the database tools.

Usage examples

Database structure exploration
When you need to know what tables are in the database or view the structure of a specific table, AI can directly query through the MCP tool.
Intelligent code generation
Generate API code that perfectly matches the database structure to avoid field name errors.
Data query and debugging
Directly query database data to debug problems or obtain information.
Migration and refactoring assistance
Help update relevant code when the database structure changes.

Frequently Asked Questions

Do I need to install Node.js?
Which databases are supported?
How to ensure database security?
Can it be used in a production environment?
Which AI editors are supported?
What if the connection fails?
Can I connect to multiple databases at the same time?
How is the query performance?

Related resources

GitHub repository
Source code, issue feedback, and contribution guidelines.
Model Context Protocol official website
Official documentation and specifications of the MCP protocol.
Cursor editor
An AI code editor that supports MCP.
Windsurf editor
Another AI development environment that supports MCP.
Node.js download
Download the runtime environment (requires version 18+).
PostgreSQL documentation
Official documentation of PostgreSQL.
MySQL documentation
Official documentation of MySQL.

Installation

Copy the following command to your Client for configuration
{
  "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"
      }
    }
  }
}

{
  "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"
      }
    }
  }
}

{
  "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"
      }
    }
  }
}

{
  "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"
      }
    }
  }
}
Note: Your key is sensitive information, do not share it with anyone.

Alternatives

V
Vestige
Vestige is an AI memory engine based on cognitive science. By implementing 29 neuroscience modules such as prediction error gating, FSRS - 6 spaced repetition, and memory dreaming, it provides long - term memory capabilities for AI. It includes a 3D visualization dashboard and 21 MCP tools, runs completely locally, and does not require the cloud.
Rust
4.6K
4.5 points
M
Moltbrain
MoltBrain is a long-term memory layer plugin designed for OpenClaw, MoltBook, and Claude Code, capable of automatically learning and recalling project context, providing intelligent search, observation recording, analysis statistics, and persistent storage functions.
TypeScript
5.2K
4.5 points
B
Bm.md
A feature-rich Markdown typesetting tool that supports multiple style themes and platform adaptation, providing real-time editing preview, image export, and API integration capabilities
TypeScript
4.9K
5 points
S
Security Detections MCP
Security Detections MCP is a server based on the Model Context Protocol that allows LLMs to query a unified security detection rule database covering Sigma, Splunk ESCU, Elastic, and KQL formats. The latest version 3.0 is upgraded to an autonomous detection engineering platform that can automatically extract TTPs from threat intelligence, analyze coverage gaps, generate SIEM-native format detection rules, run tests, and verify. The project includes over 71 tools, 11 pre-built workflow prompts, and a knowledge graph system, supporting multiple SIEM platforms.
TypeScript
6.2K
4 points
P
Paperbanana
Python
6.3K
5 points
B
Better Icons
An MCP server and CLI tool that provides search and retrieval of over 200,000 icons, supports more than 150 icon libraries, and helps AI assistants and developers quickly obtain and use icons.
TypeScript
5.9K
4.5 points
A
Assistant Ui
assistant - ui is an open - source TypeScript/React library for quickly building production - grade AI chat interfaces, providing composable UI components, streaming responses, accessibility, etc., and supporting multiple AI backends and models.
TypeScript
7.6K
5 points
A
Apify MCP Server
The Apify MCP Server is a tool based on the Model Context Protocol (MCP) that allows AI assistants to extract data from websites such as social media, search engines, and e-commerce through thousands of ready-to-use crawlers, scrapers, and automation tools (Apify Actors). It supports OAuth and Skyfire proxy payment and can be integrated into MCP clients such as Claude and VS Code through HTTPS endpoints or local stdio.
TypeScript
6.7K
5 points
G
Gitlab MCP Server
Certified
The GitLab MCP server is a project based on the Model Context Protocol that provides a comprehensive toolset for interacting with GitLab accounts, including code review, merge request management, CI/CD configuration, and other functions.
TypeScript
24.6K
4.3 points
M
Markdownify MCP
Markdownify is a multi-functional file conversion service that supports converting multiple formats such as PDFs, images, audio, and web page content into Markdown format.
TypeScript
35.5K
5 points
N
Notion Api MCP
Certified
A Python-based MCP Server that provides advanced to-do list management and content organization functions through the Notion API, enabling seamless integration between AI models and Notion.
Python
21.4K
4.5 points
D
Duckduckgo MCP Server
Certified
The DuckDuckGo Search MCP Server provides web search and content scraping services for LLMs such as Claude.
Python
73.1K
4.3 points
F
Figma Context MCP
Framelink Figma MCP Server is a server that provides access to Figma design data for AI programming tools (such as Cursor). By simplifying the Figma API response, it helps AI more accurately achieve one - click conversion from design to code.
TypeScript
65.6K
4.5 points
U
Unity
Certified
UnityMCP is a Unity editor plugin that implements the Model Context Protocol (MCP), providing seamless integration between Unity and AI assistants, including real - time state monitoring, remote command execution, and log functions.
C#
32.3K
5 points
G
Gmail MCP Server
A Gmail automatic authentication MCP server designed for Claude Desktop, supporting Gmail management through natural language interaction, including complete functions such as sending emails, label management, and batch operations.
TypeScript
22.1K
4.5 points
M
Minimax MCP Server
The MiniMax Model Context Protocol (MCP) is an official server that supports interaction with powerful text-to-speech, video/image generation APIs, and is suitable for various client tools such as Claude Desktop and Cursor.
Python
49.1K
4.8 points