Overview
PostgreSQL is a Model Context Protocol server providing read-only access to PostgreSQL databases, allowing for schema inspection and execution of read-only queries.
To use PostgreSQL, configure it within the Claude Desktop app by adding the necessary parameters to the "mcpServers" section of the `claude_desktop_config.json` file. Replace the database name in the configuration with your specific database.
- Execute read-only SQL queries within a read-only transaction. - Access detailed schema information for each table, including column names and data types. - Automatically discovers schemas from database metadata.
- Inspecting database schemas before performing extensive data analysis.
- Running read-only queries to generate reports without altering database states.
- Integration with LLMs for database-related tasks in applications.
Tools
query
Run a read-only SQL query
Run a read-only SQL query
Add to your AI client
Use these steps to connect PostgreSQL in Cursor, Claude, VS Code, and other MCP-compatible apps. The same JSON appears in the Use with menu above for one-click copy.
Cursor
Add this to your .cursor/mcp.json file in your project root, then restart Cursor.
.cursor/mcp.json
{
"mcpServers": {
"postgres-modelcontextprotocol": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}Claude Desktop
Add this server entry to the mcpServers object in your Claude Desktop config, then restart the app.
~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
{
"mcpServers": {
"postgres-modelcontextprotocol": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}Claude Code
Add this to your project's .mcp.json file. Claude Code will detect it automatically.
.mcp.json (project root)
{
"mcpServers": {
"postgres-modelcontextprotocol": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}VS Code (Copilot)
Add this to your .vscode/mcp.json file. Requires the GitHub Copilot extension with MCP support enabled.
.vscode/mcp.json
{
"servers": {
"postgres-modelcontextprotocol": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}Windsurf
Add this to your Windsurf MCP config file, then restart Windsurf.
~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"postgres-modelcontextprotocol": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}Cline
Open Cline settings, navigate to MCP Servers, and add this server configuration.
Cline MCP Settings (via UI)
{
"mcpServers": {
"postgres-modelcontextprotocol": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}FAQ
Is PostgreSQL suitable for writing data?
No! PostgreSQL provides read-only access, which means data cannot be modified through this server.
Can I use PostgreSQL with other apps?
Yes! While designed for Claude Desktop, PostgreSQL can be integrated into other applications that can call its endpoints.
How do I get schema information for a table?
Schema information is automatically discovered and can be accessed via the provided schema URL endpoint.