tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > MCP Protocol > MCP Server with Cloud Spanner

MCP Server with Cloud Spanner

Author: Venkata Sudhakar

Cloud Spanner is Google's fully managed, globally distributed relational database that offers strong consistency and high availability. By wrapping Spanner as an MCP server, AI agents can run SQL queries, insert records, and perform transactional operations through simple tool calls.

ShopMax India uses Cloud Spanner as its inventory and orders database across Mumbai, Bangalore, and Delhi regions. An MCP server exposes Spanner operations as tools so that ADK agents can query stock levels, process orders, and check regional availability without any direct database credentials.

The below example shows an MCP server that exposes two tools - one for querying product inventory and another for inserting an order record into Cloud Spanner.


It gives the following output,

# Agent query: "Show Laptops stock in Mumbai"
Tool: query_inventory({city: "Mumbai", category: "Laptops"})

[{"product_id": "LAP001", "name": "Dell Inspiron 15", "stock": 42, "price_rs": 55000},
 {"product_id": "LAP002", "name": "HP Pavilion 14", "stock": 18, "price_rs": 49000},
 {"product_id": "LAP003", "name": "Lenovo IdeaPad 3", "stock": 67, "price_rs": 43000}]

# Agent query: "Create order ORD-9001 for LAP001 in Mumbai, qty 2 at Rs 110000"
Tool: insert_order({order_id: "ORD-9001", product_id: "LAP001", city: "Mumbai", quantity: 2, amount: 110000})

Order inserted successfully

For production deployments, use Spanner's read-only replicas for query tools to reduce costs, while reserving read-write transactions for mutation tools. Apply IAM roles at the database level so the MCP server service account has only the permissions it needs. Use Spanner's built-in query statistics to monitor slow queries from agent workloads.


 
  


  
bl  br