postgres
A Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.
The PostgreSQL Model Context Protocol (MCP) server is designed to facilitate read-only interactions with PostgreSQL databases. It allows Language Model Machines (LLMs) to access and inspect database schemas, as well as execute read-only SQL queries. This server is particularly useful for applications that require database insights without the risk of data modification. The server operates by connecting to a PostgreSQL database and providing schema information for each table, including column names and data types. It supports various platforms, including Docker and NPX, and can be easily integrated into development environments like VS Code and Claude Desktop. The server is licensed under the MIT License, allowing for free use, modification, and distribution.
Features
- Read-only SQL query execution
- Automatic schema discovery
- Integration with Docker and NPX
- Support for VS Code and Claude Desktop
- MIT License for open use
MCP Tools
- query: Execute read-only SQL queries against the connected database. All queries are executed within a READ ONLY transaction.
MCP Resources
- {'name': 'Table Schemas', 'description': 'JSON schema information for each table, including column names and data types, automatically discovered from database metadata.'}
Usage with Different Platforms
Claude Desktop
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"]
}
}
}
Docker
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@host.docker.internal:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"${input:pg_url}"
]
}
}
}
}
NPX
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@localhost:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"${input:pg_url}"
]
}
}
}
}