---
title: "Deploy Postgres MCP"
description: "Deploy and Host Postgres MCP with Railway"
category: "Automation"
url: https://railway.com/deploy/postgres-mcp
---

# Deploy Postgres MCP

Deploy and Host Postgres MCP with Railway

**[Deploy Postgres MCP on Railway](https://railway.com/template/postgres-mcp)**

- **Creator:** fournyp's Projects
- **Category:** Automation
- **Total deploys:** 2

## Template content

### Postgres MCP https://api.iconify.design/simple-icons:modelcontextprotocol.svg

- **Source:** https://github.com/FournyP/postgres-mcp-railway-template

### Postgres MCP Gateway https://cdn.simpleicons.org/nginx

- **Source:** https://github.com/FournyP/postgres-mcp-railway-template
- **Public domain:** Yes

## Documentation

![Postgres MCP logo](https://raw.githubusercontent.com/FournyP/postgres-mcp-railway-template/main/icon.svg)

# 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/dbname` connection string for the database the MCP should expose.

## Implementation Details

### Architecture Components

This template deploys two services:

- **Gateway**: `nginx:alpine` with a public Railway domain. Validates `Authorization: Bearer ` against `API_KEYS` and proxies the rest to the MCP over Railway's private network with SSE-friendly settings.
- **Postgres MCP**: the [crystaldba/postgres-mcp](https://github.com/crystaldba/postgres-mcp) server (pinned to `v0.3.0`) running in SSE transport mode. No public domain — reachable only via `mcp.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_URI` on 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, or `unrestricted` for 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

## Similar templates

- [N8N Main + Worker](https://railway.com/deploy/n8n-main-worker) — Deploy and Host N8N with Inactive worker.
- [Evolution API with n8n](https://railway.com/deploy/evolution-api-with-n8n) — [Jul'26] WhatsApp automation platform using Evolution API, n8n & PostgreSQL
- [Postgres Backup](https://railway.com/deploy/postgres-s3-backups) — Cron-based PostgreSQL backup to bucket storage

Open this page in a browser: https://railway.com/deploy/postgres-mcp
