PostgreSQL MCP
Template for a remote MCP server with GitHub OAuth - following best practices for building MCP servers so you can take this as a starting point for any MCP server you want to build!
What is PostgreSQL MCP?
PostgreSQL MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to template for a remote mcp server with github oauth - following best practices for building mcp servers so you can take this as a starting point for any mcp server you want to build!
Template for a remote MCP server with GitHub OAuth - following best practices for building MCP servers so you can take this as a starting point for any MCP server you want to build!
This server falls under the Databases and Developer Tools categories on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- Template for a remote MCP server with GitHub OAuth - followi
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx postgresql-mcp-server-with-github-oauthConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use PostgreSQL MCP
This project is a production-ready template for building remote MCP servers with GitHub OAuth authentication, backed by a PostgreSQL database and deployed on Cloudflare Workers. It demonstrates best practices for secure MCP server construction: OAuth 2.0 login flow, encrypted session cookies, role-based database access, and deployment to the Cloudflare edge network. Developers can use it as a starting point for any MCP server that needs authenticated multi-user access, or use it directly to expose a PostgreSQL database to AI clients with read/write access control.
Prerequisites
- Node.js 18+ and npm installed
- A Cloudflare account with Workers enabled (free tier works for development)
- A PostgreSQL database with connection string (local, Supabase, Neon, etc.)
- A GitHub account to create an OAuth App for authentication
- Wrangler CLI (Cloudflare's deployment tool) — installed via npm
Clone the repository and install dependencies
Clone the template repository and install all npm dependencies including the Wrangler CLI.
git clone https://github.com/coleam00/remote-mcp-server-with-auth
cd remote-mcp-server-with-auth
npm install -g wrangler
npm installCreate a GitHub OAuth App
Go to https://github.com/settings/developers and create a new OAuth App. Set the Homepage URL to http://localhost:8792 for development and the Authorization callback URL to http://localhost:8792/callback.
Configure local environment variables
Create a .dev.vars file in the project root with your GitHub OAuth credentials, a generated encryption key, and your PostgreSQL connection string.
# .dev.vars
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
COOKIE_ENCRYPTION_KEY=$(openssl rand -hex 32)
DATABASE_URL=postgresql://username:password@host:5432/database_nameRun locally for development
Start the Cloudflare Worker in local development mode. The MCP server will be available at http://localhost:8792.
wrangler devDeploy to Cloudflare Workers
Create the KV namespace for OAuth state, update wrangler.jsonc with the KV ID, then deploy and set production secrets.
wrangler kv namespace create "OAUTH_KV"
# Update wrangler.jsonc with the returned KV namespace ID
wrangler deploy
wrangler secret put GITHUB_CLIENT_ID
wrangler secret put GITHUB_CLIENT_SECRET
wrangler secret put COOKIE_ENCRYPTION_KEY
wrangler secret put DATABASE_URLConnect your MCP client to the deployed server
Point your MCP client at the deployed Cloudflare Worker URL. Users will be prompted to authenticate with GitHub before accessing the database tools.
{
"mcpServers": {
"postgres-remote": {
"url": "https://your-worker.workers.dev/mcp"
}
}
}PostgreSQL MCP Examples
Client configuration
Connect to the deployed remote MCP server using its Cloudflare Workers URL. Authentication is handled via GitHub OAuth in the browser.
{
"mcpServers": {
"postgres-remote": {
"url": "https://your-worker.workers.dev/mcp"
}
}
}Prompts to try
Once connected and authenticated, use these prompts to interact with your PostgreSQL database through Claude.
- "List all tables in my database and describe their schemas"
- "Run a SELECT query to find all users who signed up in the last 7 days"
- "Show me the column types and constraints for the orders table"
- "Query the products table and return the top 5 items by price"Troubleshooting PostgreSQL MCP
GitHub OAuth callback returns an error or redirects to the wrong URL
Ensure the Authorization callback URL in your GitHub OAuth App settings exactly matches your server URL plus /callback (e.g., http://localhost:8792/callback for dev, https://your-worker.workers.dev/callback for production). Both Homepage URL and Callback URL must be updated when switching between dev and prod.
DATABASE_URL connection fails in production
Cloudflare Workers run at the edge and may need a connection-pooling proxy like PgBouncer or a managed service like Supabase/Neon that supports HTTP-based connections. Direct TCP connections to a local Postgres server will not work from Workers.
Wrangler dev fails with KV namespace errors
The KV namespace for OAuth state must be created before running `wrangler dev`. Run `wrangler kv namespace create OAUTH_KV` and copy the resulting ID into the `kv_namespaces` section of wrangler.jsonc.
Frequently Asked Questions about PostgreSQL MCP
What is PostgreSQL MCP?
PostgreSQL MCP is a Model Context Protocol (MCP) server that template for a remote mcp server with github oauth - following best practices for building mcp servers so you can take this as a starting point for any mcp server you want to build! It connects AI assistants to external tools and data sources through a standardized interface.
How do I install PostgreSQL MCP?
Follow the installation instructions on the PostgreSQL MCP GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with PostgreSQL MCP?
PostgreSQL MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is PostgreSQL MCP free to use?
Yes, PostgreSQL MCP is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.
PostgreSQL MCP Alternatives — Similar Databases Servers
Looking for alternatives to PostgreSQL MCP? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up PostgreSQL MCP in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use PostgreSQL MCP?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.