A Go implementation of a Model Context Protocol (MCP) server for PostgreSQL. This server enables LLMs to inspect database schemas and execute read-only queries against PostgreSQL databases.
- Exposes PostgreSQL table schemas as resources
- Provides a tool to execute read-only SQL queries
- Uses sqlx for PostgreSQL connectivity
- Built with the mcp-go library
go install github.com/iwanbk/postgres-mcp-go@latestOr build from source:
git clone https://github.com/iwanbk/postgres-mcp-go.git
cd postgres-mcp-go
go build -vRun the server by providing a PostgreSQL connection URL using the -database_url flag:
postgres-mcp-go -database_url=postgresql://username:password@localhost/mydbYou can also view available options with the help flag:
postgres-mcp-go -helpThe server provides schema information for each table in the database:
postgres://<host>/<table>/schema- JSON schema information for each table- Includes column names and data types
- Automatically discovered from database metadata
query- Execute read-only SQL queries against the connected database- Input:
sql(string): The SQL query to execute - All queries are executed within a READ ONLY transaction
- Input:
This server only allows read-only operations. All queries are executed within a READ ONLY transaction to prevent any data modification.
MIT