I built pg-mcp, a Model Context Protocol (MCP) server for PostgreSQL that provides structured schema inspection and query execution for LLMs and agents. It's multi-tenant and runs over HTTP/SSE (not stdio)
Features - Supports multiple database connections from multiple agents
- Schema Introspection: Returns table structures, types, indexes and constraints; enriched with descriptions from pg_catalog. (for well documented databases)
- Read-Only Queries: Controlled execution of queries via MCP.
- EXPLAIN Tool: Helps smart agents optimize queries before execution.
- Extension Plugins: YAML-based plugin system for Postgres extensions (supports pgvector and postgis out of the box).
- Server Mode: Spin up the container and it's ready to accept connections at http://localhost:8000/sse
Basically, it's not rocket science. I also built MCP servers for Mysql, Twilio, Polars, etc.
> Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something.
We are hackers here. Building is good. Sharing is good. All this is true even if you personally know how to do what is being shared, and it is easy for you. I promise you there are people who encounter every sharing post here and do not think what is posted is easy.
sidenote: I'm scared of what's going to happen to those roles!
Q: show me the top 5 customers by total sales
A: System.Data.Odbc.OdbcException (0x80131937): ERROR [57014] ERROR: canceling statement due to statement timeout;
Q: Why do I get this error
A: Looks like it needs an index, let me create that for you. Done. Rerunnign query.
could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
Q: Why this error
A: 429 Too Many Requests
Rub hands... great next 10 years to be a backend dev.
The question is do they still need 10? Or 2 would suffice? How about 5?
This does not need to be a debate about the absolutes.
It doesn't work because the PHB doesn't have the domain knowledge and doesn't know which questions to ask. (No, it's never as simple as group-by and top-5.)
I suppose this could be useful in that it prevents everyone in the company having to learn even the basics of SQL which is some barrier, however minimal.
Also the LLM will presumably be able to see all the tables/fields and ‘understand’ them (with the big assumption that they are even remotely reasonably named) so English language queries will be much more feasible now. Basically what LLMs have over all those older attempts is REALLY good fuzziness.
I see this being useful for some subset of questions.
Do human reviewing and correcting of the updated documentation. Then ensure that the AI knows that the documentation might still contain errors and ask it to do the 'actual' work.
[1] https://bird-bench.github.io/
Thats cute.
i suppose the desktop app can use it, but how good is it for this general purpose "chat with the database for lightweight analytics" use cases is it worth the trouble of dealing with some electron app to make it work?
Agents will become ubiquitous parts of the user interface that is currently the chat.
So if you bother with a website or an electron app now, MCP will just add more capabilities to what you can control using agents.
OP, exposing your application without authentication is a serious security risk!
Quick anecdote: Last week, I ran a Redis container on a VPS with an exposed port and no password (rookie mistake). Within 24 hours, the logs revealed someone attempting to make my Redis instance a slave to theirs! The IP traced back to Tencent, the Chinese tech giant... Really weird. Fortunately, there was nothing valuable stored in it.
They're a large cloud provider in Asia like Amazon AWS or Microsoft Azure. I doubt such a tech company would make it that obvious when breaking the law.
https://github.com/stuzero/pg-mcp/blob/main/server/tools/que...
What I'd be looking for is a MCP server where I can run in "biz/R&D exploration-mode", eg:
- assume I'm working on a replica (shared about all R&D engineers) - they can connect and make read-only queries to the replica for the company data - they have a temporary read-write schema just for their current connection so they can have temporary tables and caches - temporary data is deleted when they close the session
How could you make a setup like that so that when using your MCP server, I'm not worried about the model / users modifying the data, but only doing their own private queries/tables?