|
|
MCP Server with Cloud SQL
Author: Venkata Sudhakar
Cloud SQL is Google Cloud's fully managed relational database service supporting MySQL, PostgreSQL, and SQL Server. For teams already running Cloud SQL in production, building an MCP server on top of it is the fastest way to give AI agents structured data access without changing the database layer.
ShopMax India uses Cloud SQL MySQL for its product catalogue and pricing engine. The MCP server below uses the Cloud SQL Python Connector for secure IAM-authenticated connections, and exposes tools to fetch product details and update prices - operations the pricing agent uses daily.
The below example shows an MCP server connecting to Cloud SQL MySQL using the google-cloud-sql-connector library and exposing product catalogue tools.
It gives the following output,
# Agent query: "Get details for Samsung TV"
Tool: get_product({identifier: "Samsung TV"})
[{"product_id": "TV-201", "name": "Samsung 55 Crystal 4K", "category": "Televisions",
"price_rs": 62000, "stock": 15},
{"product_id": "TV-202", "name": "Samsung 43 Smart LED", "category": "Televisions",
"price_rs": 38000, "stock": 28}]
# Agent query: "Update price of TV-201 to Rs 59000"
Tool: update_price({product_id: "TV-201", new_price_rs: 59000})
Price updated successfully
For production deployments, use IAM database authentication instead of password-based credentials so the MCP server service account authenticates directly without storing passwords. Enable Cloud SQL read replicas and direct read-only MCP tools to the replica endpoint to reduce load on the primary. Use connection pooling with a max pool size tuned to the Cloud SQL instance tier to avoid connection exhaustion under concurrent agent load.
|
|