list-sql-instances
Retrieve all Cloud SQL instances in your current GCP project to manage database resources and monitor configurations.
Instructions
List all Cloud SQL instances in the current project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.ts:591-619 (handler)The handler function that executes the 'list-sql-instances' tool. It checks if a project is selected, creates a SqlInstancesServiceClient, lists the instances for the project, maps them to a simplified format, and returns the JSON response. Handles errors gracefully.} else if (name === "list-sql-instances") { if (!selectedProject) { return createTextResponse("No project selected. Please select a project first."); } try { const sqlClient = new SqlInstancesServiceClient({ fallback: 'rest' // Use HTTP/1.1 fallback mode instead of gRPC }); const request = { project: selectedProject }; const [response] = await sqlClient.list(request); return createTextResponse(JSON.stringify({ instances: (response?.items || []).map(instance => ({ name: instance.name || null, databaseVersion: instance.databaseVersion || null, state: instance.state || null, region: instance.region || null })) }, null, 2)); } catch (error: any) { console.error('Error listing SQL instances:', error); return createTextResponse(`Error listing SQL instances: ${error.message}`); } } else if (name === "get-logs") {
- index.ts:186-193 (registration)Registration of the 'list-sql-instances' tool in the server's listTools response, including name, description, and input schema (empty object since no parameters required).name: "list-sql-instances", description: "List all Cloud SQL instances in the current project", inputSchema: { type: "object", properties: {}, required: [], }, },
- index.ts:258-263 (schema)TypeScript interface defining the structure of SQL instances returned by the handler, used for type safety in the response mapping.interface SQLInstance { name: string | null; databaseVersion: string | null; state: string | null; region: string | null; }
- index.ts:22-22 (helper)Import of the SqlInstancesServiceClient used by the handler.import { SqlInstancesServiceClient } from '@google-cloud/sql';