mcp-postgres
Read-only PostgreSQL MCP server that enables running SELECT queries, listing tables and schemas, and describing columns, with built-in protection against writes and malicious SQL attacks.
README
mcp-postgres
Read-only PostgreSQL MCP server for Claude Desktop (and any MCP-compatible client).
Tools exposed
| Tool | Description |
|---|---|
query |
Run a SELECT query |
list_tables |
List all user tables with row-count estimate and size |
describe_table |
Show columns, types, nullability, PK for a table |
list_schemas |
List user-defined schemas |
Security protections
| Attack | Example | Status |
|---|---|---|
| Direct writes | DROP, DELETE, UPDATE, INSERT, COPY |
✅ Blocked |
| Multiple statements | SELECT 1; DROP TABLE t |
✅ Blocked |
| System functions | pg_read_file, pg_sleep, dblink |
✅ Blocked |
| DoS | pg_sleep(10), GENERATE_SERIES(1,99999999) |
✅ Blocked |
| Dollar-quoted bypass | $$DROP TABLE t$$ |
✅ Blocked |
| Whitespace bypass | tabs and newlines between keywords | ✅ Blocked |
| Comment bypass | /* */ and -- before keywords |
✅ Blocked |
| Session write mode | Enforced via READ ONLY transaction |
✅ Enforced |
| Valid queries | SELECT, SELECT ... LIMIT, COUNT, WHERE |
✅ Allowed |
Environment variables
PostgreSQL connection
| Variable | Required | Default | Description |
|---|---|---|---|
PG_HOST |
✅ | — | Server hostname or IP |
PG_DATABASE |
✅ | — | Database name |
PG_USER |
✅ | — | PostgreSQL username |
PG_PASSWORD |
✅ | — | PostgreSQL password |
PG_PORT |
5432 |
TCP port | |
PG_SSL |
false |
Enable SSL (true/false) |
|
PG_SSL_REJECT_UNAUTHORIZED |
true |
Reject self-signed certs |
SSH tunnel (optional)
Set PG_SSH_HOST to activate the tunnel. Authentication requires either a private key file or a password.
| Variable | Required | Default | Description |
|---|---|---|---|
PG_SSH_HOST |
— | — | SSH server hostname (activates tunnel when set) |
PG_SSH_PORT |
22 |
SSH server port | |
PG_SSH_USER |
✅ (if tunnel) | — | SSH username |
PG_SSH_PRIVATE_KEY |
✅ or password | — | Path to private key file (e.g. ~/.ssh/id_rsa) |
PG_SSH_KEY_PASSPHRASE |
— | Passphrase for the private key (if encrypted) | |
PG_SSH_PASSWORD |
✅ or key | — | SSH password (used when no key file is provided) |
PG_SSH_REMOTE_HOST |
PG_HOST |
Postgres host as seen from the SSH server |
Build
npm install
npm run build
Claude Desktop configuration
Add to %APPDATA%\Claude\claude_desktop_config.json:
Conexão direta:
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword"
}
}
}
}
Conexão direta com SSL (certificado auto-assinado):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "db.example.com",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSL": "true",
"PG_SSL_REJECT_UNAUTHORIZED": "false"
}
}
}
}
Via SSH tunnel (private key):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSH_HOST": "bastion.example.com",
"PG_SSH_USER": "ubuntu",
"PG_SSH_PRIVATE_KEY": "C:/Users/you/.ssh/id_rsa"
}
}
}
}
Via SSH tunnel (password):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSH_HOST": "bastion.example.com",
"PG_SSH_USER": "ubuntu",
"PG_SSH_PASSWORD": "sshpassword"
}
}
}
}
Tip: When
PG_SSH_REMOTE_HOSTis omitted, the tunnel forwards toPG_HOSTas seen from the SSH server. If Postgres runs on a private address only reachable from the bastion (e.g.db.internal), setPG_SSH_REMOTE_HOST=db.internalandPG_HOSTto anything (it will be overridden).
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。