PostgreSQL MCP Server logo

PostgreSQL MCP Server

by leixiaotian1

The PostgreSQL MCP Server provides tools for interacting with a PostgreSQL database through the Model Context Protocol (MCP). It enables AI assistants to execute SQL queries, create tables, and list database tables.

View on GitHub

Last updated: N/A

What is PostgreSQL MCP Server?

A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database, enabling AI assistants to execute SQL queries and manage database schemas.

How to use PostgreSQL MCP Server?

  1. Clone the repository. 2. Install dependencies using go mod download. 3. Build the server using go build -o sql-mcp-server. 4. Configure database connection details in a .env file. 5. Run the server using ./sql-mcp-server. 6. Configure your AI assistant with the provided MCP configuration.

Key features of PostgreSQL MCP Server

  • Execute SELECT queries

  • Execute INSERT, UPDATE, or DELETE queries

  • Create new tables

  • List user tables

  • Explain queries

Use cases of PostgreSQL MCP Server

  • Enabling AI assistants to query and manipulate PostgreSQL databases

  • Automating database tasks through AI

  • Integrating PostgreSQL with AI-powered applications

  • Providing a secure and controlled interface for AI to interact with databases

FAQ from PostgreSQL MCP Server

What is the purpose of the DB_SSLMODE environment variable?

It configures the SSL mode for the database connection. Setting it to require or higher enables SSL encryption for secure communication.

How do I prevent SQL injection vulnerabilities?

The server validates query types and sanitizes schema names. It's also recommended to use a dedicated database user with limited permissions.

What are the dependencies of this server?

The server depends on github.com/joho/godotenv for loading environment variables, github.com/lib/pq for the PostgreSQL driver, and github.com/mark3labs/mcp-go for the MCP SDK.

Can I contribute to this project?

Contribution guidelines are not specified in the README. Please contact the author for more information.

Is there a license for this project?

The license information is not specified in the README. Please contact the author for more information.