|
| 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 "bigquery-<toolset>" |
| 13 | +SKILLS=( |
| 14 | + "data" |
| 15 | + "Use these skills when you need to handle large-scale data exploration and dataset management. Use when users need to find data assets or run SQL at scale. Provides metadata discovery and query execution across the data warehouse." |
| 16 | + |
| 17 | + "analytics" |
| 18 | + "Use these skills when you need to handle advanced data intelligence and predictive tasks. Use when a user asks \"why\" data changed or needs future projections. Provides automated insight generation and time-series forecasting." |
| 19 | +) |
| 20 | + |
| 21 | +echo "VALIDATING TOOLSETS BEFORE GENERATION" |
| 22 | + |
| 23 | +# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array. |
| 24 | +# We use 'set --' to process the array in chunks without index arithmetic. |
| 25 | +SUPPORTED_TOOLSETS=() |
| 26 | +set -- "${SKILLS[@]}" |
| 27 | +while [ $# -gt 0 ]; do |
| 28 | + SUPPORTED_TOOLSETS+=("$1") |
| 29 | + shift 2 |
| 30 | +done |
| 31 | + |
| 32 | +echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}" |
| 33 | + |
| 34 | +# Fetch the upstream source of truth YAML for this specific version |
| 35 | +RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/bigquery.yaml" |
| 36 | +echo "Fetching upstream config from: $RAW_URL" |
| 37 | +UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; }) |
| 38 | + |
| 39 | +# Extract the list of toolsets. Each toolset is its own YAML document: |
| 40 | +# kind: toolset |
| 41 | +# name: <toolset> |
| 42 | +UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '$1=="kind:" && $2=="toolset"{f=1; next} f && $1=="name:"{print $2; f=0}') |
| 43 | + |
| 44 | +# Compare upstream toolsets against our supported list |
| 45 | +MISSING_TOOLSETS=false |
| 46 | + |
| 47 | +for upstream_tool in $UPSTREAM_TOOLSETS; do |
| 48 | + if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi |
| 49 | + |
| 50 | + if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then |
| 51 | + echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'" |
| 52 | + MISSING_TOOLSETS=true |
| 53 | + fi |
| 54 | +done |
| 55 | + |
| 56 | +if [ "$MISSING_TOOLSETS" = true ]; then |
| 57 | + echo "PIPELINE FAILED: Missing Toolset Generators" |
| 58 | + echo "The source of truth file has toolsets that your script does not support." |
| 59 | + echo "Please update the SKILLS array in generate_skills.sh to include generators" |
| 60 | + echo "for the missing toolsets above, then commit your changes to unblock this PR." |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +echo "Validation passed. All upstream toolsets are supported." |
| 65 | + |
| 66 | +echo "BEGINNING SKILL GENERATION" |
| 67 | + |
| 68 | +LICENSE_HEADER="// Copyright 2026 Google LLC |
| 69 | +// |
| 70 | +// Licensed under the Apache License, Version 2.0 (the \"License\"); |
| 71 | +// you may not use this file except in compliance with the License. |
| 72 | +// You may obtain a copy of the License at |
| 73 | +// |
| 74 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 75 | +// |
| 76 | +// Unless required by applicable law or agreed to in writing, software |
| 77 | +// distributed under the License is distributed on an \"AS IS\" BASIS, |
| 78 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 79 | +// See the License for the specific language governing permissions and |
| 80 | +// limitations under the License." |
| 81 | + |
| 82 | +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." |
| 83 | + |
| 84 | +# Base Command Function |
| 85 | +generate_skill() { |
| 86 | + local TOOLSET="$1" |
| 87 | + local SKILL_DESC="$2" |
| 88 | + local SKILL_NAME="bigquery-$TOOLSET" |
| 89 | + |
| 90 | + echo "Generating skill: $SKILL_NAME..." |
| 91 | + |
| 92 | + npx "@toolbox-sdk/server@${VERSION}" --prebuilt bigquery skills-generate \ |
| 93 | + --name "$SKILL_NAME" \ |
| 94 | + --description "$SKILL_DESC" \ |
| 95 | + --toolset="$TOOLSET" \ |
| 96 | + --license-header "$LICENSE_HEADER" \ |
| 97 | + --additional-notes="$ADDITIONAL_NOTES" |
| 98 | +} |
| 99 | + |
| 100 | +set -- "${SKILLS[@]}" |
| 101 | +while [ $# -gt 0 ]; do |
| 102 | + generate_skill "$1" "$2" |
| 103 | + shift 2 |
| 104 | +done |
| 105 | + |
| 106 | +echo "All skills generated successfully!" |
0 commit comments