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
6.8K

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

C
Claude Context
Claude Context is an MCP plugin that provides in - depth context of the entire codebase for AI programming assistants through semantic code search. It supports multiple embedding models and vector databases to achieve efficient code retrieval.
TypeScript
5.8K
5 points
A
Acemcp
Acemcp is an MCP server for codebase indexing and semantic search, supporting automatic incremental indexing, multi-encoding file processing, .gitignore integration, and a Web management interface, helping developers quickly search for and understand code context.
Python
9.9K
5 points
B
Blueprint MCP
Blueprint MCP is a chart generation tool based on the Arcade ecosystem. It uses technologies such as Nano Banana Pro to automatically generate visual charts such as architecture diagrams and flowcharts by analyzing codebases and system architectures, helping developers understand complex systems.
Python
8.2K
4 points
M
MCP Agent Mail
MCP Agent Mail is a mail - based coordination layer designed for AI programming agents, providing identity management, message sending and receiving, file reservation, and search functions, supporting asynchronous collaboration and conflict avoidance among multiple agents.
Python
8.4K
5 points
M
MCP
The Microsoft official MCP server provides search and access functions for the latest Microsoft technical documentation for AI assistants
13.1K
5 points
A
Aderyn
Aderyn is an open - source Solidity smart contract static analysis tool written in Rust, which helps developers and security researchers discover vulnerabilities in Solidity code. It supports Foundry and Hardhat projects, can generate reports in multiple formats, and provides a VSCode extension.
Rust
8.7K
5 points
D
Devtools Debugger MCP
The Node.js Debugger MCP server provides complete debugging capabilities based on the Chrome DevTools protocol, including breakpoint setting, stepping execution, variable inspection, and expression evaluation.
TypeScript
10.0K
4 points
S
Scrapling
Scrapling is an adaptive web scraping library that can automatically learn website changes and re - locate elements. It supports multiple scraping methods and AI integration, providing high - performance parsing and a developer - friendly experience.
Python
11.9K
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
17.5K
4.5 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
28.6K
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
17.5K
4.3 points
D
Duckduckgo MCP Server
Certified
The DuckDuckGo Search MCP Server provides web search and content scraping services for LLMs such as Claude.
Python
54.9K
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
51.3K
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#
24.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
17.2K
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
36.7K
4.8 points