gcp-postgres-tools
Provides read-only query tools for a PostgreSQL database, including retrieving recent users, user details, and recent user activities.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@gcp-postgres-toolsShow me the most recent 10 users."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GCP Postgres MCP Tools
FastAPI app that connects to your GCP PostgreSQL database and exposes query tools over REST and MCP.
Setup
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .envPut your Cloud SQL URL in .env. If you already use a local Cloud SQL Auth Proxy, point at that host and port:
DATABASE_URL=postgresql+asyncpg://USERNAME:PASSWORD@127.0.0.1:5439/DATABASE_NAME
USERS_TABLE=tbl_users
USERS_ORDER_COLUMN=date_joinedThis app is read-only against Cloud SQL. Every production session sets default_transaction_read_only and SET TRANSACTION READ ONLY. REST tools are GET-only. POST is allowed only on /mcp (protocol) and /agent/chat (the agent loop). Agent traces are written to a separate local SQLite file, never to evolve_production.
get_last_10_users uses tbl_users. get_last_5_user_activities uses tbl_user_activities. Password columns are never returned.
For production, also use a Cloud SQL user that has SELECT only.
Related MCP server: PostgreSQL MCP Server
Run
uvicorn app.main:app --reload --port 8000Health:
GET /healthDocs:
http://127.0.0.1:8000/docsMCP:
http://127.0.0.1:8000/mcpAgent:
POST /agent/chatTraces:
GET /agent/tracesandGET /agent/traces/{trace_id}
Agentic loop and traces
The agent is a ReAct loop: think → call a read-only tool → observe → repeat → final answer.
curl -s http://127.0.0.1:8000/agent/chat \
-H 'Content-Type: application/json' \
-d '{"message":"Get the last 10 users"}'Each run stores a structured trace (user_input, LLM tool choices, tool results, final answer) in data/traces.db.
The agent uses the Gemini Developer API (Google AI Studio key), not Vertex AI and not OpenAI.
GEMINI_API_KEY=AIza...
GEMINI_MODEL=gemini-3.6-flashGet a key at aistudio.google.com/apikey. GOOGLE_API_KEY also works.
These are not the same as a Vertex AI key. Gemini keys start with AIza and do not need a GCP project or region.
Optional: LangSmith via LANGSMITH_TRACING=true and LANGSMITH_API_KEY.
Without GEMINI_API_KEY, /agent/chat returns 503. REST and MCP read tools still work.
Each chat request is capped so the agent cannot loop or retry forever:
Setting | Default | What it stops |
| 2 | Gemini HTTP retries |
| 1 | Tool/DB retries |
| 5 | Tools per request |
| 6 | Model turns per request |
| 12 | Hard LangGraph step stop |
Tools
REST | MCP tool | What it does |
|
| Latest 10 users |
|
| One user by id |
|
| Latest 5 activities |
|
| Full agent audit trace |
|
| Recent agent traces |
Password and hash columns are never returned.
Cursor MCP config
{
"mcpServers": {
"gcp-postgres-tools": {
"url": "http://127.0.0.1:8000/mcp"
}
}
}This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Generate, fix, explain and run read-only SQL on PostgreSQL, MySQL and SQL Server
Create, manage, and query your Google Cloud SQL resources.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only SQL queries.64,378 npmMIT
- FlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases with schema inspection, query execution in multiple formats (JSON, CSV, Markdown), and query history tracking with built-in security features.-
- AlicenseNot gradedqualityCmaintenanceEnables secure read-only access to PostgreSQL databases, allowing users to list tables, query schemas, execute SELECT statements, and inspect table structures through natural language interactions.306 npm4MIT
- AlicenseNot gradedqualityDmaintenanceEnables safe interaction with PostgreSQL databases through read-only queries, schema exploration, and performance analysis.65 npmMIT