postgres-mcp
Enables read-only SQL queries and schema inspection for PostgreSQL databases with up to 3 named connections.
README
postgres-mcp
PostgreSQL MCP server focused on read-only queries and schema inspection, with support for up to 3 named database connections.
Tools
pg_execute_query: validates and executes a single read-only SQL query.pg_list_tables: lists user tables with size and row estimates.pg_describe_table: describes columns, foreign keys, and indexes for a table.
All tools accept an optional database parameter. When omitted, the server uses the default configured database.
Configuration
Copy .env.example to .env and choose one mode.
Legacy single-database mode
POSTGRES_DSN=postgresql://user:password@localhost:5432/app_db
Multi-database mode
Slot 1 is required and becomes the default alias. Slots 2 and 3 are optional.
POSTGRES_DB_1_NAME=main
POSTGRES_DB_1_DSN=postgresql://user:password@localhost:5432/app_db
POSTGRES_DB_2_NAME=analytics
POSTGRES_DB_2_DSN=postgresql://user:password@localhost:5432/analytics_db
POSTGRES_DB_3_NAME=billing
POSTGRES_DB_3_DSN=postgresql://user:password@localhost:5432/billing_db
Optional tuning
POOL_MIN_SIZE=1
POOL_MAX_SIZE=3
POOL_COMMAND_TIMEOUT=30
POOL_CONNECT_TIMEOUT=10
QUERY_STATEMENT_TIMEOUT_MS=10000
QUERY_LOCK_TIMEOUT_MS=1000
QUERY_IDLE_IN_TRANSACTION_TIMEOUT_MS=15000
Installation
python -m pip install -r requirements.txt
python -m pip install -e ".[dev]"
Running
python server.py
Claude Desktop
{
"mcpServers": {
"postgres": {
"command": "python",
"args": ["C:/path/to/axis-postgres-mcp/server.py"],
"env": {
"POSTGRES_DB_1_NAME": "main",
"POSTGRES_DB_1_DSN": "postgresql://user:password@host:5432/app_db",
"POSTGRES_DB_2_NAME": "analytics",
"POSTGRES_DB_2_DSN": "postgresql://user:password@host:5432/analytics_db"
}
}
}
}
Example tool inputs
{
"sql": "SELECT id, email FROM users ORDER BY id DESC",
"limit": 50,
"format": "markdown",
"database": "main"
}
{
"schema_name": "public",
"database": "analytics"
}
Security model
- The server only accepts a single validated read-only SQL statement for
pg_execute_query. - Every tool runs inside a read-only transaction with local statement, lock, and idle-in-transaction timeouts.
- The server sanitizes database errors before returning them to the MCP client.
- Logs never include the full DSN or password.
- You should still connect with a PostgreSQL role that only has
SELECTand metadata access.
Recommended role setup:
CREATE ROLE mcp_reader WITH LOGIN PASSWORD 'secret';
GRANT CONNECT ON DATABASE app_db TO mcp_reader;
GRANT USAGE ON SCHEMA public TO mcp_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_reader;
Testing
Run the unit suite:
python -m pytest
Run integration tests only when you have real database credentials available:
python -m pytest -m integration
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。