|
| 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-mysql-<toolset>" |
| 13 | +SKILLS=( |
| 14 | + "admin" |
| 15 | + "Use these skills when you need to provision new Cloud SQL for MySQL instances, create databases and users, clone existing environments, and monitor the progress of infrastructure operations." |
| 16 | + |
| 17 | + "data" |
| 18 | + "Use these skills when you need to explore your database schema, execute SQL queries to interact with your data, and inspect how MySQL plans to execute your statements." |
| 19 | + |
| 20 | + "monitor" |
| 21 | + "Use these skills when you need to troubleshoot slow queries, analyze system-level PromQL metrics, and identify structural performance issues like table fragmentation or missing unique indexes." |
| 22 | + |
| 23 | + "lifecycle" |
| 24 | + "Use these skills when you need to manage the durability and safety of your data by creating backups, restoring from previous states, or cloning instances for recovery and testing." |
| 25 | +) |
| 26 | + |
| 27 | +echo "VALIDATING TOOLSETS BEFORE GENERATION" |
| 28 | + |
| 29 | +# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array. |
| 30 | +# We use 'set --' to process the array in chunks without index arithmetic. |
| 31 | +SUPPORTED_TOOLSETS=() |
| 32 | +set -- "${SKILLS[@]}" |
| 33 | +while [ $# -gt 0 ]; do |
| 34 | + SUPPORTED_TOOLSETS+=("$1") |
| 35 | + shift 2 |
| 36 | +done |
| 37 | + |
| 38 | +echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}" |
| 39 | + |
| 40 | +# Fetch the upstream source of truth YAML for this specific version |
| 41 | +RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml" |
| 42 | +echo "Fetching upstream config from: $RAW_URL" |
| 43 | +UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; }) |
| 44 | + |
| 45 | +# Extract the list of toolsets. Each toolset is its own YAML document: |
| 46 | +# kind: toolset |
| 47 | +# name: <toolset> |
| 48 | +UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '$1=="kind:" && $2=="toolset"{f=1; next} f && $1=="name:"{print $2; f=0}') |
| 49 | + |
| 50 | +# Compare upstream toolsets against our supported list |
| 51 | +MISSING_TOOLSETS=false |
| 52 | + |
| 53 | +for upstream_tool in $UPSTREAM_TOOLSETS; do |
| 54 | + if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi |
| 55 | + |
| 56 | + if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then |
| 57 | + echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'" |
| 58 | + MISSING_TOOLSETS=true |
| 59 | + fi |
| 60 | +done |
| 61 | + |
| 62 | +if [ "$MISSING_TOOLSETS" = true ]; then |
| 63 | + echo "PIPELINE FAILED: Missing Toolset Generators" |
| 64 | + echo "The source of truth file has toolsets that your script does not support." |
| 65 | + echo "Please update the SKILLS array in generate_skills.sh to include generators" |
| 66 | + echo "for the missing toolsets above, then commit your changes to unblock this PR." |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +echo "Validation passed. All upstream toolsets are supported." |
| 71 | + |
| 72 | +echo "BEGINNING SKILL GENERATION" |
| 73 | + |
| 74 | +LICENSE_HEADER="// Copyright 2026 Google LLC |
| 75 | +// |
| 76 | +// Licensed under the Apache License, Version 2.0 (the \"License\"); |
| 77 | +// you may not use this file except in compliance with the License. |
| 78 | +// You may obtain a copy of the License at |
| 79 | +// |
| 80 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 81 | +// |
| 82 | +// Unless required by applicable law or agreed to in writing, software |
| 83 | +// distributed under the License is distributed on an \"AS IS\" BASIS, |
| 84 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 85 | +// See the License for the specific language governing permissions and |
| 86 | +// limitations under the License." |
| 87 | + |
| 88 | +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." |
| 89 | + |
| 90 | +# Base Command Function |
| 91 | +generate_skill() { |
| 92 | + local TOOLSET="$1" |
| 93 | + local SKILL_DESC="$2" |
| 94 | + local SKILL_NAME="cloud-sql-mysql-$TOOLSET" |
| 95 | + |
| 96 | + echo "Generating skill: $SKILL_NAME..." |
| 97 | + |
| 98 | + npx "@toolbox-sdk/server@${VERSION}" --prebuilt cloud-sql-mysql skills-generate \ |
| 99 | + --name "$SKILL_NAME" \ |
| 100 | + --description "$SKILL_DESC" \ |
| 101 | + --toolset="$TOOLSET" \ |
| 102 | + --license-header "$LICENSE_HEADER" \ |
| 103 | + --additional-notes="$ADDITIONAL_NOTES" |
| 104 | +} |
| 105 | + |
| 106 | +set -- "${SKILLS[@]}" |
| 107 | +while [ $# -gt 0 ]; do |
| 108 | + generate_skill "$1" "$2" |
| 109 | + shift 2 |
| 110 | +done |
| 111 | + |
| 112 | +echo "All skills generated successfully!" |
0 commit comments