list_cloud_sql_instances
Retrieve a list of Cloud SQL instances within a specified GCP project using this tool. It simplifies database instance management by providing an organized overview of your SQL resources for efficient project monitoring and administration.
Instructions
List Cloud SQL instances in a GCP project.
Args:
project_id: The ID of the GCP project to list Cloud SQL instances for
Returns:
List of Cloud SQL instances in the specified GCP project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes |
Implementation Reference
- The handler function decorated with @mcp.tool() that implements the logic to list Cloud SQL instances in a GCP project using the SQL Admin API.@mcp.tool() def list_cloud_sql_instances(project_id: str) -> str: """ List Cloud SQL instances in a GCP project. Args: project_id: The ID of the GCP project to list Cloud SQL instances for Returns: List of Cloud SQL instances in the specified GCP project """ try: from googleapiclient import discovery # Initialize the Cloud SQL Admin API client service = discovery.build('sqladmin', 'v1') # List SQL instances request = service.instances().list(project=project_id) response = request.execute() # Format the response instances_list = [] if 'items' in response: for instance in response['items']: name = instance.get('name', 'Unknown') db_version = instance.get('databaseVersion', 'Unknown') state = instance.get('state', 'Unknown') region = instance.get('region', 'Unknown') tier = instance.get('settings', {}).get('tier', 'Unknown') storage_size = instance.get('settings', {}).get('dataDiskSizeGb', 'Unknown') instances_list.append(f"- {name} (Type: {db_version}, Region: {region}, Tier: {tier}, Storage: {storage_size}GB, State: {state})") if not instances_list: return f"No Cloud SQL instances found in project {project_id}." instances_str = "\n".join(instances_list) return f""" Cloud SQL Instances in GCP Project {project_id}: {instances_str} """ except Exception as e: return f"Error listing Cloud SQL instances: {str(e)}"
- src/gcp_mcp/server.py:57-57 (registration)Call to register the databases tools module, which registers the list_cloud_sql_instances tool among others.databases_tools.register_tools(mcp)
- src/gcp_mcp/gcp_modules/databases/tools.py:6-6 (registration)The register_tools function in the databases module where the list_cloud_sql_instances tool is defined and registered via decorator.def register_tools(mcp):