The Enhanced PostgreSQL MCP Server is 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. It is an enhanced version of the original PostgreSQL MCP server by Anthropic, adding write capabilities and schema management.
sql
(string): The SQL query to executesql
(string): The SQL statement to executetable
(string): The table namedata
(object): Key-value pairs where keys are column names and values are the data to inserttable
(string): The table namedata
(object): Key-value pairs for the fields to updatewhere
(string): The WHERE condition to identify records to updatetable
(string): The table namewhere
(string): The WHERE condition to identify records to deletetableName
(string): The table namecolumns
(array): Array of column definitions with name, type, and optional constraintsconstraints
(array): Optional array of table-level constraintsname
(string): Function nameparameters
(string): Function parametersreturnType
(string): Return typelanguage
(string): Language (plpgsql, sql, etc.)body
(string): Function bodyoptions
(string): Optional additional function optionsname
(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 conditiontableName
(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 conditiontableName
(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
:
{
"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": "[email protected]"}
/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 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.
No description, website, or topics provided.