home / mcp / postgres mcp server
Provides safe, read-controlled access to PostgreSQL with NL queries, schema introspection, and guarded write operations.
Configuration
View docs{
"mcpServers": {
"arktechnwa-postgres-mcp": {
"command": "node",
"args": [
"/path/to/postgres-mcp/dist/index.js"
],
"env": {
"PGHOST": "localhost",
"PGUSER": "readonly_user",
"PGDATABASE": "myapp",
"PGPASSWORD": "secret",
"ANTHROPIC_API_KEY": "sk-..."
}
}
}
}You run a PostgreSQL MCP server that safely exposes your database for natural-language queries and controlled SQL execution. It provides schema visibility, guarded read/write access, and reliability features so your AI assistant can help you explore and modify data without risking your data.
You interact with the PostgreSQL MCP server through an MCP client. Start with a config that restricts access to read-only by default, then grant write or admin permissions only when you truly need them. Use the natural language interface to ask questions in plain English and receive generated SQL along with results. When you want to execute changes, use the write-enabled or admin modes that you explicitly enable.
Prerequisites: Node.js 18+ and PostgreSQL 12+. You may optionally provide an Anthropic API key for AI-powered NL→SQL features.
npm install -g @arktechnwa/postgres-mcpSet up MCP servers to run locally or remotely. You can configure a local stdio server that runs a Node-based MCP, or a CLI-style server that executes the postgres-mcp binary. Use environment variables to pass your database credentials and any API keys.
Example local stdio server setup (two approaches shown in code snippets): one using Node to run the MCP index, and one using the postgres-mcp CLI executable.
Security: use a read-only database user by default. Blacklist sensitive schemas and columns. Enforce a statement timeout and row limits to prevent runaway queries. Do not log credentials or reveal connection strings.
If you encounter timeouts or degraded health, check circuit-breaker status and ensure your pool size is appropriate for your workload. Review the row limits and filtering rules to avoid unintended large queries.
The server supports read operations by default and writes only when explicitly permitted. It introspects the schema without exposing data, and it includes mechanisms to prevent long-running or dangerous queries.
Execute a SELECT query and return results with metadata such as row_count and execution_time.
Execute INSERT/UPDATE/DELETE statements with optional RETURNING and track affected_rows.
Ask a question in natural language and translate it to SQL, returning generated SQL and results. Supports fallback mode when API key is not provided.
List tables with metadata such as schema, name, type, row_estimate, and description.
Get column information for a specific table, including data types and constraints.
Get index information for tables.
Get constraint information (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK) for a table.
Return complete schema for a table, including columns, indexes, and constraints.
Return sample rows from a table with optional limit and order.
Get query execution plan with optional analysis and format.
Get database or table statistics, with optional index usage.
List active connections with optional query details.
Show current locks with an option to show only blocked locks.
AI-powered analysis of a given query with optional use of AI for synthesis.
AI-assisted suggestions to improve schema design for a given table.