get_sql_instance_details
Retrieve comprehensive details about a specific Cloud SQL instance in Google Cloud Platform (GCP) by providing the project ID and instance ID for quick insights and management.
Instructions
Get detailed information about a specific Cloud SQL instance.
Args:
project_id: The ID of the GCP project
instance_id: The ID of the Cloud SQL instance
Returns:
Detailed information about the specified Cloud SQL instance
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instance_id | Yes | ||
| project_id | Yes |
Implementation Reference
- The handler function for the 'get_sql_instance_details' tool. It uses the Google Cloud SQL Admin API to retrieve and format detailed information about a specified Cloud SQL instance, including name, version, state, settings (tier, storage, backups, IP config), and IP addresses.def get_sql_instance_details(project_id: str, instance_id: str) -> str: """ Get detailed information about a specific Cloud SQL instance. Args: project_id: The ID of the GCP project instance_id: The ID of the Cloud SQL instance Returns: Detailed information about the specified Cloud SQL instance """ try: from googleapiclient import discovery # Initialize the Cloud SQL Admin API client service = discovery.build('sqladmin', 'v1') # Get instance details request = service.instances().get(project=project_id, instance=instance_id) instance = request.execute() # Format the response details = [] details.append(f"Name: {instance.get('name', 'Unknown')}") details.append(f"Self Link: {instance.get('selfLink', 'Unknown')}") details.append(f"Database Version: {instance.get('databaseVersion', 'Unknown')}") details.append(f"State: {instance.get('state', 'Unknown')}") details.append(f"Region: {instance.get('region', 'Unknown')}") # Settings information if 'settings' in instance: settings = instance['settings'] details.append(f"Tier: {settings.get('tier', 'Unknown')}") details.append(f"Storage Size: {settings.get('dataDiskSizeGb', 'Unknown')}GB") details.append(f"Availability Type: {settings.get('availabilityType', 'Unknown')}") # Backup configuration if 'backupConfiguration' in settings: backup = settings['backupConfiguration'] enabled = backup.get('enabled', False) details.append(f"Automated Backups: {'Enabled' if enabled else 'Disabled'}") if enabled: details.append(f"Backup Start Time: {backup.get('startTime', 'Unknown')}") details.append(f"Binary Log Enabled: {backup.get('binaryLogEnabled', False)}") # IP configuration if 'ipConfiguration' in settings: ip_config = settings['ipConfiguration'] public_ip = "Enabled" if not ip_config.get('privateNetwork') else "Disabled" details.append(f"Public IP: {public_ip}") if 'authorizedNetworks' in ip_config: networks = [] for network in ip_config['authorizedNetworks']: name = network.get('name', 'Unnamed') value = network.get('value', 'Unknown') networks.append(f" - {name}: {value}") if networks: details.append("Authorized Networks:") details.extend(networks) # IP Addresses if 'ipAddresses' in instance: ip_addresses = [] for ip in instance['ipAddresses']: ip_type = ip.get('type', 'Unknown') ip_address = ip.get('ipAddress', 'Unknown') ip_addresses.append(f" - {ip_type}: {ip_address}") if ip_addresses: details.append("IP Addresses:") details.extend(ip_addresses) details_str = "\n".join(details) return f""" Cloud SQL Instance Details: {details_str} """ except Exception as e: return f"Error getting SQL instance details: {str(e)}"
- src/gcp_mcp/server.py:56-57 (registration)The registration call for the databases tools module, which includes the 'get_sql_instance_details' tool via databases_tools.register_tools(mcp).# Register databases tools databases_tools.register_tools(mcp)
- src/gcp_mcp/gcp_modules/databases/tools.py:57-57 (registration)The @mcp.tool() decorator that registers the get_sql_instance_details function as an MCP tool.def get_sql_instance_details(project_id: str, instance_id: str) -> str: