home / mcp / go mcp postgres mcp server
Provides CRUD and read-only operations for PostgreSQL databases via MCP with optional query plan validation.
Configuration
View docs{
"mcpServers": {
"guoling2008-go-mcp-postgres": {
"command": "go-mcp-postgres",
"args": [
"--dsn",
"postgresql://user:pass@host:port/db"
]
}
}
}You get a zero-burden MCP server that lets you interact with PostgreSQL databases through CRUD operations, with an optional read-only mode and an explain-check feature to validate queries before execution. It runs as a self-contained Go-based MCP server, so you don’t need Node.js or Python environments to automate database tasks.
Start the MCP server using the provided command so you can connect with an MCP client. You configure the server to connect to your PostgreSQL database via a DSN (Data Source Name). You can enable read-only mode to restrict operations to listing and reading data, which helps prevent unintended writes. If you want to validate query plans before executing CRUD operations, you can use the explain-check behavior.
Prerequisites: you need a Go toolchain installed on your system to build or install the MCP server from source.
Option A: Install a prebuilt binary (simplest)
- Ensure the binary is placed in your PATH or a location you can easily access.
Option B: Build from source with Go
- Run: go install -v github.com/guoling2008/go-mcp-postgres@latest
{
"mcpServers": {
"postgres": {
"command": "go-mcp-postgres",
"args": [
"--dsn",
"postgresql://user:pass@host:port/db"
]
}
}
}You can run the server in standard stdio mode or in SSE mode (streaming). In stdio mode, the server starts from the command and arguments you provide. In SSE mode, you specify the network binding and language parameters as shown in the usage example. You can also enable read-only mode to restrict to listing and reading tools, and you can disable the default EXPLAIN-check if you prefer not to validate query plans.
Security and best practices: Use a strong DSN with restricted database privileges for the MCP server user. If your deployment requires multiple environments (dev/stage/prod), separate DSNs per environment and consider environment-specific flags or configurations to minimize cross-environment impacts.
List available databases matching the provided criteria or show all databases if no filter is supplied.
List tables in a database, optionally filtering by table name.
Create a new table using a provided SQL query and return the number of rows affected.
Alter an existing table; the system will ensure an existing table or column is not dropped during the operation.
Describe the structure of a specified table, returning its columns and types.
Execute a read-only SQL query and return the results.
Execute a write SQL query and return the number of rows affected plus the last insert identifier when applicable.
Execute an update SQL query and return the number of rows affected.
Execute a delete SQL query and return the number of rows affected.
Return the row count for a specified table.