PostgreSQL MCP Server logo

PostgreSQL MCP Server

by assadnasser

A Model Context Protocol (MCP) server that allows users to connect to PostgreSQL databases. This server exposes resources, tools, and prompts for interacting with PostgreSQL databases through the MCP protocol.

View on GitHub

Last updated: N/A

What is PostgreSQL MCP Server?

This MCP server allows external applications to share database credentials via POST requests to an SSE (Server-Sent Events) endpoint. The server then establishes a connection to the specified PostgreSQL database and provides various ways to interact with it, including resources, tools, and prompts.

How to use PostgreSQL MCP Server?

To use the server, you need to clone the repository, install the dependencies, configure the environment variables, and then run the server. You can then use the API endpoints to interact with the PostgreSQL database. The MCP Inspector can be used to test the server.

Key features of PostgreSQL MCP Server

  • Secure PostgreSQL connections with connection pooling and SSL support

  • SQL query execution with parameter binding and query history tracking

  • Schema management with table listing, description, and column metadata

  • Database analytics with database size information and activity monitoring

  • API rate limiting and CORS support for security

  • Natural language templates for database operations

Use cases of PostgreSQL MCP Server

  • Exposing database resources to external applications

  • Providing a natural language interface to PostgreSQL databases

  • Automating database operations and tasks

  • Monitoring database performance and activity

FAQ from PostgreSQL MCP Server

What is MCP?

MCP stands for Model Context Protocol, a protocol for interacting with resources, tools, and prompts.

How do I configure the database connection?

You need to set the environment variables PGHOST, PGUSER, PGDATABASE, PGPASSWORD, and PGPORT in the .env file.

How do I deploy the server to Vercel?

You can use the Vercel CLI to deploy the server to Vercel. First, install the Vercel CLI with npm install -g vercel, then run vercel to deploy.

What storage implementations are used for query history?

The server uses in-memory storage for development and Redis storage for production when REDIS_URL is provided.

How can I test the server?

You can use the MCP Inspector to test the server. Install it with npm install -g @modelcontextprotocol/inspector and start it with mcp-inspector --server-url http://localhost:3000.