|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Ensure VERSION is passed from the environment |
| 5 | +if [ -z "$VERSION" ]; then |
| 6 | + echo "Error: VERSION environment variable is not set." |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +# SKILL CONFIGURATION |
| 11 | +# Format: "toolset" "description" |
| 12 | +# The skill name is automatically generated as "cloud-sql-postgres-<toolset>" |
| 13 | +SKILLS=( |
| 14 | + "admin" |
| 15 | + "Use these skills when you need to provision new Cloud SQL instances, create databases and users, clone existing environments, and monitor the progress of long-running operations." |
| 16 | + |
| 17 | + "lifecycle" |
| 18 | + "Use these skills when you need to manage the lifecycle of your instances, including performing backups and restores, checking major version upgrade compatibility, and monitoring overall instance status." |
| 19 | + |
| 20 | + "data" |
| 21 | + "Use these skills when you need to explore the database structure, discover schema objects like views or stored procedures, and execute custom SQL queries to interact with your data." |
| 22 | + |
| 23 | + "health" |
| 24 | + "Use these skills when you need to audit database health, identify storage bloat, find invalid indexes, analyze table statistics, and manage maintenance configurations like autovacuum." |
| 25 | + |
| 26 | + "monitor" |
| 27 | + "Use these skills when you need to troubleshoot performance bottlenecks, analyze query execution plans, identify resource-heavy processes, and monitor system-level PromQL metrics." |
| 28 | + |
| 29 | + "view-config" |
| 30 | + "Use these skills when you need to discover and manage PostgreSQL extensions or fine-tune engine-level settings such as memory allocation and server configuration parameters." |
| 31 | + |
| 32 | + "replication" |
| 33 | + "Use these skills when you need to monitor replication health, manage sync states between nodes, and audit database roles and security settings to ensure environment integrity." |
| 34 | + |
| 35 | + "vectorassist" |
| 36 | + "Use these skills to set up and optimize production-ready vector workloads by simply expressing your intent and performance requirements" |
| 37 | +) |
| 38 | + |
| 39 | +echo "VALIDATING TOOLSETS BEFORE GENERATION" |
| 40 | + |
| 41 | +# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array. |
| 42 | +# We use 'set --' to process the array in chunks without index arithmetic. |
| 43 | +SUPPORTED_TOOLSETS=() |
| 44 | +set -- "${SKILLS[@]}" |
| 45 | +while [ $# -gt 0 ]; do |
| 46 | + SUPPORTED_TOOLSETS+=("$1") |
| 47 | + shift 2 |
| 48 | +done |
| 49 | + |
| 50 | +echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}" |
| 51 | + |
| 52 | +# Fetch the upstream source of truth YAML for this specific version |
| 53 | +RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml" |
| 54 | +echo "Fetching upstream config from: $RAW_URL" |
| 55 | +UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; }) |
| 56 | + |
| 57 | +# Extract the list of toolsets |
| 58 | +UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '/^toolsets:/{flag=1; next} flag && /^ [a-zA-Z0-9_-]+:/{print $1}' | sed 's/://g') |
| 59 | + |
| 60 | +# Compare upstream toolsets against our supported list |
| 61 | +MISSING_TOOLSETS=false |
| 62 | + |
| 63 | +for upstream_tool in $UPSTREAM_TOOLSETS; do |
| 64 | + if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi |
| 65 | + |
| 66 | + if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then |
| 67 | + echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'" |
| 68 | + MISSING_TOOLSETS=true |
| 69 | + fi |
| 70 | +done |
| 71 | + |
| 72 | +if [ "$MISSING_TOOLSETS" = true ]; then |
| 73 | + echo "PIPELINE FAILED: Missing Toolset Generators" |
| 74 | + echo "The source of truth file has toolsets that your script does not support." |
| 75 | + echo "Please update the SKILLS array in generate_skills.sh to include generators" |
| 76 | + echo "for the missing toolsets above, then commit your changes to unblock this PR." |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | + |
| 80 | +echo "Validation passed. All upstream toolsets are supported." |
| 81 | + |
| 82 | +echo "BEGINNING SKILL GENERATION" |
| 83 | + |
| 84 | +LICENSE_HEADER="// Copyright 2026 Google LLC |
| 85 | +// |
| 86 | +// Licensed under the Apache License, Version 2.0 (the \"License\"); |
| 87 | +// you may not use this file except in compliance with the License. |
| 88 | +// You may obtain a copy of the License at |
| 89 | +// |
| 90 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 91 | +// |
| 92 | +// Unless required by applicable law or agreed to in writing, software |
| 93 | +// distributed under the License is distributed on an \"AS IS\" BASIS, |
| 94 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 95 | +// See the License for the specific language governing permissions and |
| 96 | +// limitations under the License." |
| 97 | + |
| 98 | +ADDITIONAL_NOTES="Note: The scripts automatically load the environment variables from various .env files. Do not ask the user to set vars unless skill executions fails due to env var absence." |
| 99 | + |
| 100 | +# Base Command Function |
| 101 | +generate_skill() { |
| 102 | + local TOOLSET="$1" |
| 103 | + local SKILL_DESC="$2" |
| 104 | + local SKILL_NAME="cloud-sql-postgres-$TOOLSET" |
| 105 | + |
| 106 | + echo "Generating skill: $SKILL_NAME..." |
| 107 | + |
| 108 | + npx "@toolbox-sdk/server@${VERSION}" --prebuilt cloud-sql-postgres skills-generate \ |
| 109 | + --name "$SKILL_NAME" \ |
| 110 | + --description "$SKILL_DESC" \ |
| 111 | + --toolset="$TOOLSET" \ |
| 112 | + --license-header "$LICENSE_HEADER" \ |
| 113 | + --additional-notes="$ADDITIONAL_NOTES" |
| 114 | +} |
| 115 | + |
| 116 | +set -- "${SKILLS[@]}" |
| 117 | +while [ $# -gt 0 ]; do |
| 118 | + generate_skill "$1" "$2" |
| 119 | + shift 2 |
| 120 | +done |
| 121 | + |
| 122 | +echo "All skills generated successfully!" |
0 commit comments