A Model Context Protocol server that provides both read and write access to PostgreSQL databases. This server enables LLMs to inspect database schemas, execute queries, modify data, and create/modify database schema objects.
Note: This is an enhanced version of the original PostgreSQL MCP server by Anthropic. The original server provides read-only access, while this enhanced version adds write capabilities and schema management.
sql
(string): The SQL query to executeexecute
sql
(string): The SQL statement to executeinsert
table
(string): The table namedata
(object): Key-value pairs where keys are column names and values are the data to insertupdate
table
(string): The table namedata
(object): Key-value pairs for the fields to updatewhere
(string): The WHERE condition to identify records to updatedelete
table
(string): The table namewhere
(string): The WHERE condition to identify records to deletecreateTable
tableName
(string): The table namecolumns
(array): Array of column definitions with name, type, and optional constraintsconstraints
(array): Optional array of table-level constraintscreateFunction
name
(string): Function nameparameters
(string): Function parametersreturnType
(string): Return typelanguage
(string): Language (plpgsql, sql, etc.)body
(string): Function bodyoptions
(string): Optional additional function optionscreateTrigger
name
(string): Trigger nametableName
(string): Table to apply trigger tofunctionName
(string): Function to callwhen
(string): BEFORE, AFTER, or INSTEAD OFevents
(array): Array of events (INSERT, UPDATE, DELETE)forEach
(string): ROW or STATEMENTcondition
(string): Optional WHEN conditioncreateIndex
tableName
(string): Table nameindexName
(string): Index namecolumns
(array): Columns to indexunique
(boolean): Whether the index is uniquetype
(string): Optional index type (BTREE, HASH, GIN, GIST, etc.)where
(string): Optional conditionalterTable
tableName
(string): Table nameoperation
(string): Operation (ADD COLUMN, DROP COLUMN, etc.)details
(string): Operation detailsThe server provides schema information for each table in the database:
postgres://<host>/<table>/schema
)
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json
:
postgresql://user:password@host:port/db-name
?sslmode=no-verify
if you need to bypass SSL certificate verification{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"]
}
}
}
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}
Replace /mydb
with your database name.
/query SELECT * FROM users LIMIT 5
/insert table="users", data={"name": "John Doe", "email": "john@example.com"}
/update table="users", data={"status": "inactive"}, where="id='123'"
/createTable tableName="tasks", columns=[
{"name": "id", "type": "SERIAL", "constraints": "PRIMARY KEY"},
{"name": "title", "type": "VARCHAR(100)", "constraints": "NOT NULL"},
{"name": "created_at", "type": "TIMESTAMP", "constraints": "DEFAULT CURRENT_TIMESTAMP"}
]
/createFunction name="update_timestamp", parameters="", returnType="TRIGGER", language="plpgsql", body="BEGIN NEW.updated_at = NOW(); RETURN NEW; END;"
/createTrigger name="set_timestamp", tableName="tasks", functionName="update_timestamp", when="BEFORE", events=["UPDATE"], forEach="ROW"
Docker:
docker build -t mcp/postgres -f Dockerfile .
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
{
"mcpServers": {
"postgres": {
"env": {},
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
],
"command": "docker"
}
}
}
Seamless access to top MCP servers powering the future of AI integration.