Deploy Postgres MCP
Deploy and Host Postgres MCP with Railway
Postgres MCP
Just deployed
Postgres MCP Gateway
Just deployed
Deploy and Host Postgres MCP on Railway
Postgres MCP is a Model Context Protocol server that exposes a PostgreSQL database to LLM clients as tools — database health checks, query plan analysis, index tuning, and constrained SQL execution. This template deploys the MCP server behind an nginx bearer-token auth gateway, so an LLM can safely talk to your database from a publicly reachable endpoint.
About Hosting Postgres MCP
The upstream project has no built-in client authentication, so this template places an nginx service in front that validates every request against a comma-separated list of bearer tokens before proxying to the MCP over Railway's private network. The MCP can be pointed at any PostgreSQL-compatible database — a Railway Postgres plugin you add to the project, a managed cloud database (Supabase, Neon, RDS), or a self-hosted instance.
Common Use Cases
- Give Claude, Cursor, or other MCP clients read-only access to a production database
- Let an agent profile slow queries and recommend indexes without giving it a raw connection string
- Retrieval-Augmented Generation (RAG) over relational data
- Secure sharing of a database tool endpoint with teammates via a bearer token
Dependencies for Postgres MCP Hosting
The template ships the nginx auth gateway and the Postgres MCP server. You bring the database: add a Railway Postgres plugin to the same project after deploy, or point the MCP at any external PostgreSQL instance via DATABASE_URI.
Deployment Dependencies
- A
postgresql://user:pass@host:port/dbnameconnection string for the database the MCP should expose.
Implementation Details
Architecture Components
This template deploys two services:
- Gateway:
nginx:alpinewith a public Railway domain. ValidatesAuthorization: BeareragainstAPI_KEYSand proxies the rest to the MCP over Railway's private network with SSE-friendly settings. - Postgres MCP: the crystaldba/postgres-mcp server (pinned to
v0.3.0) running in SSE transport mode. No public domain — reachable only viamcp.railway.internal:8000.
Authentication
Clients must send Authorization: Bearer where `` is one of the comma-separated entries in API_KEYS. Generate keys with openssl rand -hex 32; rotating is a variable update + gateway redeploy. Defense-in-depth is provided by ACCESS_MODE=restricted on the MCP, which forces read-only transactions and rejects commit/rollback even if a key leaks.
Service Configuration
- MCP endpoint:
https:///sse. - Database: set
DATABASE_URIon the MCP service. If you add a Railway Postgres plugin to the same project, use${{Postgres.DATABASE_URL}}as a reference variable; otherwise paste an external connection string. - Access mode:
ACCESS_MODE=restricted(default) for read-only with execution-time limits, orunrestrictedfor full read/write — recommended only for dev/throwaway databases.
License Information
MIT (postgres-mcp) + BSD-2-Clause (nginx).
Why Deploy Postgres MCP on Railway?
The auth gateway, private-network wiring, and SSE passthrough are all pre-configured — giving an MCP client secure access to a Postgres database is a one-click deploy instead of a custom nginx + reverse-proxy project.
Notes
- Source repo: https://github.com/FournyP/postgres-mcp-railway-template
- Upstream MCP server: https://github.com/crystaldba/postgres-mcp
- Model Context Protocol: https://modelcontextprotocol.io
Template Content
Postgres MCP
FournyP/postgres-mcp-railway-templateDATABASE_URI
Postgres connection string the MCP will analyse. Wire this to the bundled Postgres plugin's private URL, or paste your own postgresql://user:pass@host:port/db for an external database.
Postgres MCP Gateway
FournyP/postgres-mcp-railway-templateAPI_KEYS
Comma-separated list of bearer tokens allowed to call the MCP.
