PostgreSQL
Access and analyze Postgres databases with read-only queries.
This MCP server provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries. It's designed to allow AI assistants like Claude to interact with PostgreSQL databases in a controlled, secure manner.
Installation Options
You can run the PostgreSQL MCP server using either Docker or NPX.
Docker Installation
To use the server with Docker:
docker run -i --rm mcp/postgres postgresql://host:port/db-name
Note for macOS users: When running Docker on macOS, use host.docker.internal
in place of localhost
if the server is running on the host network:
docker run -i --rm mcp/postgres postgresql://host.docker.internal:5432/db-name
NPX Installation
Alternatively, you can run the server directly with NPX:
npx -y @modelcontextprotocol/server-postgres postgresql://localhost/db-name
Replace /db-name
with your actual database name.
Configuring with Claude Desktop
To use this PostgreSQL MCP server with the Claude Desktop app, you'll need to add configuration to your claude_desktop_config.json
file.
Docker Configuration
Add the following to the "mcpServers" section of your config file:
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"]
}
}
}
NPX Configuration
Alternatively, use NPX configuration:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}
Authentication
To include username and password authentication, add them to the PostgreSQL URL:
postgresql://username:password@host:port/db-name
Capabilities
The PostgreSQL MCP server offers:
Query Tool
Execute read-only SQL queries against your database:
- All queries run within a READ ONLY transaction for safety
- Input required:
sql
(string) containing the SQL query to execute
Database Schema Access
The server automatically provides schema information for all tables:
- Available at
postgres://<host>/<table>/schema
- Includes JSON schema with column names and data types
- Schema information is automatically discovered from database metadata
How to add this MCP server to Cursor
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
Adding an MCP server to Cursor globally
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
Adding an MCP server to a project
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
How to use the MCP server
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.
Related servers
Time
MCP server providing time and timezone conversion tools for AI assistants to handle localized time data and calculations...
AWS Bedrock: Knowledge Base
Query and retrieve information from AWS knowledge bases using the Bedrock Agent Runtime.
Google Maps
Access location data, geocoding, and place details through Maps API.