pgmcp  by subnetmarco

Natural language interface for PostgreSQL

Created 1 month ago
496 stars

Top 62.4% on SourcePulse

GitHubView on GitHub
Project Summary

PGMCP (PostgreSQL Model Context Protocol Server) bridges the gap between AI assistants and PostgreSQL databases by enabling natural language querying. It allows users to interact with any PostgreSQL database using plain English, translating questions into SQL queries and returning structured results. This facilitates data access for tools like Cursor, Claude Desktop, and VS Code extensions, simplifying complex database interactions for developers and data analysts.

How It Works

PGMCP operates as a server that connects to a PostgreSQL database. It accepts natural language prompts from various MCP-compatible clients. An integrated AI engine, typically leveraging OpenAI's API, interprets these prompts and generates corresponding SQL queries. The server then executes these read-only queries against the database, managing results through automatic streaming, pagination, and robust error handling for AI-generated SQL. This approach ensures safe, efficient, and intuitive database interaction without requiring schema modifications.

Quick Start & Requirements

  • Primary install/run command: Build server and client binaries using go build -o pgmcp-server ./server and go build -o pgmcp-client ./client.
  • Prerequisites: Go 1.23+, a PostgreSQL database, and an OpenAI API key (optional, but recommended for SQL generation).
  • Environment Variables: DATABASE_URL is required for the database connection string. OPENAI_API_KEY and OPENAI_MODEL are optional for AI integration.
  • Setup: Requires a Go development environment and a running PostgreSQL instance. Configuration involves setting environment variables.
  • Links: Examples for Cursor and Claude Desktop integration are provided within the README.

Highlighted Details

  • Works with ANY PostgreSQL database without requiring schema modifications.
  • Ensures safe, read-only access, preventing unintended data modifications.
  • Features automatic streaming for large result sets and intelligent query understanding.
  • Supports PostgreSQL case sensitivity and provides robust AI error handling with suggestions.
  • Includes free-text search across all text columns and supports multiple output formats (table, JSON, CSV).

Maintenance & Community

The provided README does not contain specific details regarding project maintainers, community channels (e.g., Discord, Slack), or a public roadmap.

Licensing & Compatibility

  • License: Apache 2.0.
  • Compatibility: The Apache 2.0 license is permissive, allowing for commercial use and integration with closed-source applications.

Limitations & Caveats

The accuracy of SQL generation is dependent on the underlying AI model, which may occasionally produce incorrect queries requiring user intervention or rephrasing. While an OpenAI API key is optional, its absence or the use of alternative LLMs might impact the quality and reliability of the natural language to SQL translation.

Health Check
Last Commit

1 month ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
26 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems") and Gabriel Almeida Gabriel Almeida(Cofounder of Langflow).

sqlchat by sqlchat

0.3%
5k
Chat-based SQL client using natural language
Created 2 years ago
Updated 3 months ago
Feedback? Help us improve.